[issue33944] Deprecate and remove pth files
Jason R. Coombs
report at bugs.python.org
Tue Jan 15 09:01:31 EST 2019
Jason R. Coombs <jaraco at jaraco.com> added the comment:
> `site.addsitedir` is called for every site-packages directory (whether global, within a venv, or at the user level), so my proposal above covers appending multiple segments.
Good point. I think you're assuming that only site dirs are appropriate for packages that require arbitrary code execution. I think I'd like to break that assumption and allow any location where packages can be installed (PYTHONPATH) to install hooks. Consider this use-case:
draft $ mkdir pkgs draft $ python3.5 -m pip download -d pkgs future_fstrings Collecting future_fstrings
Using cached https://files.pythonhosted.org/packages/36/25/070c2dc1fe1e51901df5875c495d6efbbf945a93a2ca40f47e5225302fb8/future_fstrings-0.4.5-py2.py3-none-any.whl
Saved ./pkgs/future_fstrings-0.4.5-py2.py3-none-any.whl
Collecting tokenize-rt; python_version < "3.6" (from future_fstrings)
Using cached https://files.pythonhosted.org/packages/76/82/0e6a9dda45dd76be22d74211443e199a330ac7e428b8dbbc5d116651be03/tokenize_rt-2.1.0-py2.py3-none-any.whl
Saved ./pkgs/tokenize_rt-2.1.0-py2.py3-none-any.whl
Successfully downloaded future-fstrings tokenize-rt
draft $ cat > hello-fstrings.py # coding: future_fstrings
print(f'hello world')
draft $ PYTHONPATH=pkgs/future_fstrings-0.4.5-py2.py3-none-any.whl:pkgs/tokenize_rt-2.1.0-py2.py3-none-any.whl python3.5 hello-fstrings.py
xonsh: subprocess mode: command not found: PYTHONPATH=pkgs/future_fstrings-0.4.5-py2.py3-none-any.whl:pkgs/tokenize_rt-2.1.0-py2.py3-none-any.whl
draft $ env PYTHONPATH=pkgs/future_fstrings-0.4.5-py2.py3-none-any.whl:pkgs/tokenize_rt-2.1.0-py2.py3-none-any.whl python3.5 hello-fstrings.py
File "hello-fstrings.py", line 1
SyntaxError: encoding problem: future_fstrings
If future-fstrings were properly installed, its runtime hook is called and the script can run:
draft $ python3.5 -m pip-run -q future-fstrings -- hello-fstrings.py
hello world
I'd like for a package like future-fstrings to be able to supply a hook that can be executed on startup that can be honored even if the package isn't installed in one of the site paths.
> Let's make a PEP.
I'd be delighted to help with the PEP.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33944>
_______________________________________
More information about the Python-bugs-list
mailing list