diff --git a/setup/git_post_checkout_hook.py b/setup/git_post_checkout_hook.py index 393c7b25b2..9dd20112b4 100755 --- a/setup/git_post_checkout_hook.py +++ b/setup/git_post_checkout_hook.py @@ -4,6 +4,7 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' import os +import runpy import subprocess import sys @@ -21,7 +22,12 @@ if flags == '1': # A branch checkout prev_branch, cur_branch = list(map(get_branch_name, (prev_rev, current_rev))) rebase_in_progress = os.path.exists('.git/rebase-apply') or os.path.exists('.git/rebase-merge') - subprocess.check_call([sys.executable, './setup.py', 'gui', '--summary']) + before = sys.argv + try: + sys.argv = ['setup.py', 'gui', '--summary'] + runpy.run_path('setup.py', run_name='__main__') + finally: + sys.argv = before # Remove .pyc files as some of them might have been orphaned for dirpath, dirnames, filenames in os.walk('.'): diff --git a/setup/git_post_rewrite_hook.py b/setup/git_post_rewrite_hook.py index becfbf8c13..d538b24b63 100755 --- a/setup/git_post_rewrite_hook.py +++ b/setup/git_post_rewrite_hook.py @@ -4,7 +4,7 @@ __license__ = 'GPL v3' __copyright__ = '2014, Kovid Goyal ' import os -import subprocess +import runpy import sys base = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) @@ -13,4 +13,9 @@ os.chdir(base) action = [x.decode('utf-8') if isinstance(x, bytes) else x for x in sys.argv[1:]][0] if action == 'rebase': - subprocess.check_call([sys.executable, './setup.py', 'gui', '--summary']) + before = sys.argv + try: + sys.argv = ['setup.py', 'gui', '--summary'] + runpy.run_path('setup.py', run_name='__main__') + finally: + sys.argv = before diff --git a/setup/git_pre_commit_hook.py b/setup/git_pre_commit_hook.py index f22fa2eba4..3b957773b8 100644 --- a/setup/git_pre_commit_hook.py +++ b/setup/git_pre_commit_hook.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import runpy import subprocess import sys @@ -37,11 +38,15 @@ filenames = tuple(filter(testfile, output)) if not filenames: sys.exit(0) -check_args = [sys.executable, './setup.py', 'check', '--no-editor'] +check_args = ['./setup.py', 'check', '--no-editor'] # let's hope that too many arguments do not hold any surprises for f in filenames: check_args.append('-f') check_args.append(f) -returncode = subprocess.call(check_args) -sys.exit(returncode) +before = sys.argv +try: + sys.argv = check_args + runpy.run_path('setup.py', run_name='__main__') +finally: + sys.argv = before