-
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
Address #6692: Only import a Command class when needed #6694
Conversation
I like it.
It would also be interesting to check the |
Thanks!
Yeah, agreed, I can check. (Note that there is still more work to be done on this front after this PR because e.g. |
Here it is (versus 234 before):
|
|
||
commands_dict = { | ||
'check': ( | ||
'pip._internal.commands.check', 'CheckCommand', |
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.
We can probably drop the "pip._internal.commands." prefix and attach it at the point where it's used. It's not a significant compute cost and helps reduce duplication (and chances of typos).
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.
That's actually how I had it originally until I encountered that test case you also discovered further on. :)
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.
One possible downside of not fully-qualifying the name is that automatic refactoring tools will not pick it up, but a quick test with PyCharm (CE 2019.1.3) indicates that even with the string as-is it does not recognize this string when I refactor the module check
to check2
.
'A helper command used for command completion.', | ||
), | ||
'config': ( | ||
'pip._internal.commands.configuration', 'ConfigurationCommand', |
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.
It might even make sense to, in a follow up, rename the this module to "config" and then simply reuse the key as the module name, since that's the case for everything else.
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.
Good thought!
@@ -26,8 +24,10 @@ class AddFakeCommandMixin(object): | |||
|
|||
def setup(self): | |||
self.environ_before = os.environ.copy() | |||
commands_dict[FakeCommand.name] = FakeCommand | |||
commands_dict['fake'] = ( | |||
'tests.lib.options_helpers', 'FakeCommand', 'fake summary', |
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.
Ah! This would be complicated by my suggestion for simplification and DRYing of "pip._internal.commands.". Let's look into that in a follow up then. :)
ae8f31b
to
81a9fae
Compare
Thanks, @xavfernandez and @pradyunsg. I've updated the PR. (There is also a new |
adcd1b7
to
1c0c777
Compare
@cjerdonek do you mind waiting for 19.2 before merging this? I'd prefer to keep that release smaller and while I don't expect this to cause any issues, I'd prefer to defer this for a later release. Does that sound fine to you? |
I guess that's okay since it doesn't really impact behavior, though it will hold back work on refactoring that depends on this. |
By the way, does anyone know why there is a lone test failure in the Travis CI run (Python 3.5) that's caused by an unrelated change? The failure seems to persist even when re-running the tests. I'm attaching a screenshot with some debug info from the error. The test that fails is |
Network-related warnings are raised and that test isn't robust to them. |
But why does it not happen for other PR's but for this one it seems to be happening reproducibly? |
Hmm... It seems to have passed here now. |
If we see it again, let's file a dedicated issue for it and fix it for good. |
This resulted in an approximate 24% speed-up of a vanilla `pip` invocation on one system (0.477 secs before, 0.363 secs after).
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
1c0c777
to
4cd8258
Compare
This implements the (first) suggestion listed in issue #6692, which is not to import all command classes when starting up and only to import the one that's actually needed.
On my system, a bare
pip
invocation sped up by about 24% with this change.Also, when inserting the following lines to list all imported pip modules at this point in time:
after these lines in
pip/_internal/__init__.py
:pip/src/pip/_internal/__init__.py
Lines 62 to 67 in ddfa401
the following lines are printed:
Without the PR, 80 modules were printed.