-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Adapt to changing Pip internals #1436
Conversation
pypa/pip@09fd200 moved Pip's `main` function underneath a new `pip._internals.main` module. Playing a risky game, using `pip._internals`. ;-)
Why not use a subprocess call (the documented way of using pip from another program) instead of calling the internal |
Because subprocess is slow... |
Use runpy? |
https://github.com/pradyunsg/pip-cli/blob/master/src/_pip_cli.py#L75 An example of how to do that, if you're interested in doing that. That said, it's still an unsupported way of doing things -- a subprocess is slower but it's easier to maintain state of. |
I don't want to make things slower. I think pip should expose it's cli interface directly, rather than just via an entry point, but that ship sailed a while ago. |
I can understand that - virtual environment creation is frustratingly slow at times. But is invoking pip really the bottleneck here (as opposed to the actual installs)? I'd suggest doing some measurements. But I can accept the possibility that it might be worth saving the subprocess call (especially on Windows, where extra processes are more costly).
See pypa/pip#3121 for the last big debate on this. It is possible to call pip's Hmm, here's a thought. Maybe we could expose a |
Why is using runpy not an OK option here? There's very little overhead to it. |
@pradyunsg Actually, agreed. |
why? |
If you mean "why wasn't it designed that way?" then it just wasn't originally, and it would be a lot of work to change that now. Pip was always intended as a standalone utility rather than a library, for better or worse. If you mean "why doesn't it work in-process" then see the issue I linked to, but briefly, from what I remember:
|
I was referring to the later.
Fair enough, though here the expectation wouldn't be to work in parallel.
This shouldn't be an impediment as long as it uses it's own logging namespace. The only potential improvement could be to allow disable-ing the config setup.
This is only an issue, if and only if, you're modifying the same site-package as the one you're running in (which wouldn't necessarily be the case with virtualenv), and furthermore this is just as much as a problem with subprocesses. If you target the same site-packages your imports might be out of date after invocation. Imports within pip shouldn't be an issue as pip vendors all its dependencies, and hopefully no one is altering the standard library with pip.
Now this part is more concerning. Going along this expectation this would make in process tests also a lot harder. And debugging subprocesses is not as straight forward and pleasent as with the in-process ones. I would expect ensure-ing we don't mutate global state to be a beneficial place as far as ease of testing and maintainability goes. On the topicThat being said I'm not too tied to using either direct pip internals or runpy. The virtualenv rewrite forgoes entirely using pip for bootstrapping, it's just too slow (yeah I profiled it - initial progress on it): rm perf -rf; time virtualenv --no-download perf --no-wheel
New python executable in /virtualenv/perf/bin/python
Installing setuptools, pip...
done.
2.72 real 1.80 user 0.86 sys New way: rm perf -rf; time .tox/dev/bin/virtualenv --no-download perf
create with venv /.pyenv/versions/3.7.4/bin/python3.7 -m venv --without-pip /virtualenv/perf
[2019-10-15 19:04:56,429] INFO [/virtualenv/src/virtualenv/interpreters/create/api.py:71]
0.28 real 0.20 user 0.05 sys Until that gets released I think I'm content to keep the current status quo of doing things. |
Tell me about it :-)
Nice! So I assume you manually unpack the embedded wheels or something like that? That seems like an entirely sensible option, there's no need for the whole of pip's machinery if all you want to do is unpack a wheel. I'd actually like to see a general library that did that, as I think it's often a good choice. (It's a shame wheel decided not to support a programming API as it has this functionality internally - but I'm not in any position to complain about a decision like that 😉)
That sounds entirely reasonable. |
Yeah, though slightly more complicated (https://github.com/gaborbernat/virtualenv/blob/rewrite/src/virtualenv/seed/link_app_data.py#L33-L41):
I'm also experimenting on just linking the files/folders via symlink/junctions/hard link, rather than copy; though this seems a lot harder, especially on Windows, mostly because pip seems to want to do a lot more than asked, e.g. even if in the RECORDS.txt I say only remove the junction it goes and removes the entire tree the junction entree points too 😢 Also before 19.3 resolves symlinks and removes target, rather than just the symlink. Still thinking about how can I side step those limitations. |
So for this you presumably need to vendor distlib or similar, to get the required |
I've put the windows console script generation on the TODO list 🤔 from what I saw in pip it's done via distlib that's part of stdlib, not? |
|
Oh thanks, no vendoring needed luckily 😄 as the new virtualenv can have install requires 😄 |
pypa/pip@09fd200 moved Pip's
main
function underneath a newpip._internal.main
module. Playing a risky game, usingpip._internal
. ;-)