diff options
authorAlexandru Croitor <>2019-02-06 17:10:46 +0100
committerAlexandru Croitor <>2019-02-06 17:25:38 +0000
commit2ff9a9ff8d5afbf9b8a347b15cf7d3043219d45c (patch)
parente1ce71572446e68bcd78fd37a061b7f32d40bd00 (diff)
Make more robust when invoked in a weird way sub-invocations use the command line arguments from the original invocation. This means that if was not invoked directly, but instead using the "python -c 'code'" approach, sub-invocations would break because argv[0] would be "-c" instead of "". This was previously seen when building PySide2 in homebrew, and allegedly when doing an sdist. Fix to pass the correct script file name, even when invoked in such a weird manner. Change-Id: Ic834d7398098095f74972661b2abc4f4e4c3c8d9 Reviewed-by: Cristian Maureira-Fredes <> Reviewed-by: Alberto Sottile <>
1 files changed, 7 insertions, 0 deletions
diff --git a/ b/
index 58bb84b3..8eb2027b 100644
--- a/
+++ b/
@@ -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):
@@ -276,6 +277,12 @@ if os.path.dirname(this_file):
# mechanism.
original_argv = list(sys.argv)
+# If 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