Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1a99b4

Browse files
authored
bpo-20443: No longer make sys.argv[0] absolute for script (GH-17534)
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.
1 parent d219cc4 commit a1a99b4

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

Lib/test/test_cmd_line_script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ def test_basic_script(self):
223223

224224
def test_script_abspath(self):
225225
# pass the script using the relative path, expect the absolute path
226-
# in __file__ and sys.argv[0]
226+
# in __file__
227227
with support.temp_cwd() as script_dir:
228228
self.assertTrue(os.path.isabs(script_dir), script_dir)
229229

230230
script_name = _make_test_script(script_dir, 'script')
231-
self._check_script(os.path.basename(script_name), script_name, script_name,
231+
relative_name = os.path.basename(script_name)
232+
self._check_script(relative_name, script_name, relative_name,
232233
script_dir, None,
233234
importlib.machinery.SourceFileLoader)
234235

Lib/test/test_embed.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,9 @@ def test_preinit_parse_argv(self):
858858
preconfig = {
859859
'allocator': PYMEM_ALLOCATOR_DEBUG,
860860
}
861-
script_abspath = os.path.abspath('script.py')
862861
config = {
863-
'argv': [script_abspath],
864-
'run_filename': script_abspath,
862+
'argv': ['script.py'],
863+
'run_filename': os.path.abspath('script.py'),
865864
'dev_mode': 1,
866865
'faulthandler': 1,
867866
'warnoptions': ['default'],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In Python 3.9.0a1, sys.argv[0] was made an asolute path if a filename was
2+
specified on the command line. Revert this change, since most users expect
3+
sys.argv to be unmodified.

Python/initconfig.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,10 +2198,6 @@ config_update_argv(PyConfig *config, Py_ssize_t opt_index)
21982198
/* Force sys.argv[0] = '-m'*/
21992199
arg0 = L"-m";
22002200
}
2201-
else if (config->run_filename != NULL) {
2202-
/* run_filename is converted to an absolute path: update argv */
2203-
arg0 = config->run_filename;
2204-
}
22052201

22062202
if (arg0 != NULL) {
22072203
arg0 = _PyMem_RawWcsdup(arg0);

0 commit comments

Comments
 (0)