-
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
Move code out of pip._internal.__init__ #7061
Move code out of pip._internal.__init__ #7061
Conversation
Moving content out of `__init__` is preferred in general because it avoids conflicts with module names and unnecessary imports.
Is there any reason why |
There's warning silencing (for warnings from I wonder if there's merit in doing the following:
|
If |
I think it can be empty, but expect that moving the warning silencing will require a little more thought or discussion. I figured it was better to submit the obvious change alone. It is definitely worth doing though, you can see these are not cheap imports. |
Right, but we'd want to silence them before loading them. As @chrahunt pointed out, it's best for doing in a follow up. None the less, I'm not 100% sure if that's the best place to investigate but, hey, I don't mean to block anyone from making improvements. :) |
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.
LGTM.
It should be imported directly from pip._internal.commands. See PR pypa/pip#7061 which breaks pip-tools.
Just a heads up: This change will mean an update to ensurepip when they upgrade to |
Thanks :), python/cpython#16782 has been created to tackle this. |
This also broke (some invocations of?) virtualenv: pypa/virtualenv#1436. Maybe Pip should promote |
Related to #4497.
Previously our main function and its associated imports were in
pip._internal.__init__
- this makes them unconditional for any access of pip internals. Nowmain
is inpip._internal.main
.This is relevant to:
tests.unit.test_build_env
, which starts subprocesses and import internals which may not require everything that was in__init__
.__init__
it is difficult to use-X importtime
to isolate slow-loading modules or modules that cause a lot of other transitive importsA test on my machine shows that import of
pip._internal
previously took around 120ms before this change, and is now around 60ms.