Skip to content

Move all internal APIs to pip._internal #4700

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

Merged
merged 2 commits into from
Aug 31, 2017
Merged

Conversation

dstufft
Copy link
Member

@dstufft dstufft commented Aug 31, 2017

It's not really going to be possible to review this PR, it touches basically every file in pip, but mostly to move them and rewrite imports. Functionally what this does is:

  • Move pip.* into pip._internal.*.
  • Move pip/ into src/pip/.

I was unsure about if this was a good idea or not, but as I implemented it, it has really grown on me. I think the biggest benefits will be:

  • Completely obvious that these APIs are internal and should not be depended on.
  • Paves the way for adding some public APIs (maybe for plugins?) with a clear distinction between what is and isn't public.

@dstufft dstufft added the skip news Does not need a NEWS file entry (eg: trivial changes) label Aug 31, 2017
@dstufft dstufft removed the skip news Does not need a NEWS file entry (eg: trivial changes) label Aug 31, 2017
@pfmoore
Copy link
Member

pfmoore commented Aug 31, 2017

Yeah, no way I'll be able to review this, but I'm +1 on the idea and if tests pass that's probably all we can expect to check.

Probably worth taking care when we merge this - as you noted elsewhere it'll break pretty much every existing PR...

@dstufft
Copy link
Member Author

dstufft commented Aug 31, 2017

@pfmoore Yea. I don't really have a good idea for how to take care of when we merge this. I think no matter what it's gonna suck and probably there's not really a good way forward besides just doing it.

@@ -0,0 +1,2 @@
Move all of pip's APIs into the pip._internal package, properly reflecting the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there are 2 news files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the contents are the same, it'll get rolled up into a single news entry, referencing multiple issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's neat. I never realised this was possible.

@@ -1,4 +0,0 @@
from pip.models.index import Index, PyPI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have removed 2 files unintentionally.

pip.models.__init__ and pip._vendor.cachecontrol.compat.

Copy link
Member Author

@dstufft dstufft Aug 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of those files still exist.

@@ -17,7 +17,9 @@
# to add socks as yet another dependency for pip, nor do I want to allow-stder
# in the DEP-8 tests, so just suppress the warning. pdb tells me this has to
# be done before the import of pip.vcs.
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
from pip._internal.vendor.requests.packages.urllib3.exceptions import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keeping vendored packages in pip._vendor?

I know it's bike shedding but if everyone agrees it's a nicer colour, that's good too. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me.

@dstufft dstufft changed the title [WIP] Move all internal APIs to pip._internal Move all internal APIs to pip._internal Aug 31, 2017
@ghost
Copy link

ghost commented Aug 31, 2017

Is this going to be merged soon? If so, then I probably need to merge this branch into my PR to avoid conflicts.

Since de-vendoring support exists only for downstream, and they need
to patch pip to get that support anyways, it seems reasonable to push
support for testing that configuration onto them. This is something
they need to do anyways, since they need to test their versions of the
vendored libraries.

See pypa#4657 for more information.
@dstufft
Copy link
Member Author

dstufft commented Aug 31, 2017

@xoviat Yes, right now actually.

@dstufft dstufft merged commit a9d56c7 into pypa:master Aug 31, 2017
@dstufft dstufft deleted the make-internal branch August 31, 2017 19:59
@benoit-pierre
Copy link
Member

Note that this will break virtualenv at some point, since even something like python -c 'import pip; pip.main(...) won't work anymore.

I know using pip's internal API is unsupported outside of pip, but there's a difference between not supporting outside use (and saying so when a related bug is open) and actively breaking every project in existence that might be using it...

@pradyunsg
Copy link
Member

@benoit-pierre Sorry if I'm being nosy but could you explain how this affects virtualenv? I'm not understanding that...

@benoit-pierre
Copy link
Member

@dstufft
Copy link
Member Author

dstufft commented Sep 1, 2017

It won't break virtualenv until virtualenv bundles a new copy of pip, at which point virtualenv can be updated.

@ghost
Copy link

ghost commented Sep 1, 2017

As far as I know, that only depends on pip.main, which is "semi-suppported."

@dstufft What about importing pip.__main__:main into the pip namespace?

@ghost
Copy link

ghost commented Sep 1, 2017

Okay then, apparently not going to happen.

@pradyunsg
Copy link
Member

pradyunsg commented Sep 1, 2017

see https://github.com/pypa/virtualenv/blob/master/virtualenv.py#L855

So, if someone does pip install -U pip in an old virtualenv, their environment would break?

What about importing pip.__main__:main into the pip namespace?

Please no... That would defeat the whole purpose of doing this change.

@benoit-pierre
Copy link
Member

benoit-pierre commented Sep 1, 2017

What about this virtualenv API use-case:

python -c 'import sys, virtualenv; virtualenv.create_environment(sys.argv[1], search_dirs=sys.argv[2:]) venv directory_with_updated_wheels

?

@RonnyPfannschmidt
Copy link
Contributor

@pradyunsg as far as i can tell the environment would not break at all - the script is only executed with a self-defined pythonpath

@dstufft
Copy link
Member Author

dstufft commented Sep 1, 2017

Virtualenv uses a bundled copy of pip. The only way that would change is if someone has explicitly overridden the bundled copy of pip (as @benoit-pierre posted above). But we don't, and have never attempted to support arbitrary versions of pip in that (virtualenv does more than just call pip.main(), so it is vulnerable to API breakages).

@techtonik
Copy link
Contributor

Why additional src level? What else is supposed to be placed there?

@pfmoore
Copy link
Member

pfmoore commented Sep 7, 2017

Because it avoids import pip in a pip checkout from accidentally picking up the development version rather than the installed version. Sometimes this is what you want, but from our overall experience, it's more often a mistake.

@derekbekoe
Copy link

This change will be in the next release of pip?
Is there currently a schedule for this?

@dstufft
Copy link
Member Author

dstufft commented Sep 13, 2017

Yes it will be part of the next release, there is no ETA at the moment.

@pradyunsg pradyunsg added this to the 10.0 milestone Oct 2, 2017
@pradyunsg pradyunsg added the type: maintenance Related to Development and Maintenance Processes label Oct 2, 2017
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation type: maintenance Related to Development and Maintenance Processes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants