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

Skip to content

bpo-20443: No longer make sys.argv[0] absolute for script #17534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/test/test_cmd_line_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ def test_basic_script(self):

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)

Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,9 @@ def test_preinit_parse_argv(self):
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'],
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 0 additions & 4 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down