-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Don't list packages in current directory #7955
Don't list packages in current directory #7955
Conversation
Following on from what @sbidoul said, I think we should investigate why we're getting the absolute path on @brettcannon maybe you happen to have some idea about this? |
Depends on how you are executing pip and whether the site package is being run. Basically if you run |
Thanks for the response @brettcannon and @pradyunsg . From the discussion, I can sense that we now have an understanding as to why cwd included in sys.path. So is the implementation of the PR fine, taking that in account, or are there changes needed in unit tests/logic to improve it? |
I have two concerns with this PR:
Maybe doing this in |
Hi @sbidoul I just found out that we are inserting a I think you are mentioning something like this in
Also there is a PR for |
@deveshks The code block you see is irrelevant. It is only executed if you execute pip directly as a source directory, e.g. |
Thank you for the comments. I will try out that suggestion, but I am not sure if it will affect any other functionality of pip. Is there any other specific place further down the code path which I can try:
Or do you have any other suggestions on what I can try to do here? |
I doubt anything later than This reminds me #7705 though. Maybe what we should do is to add a compatibility layer over |
Hi @uranusjr So in that case, should I stick to making the change in Also I think I didn't follow your suggestion on how to add a compatibility layer, could you give me some more detailed pointers on what is it and where can I start looking for it? |
Following the conversation, I initially tried to exclude the I think @uranusjr is suggesting to perform those changes outside of |
Since the issue occurs only when running pip via |
0e208e0
to
2536b19
Compare
Thanks @sbidoul I was by mistakenly removing I have made changes to the code according to your suggestion now, please have a look :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this fix and this also closes the corresponding issue w/ pip freeze
(if we haven't merged that already) by stemming the problem at the source.
I do feel like think we should only attempt this when run with "-m" but I don't think there's a good way to detect that.
Hi @pradyunsg I tried adding a print statement right after the fix in I am not sure about the reason of the behavior, but I believe that the import statements don't get called when using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about the reason of the behavior, but I believe that the import statements don't get called when using
pip <command>
and we hit theif __name__ == '__main__':
directly. Which means that the added code will only be called when using-m
.
pip <command>
directly calls pip._internal.cli.main.main
function while python -m pip
calls pip/__main__.py
2536b19
to
38eaa4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor comments, otherwise LGTM.
I can confirm that it also resolves #2926 :) |
38eaa4d
to
56d50b2
Compare
Actually even the |
HI @sbidoul , So I will mention both Also am I correct in assuming that these commands are not negatively affected by this change? |
See also #6558 that talks about this in the context of |
One more thing: we may want to add a test with a PYTHONPATH env var that includes the current directory. I that case, an .egg-info in current directory must be considered as an installed package. That test would have failed with the initial approach of this PR which unconditionally removed os.cwd from sys.path. |
Hi @sbidoul So in this test, I will run the install command as |
56d50b2
to
c7102c4
Compare
c7102c4
to
40dd286
Compare
Once this is merged, I will also create another PR to add test cases for the behaviour of the other commands which will change based on whether the cwd is added to PYTHONPATH or not. Don't want to crowd this PR and have more iterations here. |
40dd286
to
feac595
Compare
Thanks @sbidoul for the approval. Hi @pradyunsg , @xavfernandez , could I get this PR merged as well :) |
Hi @sbidoul , @pradyunsg As mentioned in a comment above, I have created #7987 to add unit tests for the remaining 4 commands affected by this on the same principle. Would really appreciate if you can take a look at the same and share your thoughts 😊 |
Fixes and closes #7731, closes #2926, closes #3710 , closes #6558 and closes #7971
Also added tests which does the following:
Test 1
setup.py
python setup.py egg_info
from the package directory.python -m pip list
from the package directory.Test 2
setup.py
python setup.py egg_info
from the package directory.python -m pip list
from the package directory.