mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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.
This commit is contained in:
parent
d219cc4180
commit
a1a99b4bb7
4 changed files with 8 additions and 9 deletions
|
@ -223,12 +223,13 @@ class CmdLineTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_script_abspath(self):
|
def test_script_abspath(self):
|
||||||
# pass the script using the relative path, expect the absolute path
|
# 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:
|
with support.temp_cwd() as script_dir:
|
||||||
self.assertTrue(os.path.isabs(script_dir), script_dir)
|
self.assertTrue(os.path.isabs(script_dir), script_dir)
|
||||||
|
|
||||||
script_name = _make_test_script(script_dir, 'script')
|
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,
|
script_dir, None,
|
||||||
importlib.machinery.SourceFileLoader)
|
importlib.machinery.SourceFileLoader)
|
||||||
|
|
||||||
|
|
|
@ -858,10 +858,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
preconfig = {
|
preconfig = {
|
||||||
'allocator': PYMEM_ALLOCATOR_DEBUG,
|
'allocator': PYMEM_ALLOCATOR_DEBUG,
|
||||||
}
|
}
|
||||||
script_abspath = os.path.abspath('script.py')
|
|
||||||
config = {
|
config = {
|
||||||
'argv': [script_abspath],
|
'argv': ['script.py'],
|
||||||
'run_filename': script_abspath,
|
'run_filename': os.path.abspath('script.py'),
|
||||||
'dev_mode': 1,
|
'dev_mode': 1,
|
||||||
'faulthandler': 1,
|
'faulthandler': 1,
|
||||||
'warnoptions': ['default'],
|
'warnoptions': ['default'],
|
||||||
|
|
|
@ -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.
|
|
@ -2198,10 +2198,6 @@ config_update_argv(PyConfig *config, Py_ssize_t opt_index)
|
||||||
/* Force sys.argv[0] = '-m'*/
|
/* Force sys.argv[0] = '-m'*/
|
||||||
arg0 = L"-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) {
|
if (arg0 != NULL) {
|
||||||
arg0 = _PyMem_RawWcsdup(arg0);
|
arg0 = _PyMem_RawWcsdup(arg0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue