cmdline: intercept setup.py calls and use shebang to get proper version (#38710)

This commit is contained in:
Frédéric Péters 2019-12-26 11:21:36 +01:00
parent 5ca950a6a2
commit 06602cd25e
2 changed files with 11 additions and 2 deletions

View File

@ -2,7 +2,6 @@ import datetime
import textwrap
import os
import sys
import subprocess
import pytz
@ -10,6 +9,8 @@ import git
from git.exc import GitCommandError
from git.objects.commit import Commit
from . import cmdline
def get_commit_from_tag(repo, tag_ref):
ref = repo.tags[tag_ref]
while ref.object.type == 'tag':
@ -24,7 +25,7 @@ def is_pep0440_project(path):
curdir = os.getcwd()
try:
os.chdir(path)
output = subprocess.check_output('python setup.py --version', shell=True)
output = cmdline.output('python setup.py --version')
if '+' in output:
return True
finally:

View File

@ -112,6 +112,10 @@ 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:
@ -122,6 +126,10 @@ 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,