bpo-20443: _PyConfig_Read() gets the absolute path of run_filename by vstinner · Pull Request #14053 · python/cpython (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation2 Commits2 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Python now gets the absolute path of the script filename specified on
the command line (ex: "python3 script.py"): the file attribute of
the main module and sys.path[0] become an absolute path, rather
than a relative path.
- Add _Py_isabs() and _Py_abspath() functions.
- _PyConfig_Read() now tries to get the absolute path of
run_filename, but keeps the relative path if _Py_abspath() fails. - Reimplement os._getfullpathname() using _Py_abspath().
- Use _Py_isabs() in getpath.c
https://bugs.python.org/issue20443
@ncoghlan: Does this change seem reasonable to you?
Effect of my PR 14053 using script.py:
import sys
print(f"{__file__=}")
print(f"{sys.argv=}")
print(f"{sys.path[0]=}")
Before:
$ ./python script.py
__file__=script.py
sys.argv=['script.py']
sys.path[0]=/home/vstinner/prog/python/master
With this change:
$ ./python script.py
__file__=/home/vstinner/prog/python/master/script.py
sys.argv=['/home/vstinner/prog/python/master/script.py']
sys.path[0]=/home/vstinner/prog/python/master
Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the file attribute of the main module and sys.path[0] become an absolute path, rather than a relative path.
- Add _Py_isabs() and _Py_abspath() functions.
- _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails.
- Reimplement os._getfullpathname() using _Py_abspath().
- Use _Py_isabs() in getpath.c
lisroach pushed a commit to lisroach/cpython that referenced this pull request
Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the file attribute of the main module, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path.
- Add _Py_isabs() and _Py_abspath() functions.
- _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails.
- Reimplement os._getfullpathname() using _Py_abspath().
- Use _Py_isabs() in getpath.c.
DinoV pushed a commit to DinoV/cpython that referenced this pull request
Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the file attribute of the main module, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path.
- Add _Py_isabs() and _Py_abspath() functions.
- _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails.
- Reimplement os._getfullpathname() using _Py_abspath().
- Use _Py_isabs() in getpath.c.
1st1 mentioned this pull request