]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-20443: No longer make sys.argv[0] absolute for script (GH-17534)
authorVictor Stinner <vstinner@python.org>
Mon, 9 Dec 2019 16:34:02 +0000 (17:34 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Dec 2019 16:34:02 +0000 (17:34 +0100)
In Python 3.9.0a1, sys.argv[0] was made an asolute path if a filename
was specified on the command line. Revert this change, since most
users expect sys.argv to be unmodified.

Lib/test/test_cmd_line_script.py
Lib/test/test_embed.py
Misc/NEWS.d/next/Core and Builtins/2019-12-09-17-05-53.bpo-20443.8OyT5P.rst [new file with mode: 0644]
Python/initconfig.c

index 2ac926deac4850adeb918aa2abc89c7235e56876..adfb8ce5ed245212ea368d18188d05950d378722 100644 (file)
@@ -223,12 +223,13 @@ class CmdLineTest(unittest.TestCase):
 
     def test_script_abspath(self):
         # pass the script using the relative path, expect the absolute path
-        # in __file__ and sys.argv[0]
+        # in __file__
         with support.temp_cwd() as script_dir:
             self.assertTrue(os.path.isabs(script_dir), script_dir)
 
             script_name = _make_test_script(script_dir, 'script')
-            self._check_script(os.path.basename(script_name), script_name, script_name,
+            relative_name = os.path.basename(script_name)
+            self._check_script(relative_name, script_name, relative_name,
                                script_dir, None,
                                importlib.machinery.SourceFileLoader)
 
index b87863a372a6c41eafc63db5ae75a7c2d93853b7..60f7f7a93ea1ad0bb3e31bc5a1c5ee4611aa36df 100644 (file)
@@ -858,10 +858,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
         preconfig = {
             'allocator': PYMEM_ALLOCATOR_DEBUG,
         }
-        script_abspath = os.path.abspath('script.py')
         config = {
-            'argv': [script_abspath],
-            'run_filename': script_abspath,
+            'argv': ['script.py'],
+            'run_filename': os.path.abspath('script.py'),
             'dev_mode': 1,
             'faulthandler': 1,
             'warnoptions': ['default'],
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-12-09-17-05-53.bpo-20443.8OyT5P.rst b/Misc/NEWS.d/next/Core and Builtins/2019-12-09-17-05-53.bpo-20443.8OyT5P.rst
new file mode 100644 (file)
index 0000000..d3855f2
--- /dev/null
@@ -0,0 +1,3 @@
+In Python 3.9.0a1, sys.argv[0] was made an asolute path if a filename was
+specified on the command line. Revert this change, since most users expect
+sys.argv to be unmodified.
index caa9bf5f5689e49a7824fbb12e5d31ec0a530e80..74c9ca007ed704b9f63b63ba86a73ad78c8b687d 100644 (file)
@@ -2198,10 +2198,6 @@ config_update_argv(PyConfig *config, Py_ssize_t opt_index)
         /* Force sys.argv[0] = '-m'*/
         arg0 = L"-m";
     }
-    else if (config->run_filename != NULL) {
-        /* run_filename is converted to an absolute path: update argv */
-        arg0 = config->run_filename;
-    }
 
     if (arg0 != NULL) {
         arg0 = _PyMem_RawWcsdup(arg0);