-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pkg_resources merrily adds site-packages to the front of sys.path #6
Comments
Original comment by ncoghlan (Bitbucket: ncoghlan, GitHub: ncoghlan): OK, we think I've narrowed down the cases where pkg_resources will do this:
The second kind of entry will have its sys.path location copied to the front of sys.path, potentially shadowing other modules. We encountered this when making the Sphinx autodoc based documentation builds for Beaker work on both RHEL 6 and Fedora, since the default versions of Sphinx and CherryPy are different, but some of the Sphinx dependencies still have the same default version on both platforms. This meant site-packages was getting a duplicate sys.path entry in front of the source directories, breaking local doc builds if the Beaker libraries were also installed system wide in site-packages. |
Original comment by pje (Bitbucket: pje, GitHub: pje): If this happens only from It seems especially likely since that bit's got the least conservative path manipulation in the entire module. ;-) The trick would be to find a way to change it that still accomplishes its purpose, which is to work around a conflict with a default version of a library. Right now it does it by punting and saying, "screw it, I'll just build a sys.path that exactly lists what I need, and then tack anything else left over at the end." Putting site-packages near the beginning of sys.path kind of defeats this purpose anyway. Thinking back, this code was probably written before .egg-info packages even existed, and it looks to me like its logic is completely broken for dealing with them. It should strictly separate .egg/.whl distributions from any other sort, and put them first on the new path list it builds, followed by the others. It also needs to arrange any unencapsulated distributions such that the version conflict doesn't persist, if it can. |
Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco): I've moved "the conflict-handling logic at the end of pkg_resources" to classmethods on the I still don't feel like I have a good grasp of the described problem. It seems there are conditions under which site-packages will be added back to sys.path as part of the _build_from_requirements step, which incidentally causes packages in site-packages to be preferred over those that otherwise would have been selected by the @ncoghlan, can you describe how to create a minimal environment that triggers the undesirable behavior? @pje, thanks for the advice. You've made some good points. Based on your last paragraph, it sounds like what you're proposing is to do two passes over 'dists', first adding only those that are encapsulated, then adding those that are not. I don't see how this will avoid the issue if any of the encapsulated packages are found in site-packages. Admittedly, I don't yet understand the nuances of the problem, so I hope Nick will be able to put together a concrete example which can be used to characterize better the failure mode. |
Original comment by ncoghlan (Bitbucket: ncoghlan, GitHub: ncoghlan): PJE recently pointed out I never summarised the current state of things on To trigger this particular case:
What seems to happen is a "one in, all in" effect, where if any package |
Original comment by pje (Bitbucket: pje, GitHub: pje): Strictly speaking, what happens is that if any addition to sys.path causes a VersionConflict, the whole thing gets thrown out and started over. Jason: by "encapsulated" I mean, "contained in its own file or directory, and therefore having a unique sys.path entry value". Thus, "/wherever/site-packages" can never be an "encapsulated" path by this definition, since it can contain encapsulated distribution but is not itself one. If encapsulated distributions are always put first on the updated path, it is impossible for a non-encapsulated (i.e. default) distribution to override it. |
Original comment by RonnyPfannschmidt (Bitbucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): is this by chance related to #2 |
Allow spawn to accept environment. Avoid monkey-patching global state.
Originally reported by: ncoghlan (Bitbucket: ncoghlan, GitHub: ncoghlan)
If a requirement in
__main__.__requires__
is met by a package in site-packages, pkg_resources will happily reinsert site-packages at the front of sys.path.This breaks the world when working on software where a previous version is installed as a system package.
The text was updated successfully, but these errors were encountered: