run setup.py with python3 in more conditions (#43601)

This commit is contained in:
Frédéric Péters 2020-06-03 20:33:15 +02:00
parent fbbeb6dfbd
commit de529a11e6
3 changed files with 18 additions and 16 deletions

View File

@ -11,7 +11,7 @@ import os
from eobuilder import settings, VERSION, init
from eobuilder.changelog import changelog_from_git
from eobuilder.cmdline import parse_cmdline, error, cat, touch, call, output
from eobuilder.cmdline import parse_cmdline, error, cat, touch, call, output, setup_py
def rm_recursive(path):
if os.path.exists(path):
@ -91,10 +91,10 @@ def get_project_infos(git_project_path, cmd_options):
}
if os.path.exists("setup.py"):
# Hack to support setup_requires
output("python setup.py --help")
results['name'] = output("python setup.py --name 2> /dev/null")[:-1]
results['version'] = output("python setup.py --version 2> /dev/null")[:-1]
results['fullname'] = output("python setup.py --fullname 2> /dev/null")[:-1]
setup_py("--help")
results['name'] = setup_py("--name 2> /dev/null")[:-1]
results['version'] = setup_py("--version 2> /dev/null")[:-1]
results['fullname'] = setup_py("--fullname 2> /dev/null")[:-1]
elif os.path.exists("configure.ac"):
call("./autogen.sh")
call('make all')
@ -189,8 +189,8 @@ def prepare_build(dist, project, cmd_options, new):
os.chdir(project['git_path'])
call("git checkout --quiet %s" % build_branch)
if os.path.exists('setup.py'):
call("python setup.py clean --all")
call("python setup.py sdist --formats=bztar")
setup_py("clean --all")
setup_py("sdist --formats=bztar")
shutil.move("dist/%s.tar.bz2" % project['fullname'], origin_archive)
elif os.path.exists('./configure.ac'):
call("make dist-bzip2")

View File

@ -27,7 +27,7 @@ def is_pep0440_project(path):
curdir = os.getcwd()
try:
os.chdir(path)
output = cmdline.output('python setup.py --version')
output = cmdline.setup_py('--version')
if '+' in output:
return True
finally:

View File

@ -112,10 +112,6 @@ def error(msg, build_dir=None, exit_code=1):
def call(cmd):
""" cmd: command line
"""
if cmd.startswith('python setup.py'):
shebang = open('setup.py').readline()
if shebang.startswith('#!'):
cmd = shebang[2:].strip() + ' ' + cmd.split(' ', 1)[1]
print('CALL:', cmd)
rcode = subprocess.call(cmd, shell=True)
if rcode != 0:
@ -126,10 +122,6 @@ def output(cmd, print_output=False, exit_on_error=True):
print_output: print stdout and stderr
return outputs (stderr + stdout) as byte string
"""
if cmd.startswith('python setup.py'):
shebang = open('setup.py').readline()
if shebang.startswith('#!'):
cmd = shebang[2:].strip() + ' ' + cmd.split(' ', 1)[1]
output = None
try:
output = subprocess.check_output(cmd,
@ -143,3 +135,13 @@ def output(cmd, print_output=False, exit_on_error=True):
if print_output:
print(output)
return output.decode('utf-8') if output else None
def setup_py(args):
python = 'python'
setup_py_contents = open('setup.py').read()
if 'python3' in setup_py_contents or 'Programming Language :: Python :: 3' in setup_py_contents:
python = 'python3'
elif os.path.exists('debian/control') and 'python3-' in open('debian/control').read():
python = 'python3'
return output(python + ' setup.py ' + args)