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

Unintended? interaction between virtualenv and ignoring installed packages #41

Closed
dstufft opened this issue Nov 11, 2018 · 2 comments · Fixed by #42
Closed

Unintended? interaction between virtualenv and ignoring installed packages #41

dstufft opened this issue Nov 11, 2018 · 2 comments · Fixed by #42

Comments

@dstufft
Copy link
Contributor

dstufft commented Nov 11, 2018

I'm not entirely sure what the specific root cause of this issue, but I feel like the behavior here is not quite right.

So basic setup, there is a virtualenv located at /opt/warehouse, and inside of that a directory called /opt/warehouse/src which has a git checkout of the Warehouse code, which is added to sys.path using PYTHONPATH.

Now, it just so happens that when inside of a virtual environment, the root of the virtual environment is set to be the "data" path (sysconfig.get_paths()["data"]). This means that /opt/warehouse gets detected as a "system path" by #40, and because the project files are in an unrelated directory within that directory, it detects the entire project as an installed project and doesn't monitor it.

It seems to me, the easiest fix would be to not use all of the paths returned by sysconfig.get_paths(). There are 8 keys that can exist in the dictionary returned by that API:

  • data
  • include
  • platinclude
  • platlib
  • platstdlib
  • purelib
  • scripts
  • stdlib

It seems to me, like installed packages are not going to exist in data, include, platinclude, and maybe scripts, so it would make sense to exclude those directories from the paths you get from sysconfig.get_paths().

Another option would be, instead of doing a simple startswith, is to figure out which sys.path entry this file is imported from (by comparing the filename to every entry in sys.path, and making it "owned" by whichever sys.pathentry is longer *and* is a prefix match), and then only ignore files whosesys.path`` entry matches on the system paths.

@mmerickel
Copy link
Member

I hadn't considered the case that the virtualenv would be at the root (something like python3 -m venv .) which is certainly a valid configuration. I'll update to only include purelib, stdlib, platlib and platstdlib. Do you see any others I should add?

@mmerickel
Copy link
Member

@dstufft if #42 is ok to you I'll push that out

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.

2 participants