Skip to content
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

pip/_vendor/pep517 is in sys.path when executing setup.py #104

Closed
hexagonrecursion opened this issue Jan 31, 2021 · 3 comments · Fixed by #105
Closed

pip/_vendor/pep517 is in sys.path when executing setup.py #104

hexagonrecursion opened this issue Jan 31, 2021 · 3 comments · Fixed by #105

Comments

@hexagonrecursion
Copy link
Contributor

hexagonrecursion commented Jan 31, 2021

This causes issues when importing certain libraries in setup.py eg colorlog

pyproject.toml

[build-system]
requires = ["setuptools", "wheel", "colorlog"]
build-backend = "setuptools.build_meta"

setup.py

import sys
from pprint import pprint
from setuptools import setup

pprint(sys.path)
setup()
exit(1)

Relevant part of the output:

  ['/home/user/pip/src/pip/_vendor/pep517',
   '/tmp/pip-build-env-ypml46ei/site',
   '/home/user/.conda/envs/hello/lib/python39.zip',
   '/home/user/.conda/envs/hello/lib/python3.9',
   '/home/user/.conda/envs/hello/lib/python3.9/lib-dynload',
   '/tmp/pip-build-env-ypml46ei/overlay/lib/python3.9/site-packages',
   '/tmp/pip-build-env-ypml46ei/normal/lib/python3.9/site-packages']

pypa/pip#8887 (comment)
The end result of this is that if anyone's build relies on a library with the name of any files in the vendored copy of the pep517 library, they'll encounter this same problem.

pypa/pip#8887 (comment)
I was confused why out of the dozens of libraries pip vendors only pep517 is in the path. I was thinking maybe pep517 is not vendored correctly. bcc execsnoop cleared that up:

PCOMM            PID    PPID   RET ARGS
pip              21719  18141    0 /home/user/.conda/envs/hello/bin/pip install -e ./hello-setup/
uname            21721  21719    0 /usr/bin/uname -rs
python           21722  21719    0 /home/user/.conda/envs/hello/bin/python /home/user/pip/src/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-xmo5gc8z/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel colorlog
uname            21726  21722    0 /usr/bin/uname -rs
python           21727  21719    0 /home/user/.conda/envs/hello/bin/python /home/user/pip/src/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp1trhhp23

Note the last line: pip runs src/pip/_vendor/pep517/_in_process.py as a subprocess. This is why its parent directory is in the path.

I want to fix this. I was instructed to open an issue in this repo.

@hexagonrecursion
Copy link
Contributor Author

I can confirm that the process is being spawned by the following code:
https://github.com/pypa/pep517/blob/a2d884976eaf93225dee151137476a042008d8dd/pep517/wrappers.py#L274-L278

@hexagonrecursion hexagonrecursion changed the title pip/_vendor/pep517 is in the path when executing setup.py pip/_vendor/pep517 is in sys.path when executing setup.py Jan 31, 2021
@hexagonrecursion
Copy link
Contributor Author

hexagonrecursion commented Jan 31, 2021

Possible solutions:

  1. Move _in_process.py into its own directory. This directory will then end up in sys.path, but if the only file in it is _in_process.py this should not be a big deal. Right?
  2. Have _in_process.py delete sys.path[0]

@hexagonrecursion

This comment has been minimized.

hexagonrecursion added a commit to hexagonrecursion/pep517 that referenced this issue Jan 31, 2021
_in_process.py is executed as a subprocess. This causes its parent
directory to become sys.path[0]. Any extra files in the same directory
shadow pypi libraries eg colorlog.

Solution: put _in_process.py in its own special subdirectory.
Note: the directory has to be a module because
importlib.resources.path does not support resources with directory
separators in their name:

https://docs.python.org/3/library/importlib.html#importlib.resources.path :
> resource is the name of the resource to open within package;
> it may not contain path separators and it may not have sub-resources
> (i.e. it cannot be a directory).
hexagonrecursion added a commit to hexagonrecursion/pep517 that referenced this issue Jan 31, 2021
takluyver added a commit that referenced this issue Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant