diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-02-06 17:10:46 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-02-06 17:25:38 +0000 |
commit | 2ff9a9ff8d5afbf9b8a347b15cf7d3043219d45c (patch) | |
tree | b9ffbf646add640fe8cefb5fd60ee3d0c5caf2d0 | |
parent | e1ce71572446e68bcd78fd37a061b7f32d40bd00 (diff) |
Make setup.py more robust when invoked in a weird way
setup.py sub-invocations use the command line arguments from the
original setup.py invocation. This means that if setup.py was not
invoked directly, but instead using the "python -c 'code'" approach,
sub-invocations would break because argv[0] would be "-c" instead
of "setup.py".
This was previously seen when building PySide2 in homebrew, and
allegedly when doing an sdist.
Fix setup.py to pass the correct script file name, even when invoked
in such a weird manner.
Change-Id: Ic834d7398098095f74972661b2abc4f4e4c3c8d9
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Alberto Sottile <alby128@gmail.com>
-rw-r--r-- | setup.py | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -268,6 +268,7 @@ try: this_file = __file__ except NameError: this_file = sys.argv[0] +this_file_original = this_file this_file = os.path.abspath(this_file) if os.path.dirname(this_file): os.chdir(os.path.dirname(this_file)) @@ -276,6 +277,12 @@ if os.path.dirname(this_file): # mechanism. original_argv = list(sys.argv) +# If setup.py was invoked via -c "some code" or -m some_command, make sure +# to replace the first argv to be the script name, so that sub-invocations +# continue to work. +if original_argv and original_argv[0] in ['-c', '-m']: + original_argv[0] = this_file_original + from build_scripts.main import get_package_version, check_allowed_python_version from build_scripts.setup_runner import SetupRunner |