From de529a11e6244a5727a589da5e01701c1f667bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 3 Jun 2020 20:33:15 +0200 Subject: [PATCH] run setup.py with python3 in more conditions (#43601) --- eobuilder-ctl | 14 +++++++------- eobuilder/changelog.py | 2 +- eobuilder/cmdline.py | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/eobuilder-ctl b/eobuilder-ctl index caac453..77a86aa 100755 --- a/eobuilder-ctl +++ b/eobuilder-ctl @@ -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") diff --git a/eobuilder/changelog.py b/eobuilder/changelog.py index 8b2a671..f4f0dbe 100644 --- a/eobuilder/changelog.py +++ b/eobuilder/changelog.py @@ -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: diff --git a/eobuilder/cmdline.py b/eobuilder/cmdline.py index 733e8be..63334a6 100644 --- a/eobuilder/cmdline.py +++ b/eobuilder/cmdline.py @@ -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)