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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .landscape.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ignore-paths:
- pip/_vendor/
- src/pip/_vendor/
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ matrix:
python: 2.7
- env: TOXENV=py36
python: 3.6
# Unvendored
- env: "TOXENV=py27 VENDOR=no WHEELS=yes"
python: 2.7
- env: "TOXENV=py36 VENDOR=no WHEELS=yes"
python: 3.6
# All the other Py3 versions
- env: TOXENV=py33
python: 3.3
Expand Down
38 changes: 0 additions & 38 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,6 @@
set -e
set -x

# We want to create the virtual environment here, but not actually run anything
tox --notest

# If we have a VENDOR=no then we want to reinstall pip into the virtual
# environment without the vendor directory included as well as install the
# dependencies we need installed.
if [[ $VENDOR = "no" ]]; then
# Install our dependencies if we're not installing from wheels
if [[ $WHEELS != "yes" ]]; then
.tox/$TOXENV/bin/pip install -r pip/_vendor/vendor.txt --no-deps
fi

# Install our dependencies if we're installing from wheels
if [[ $WHEELS = "yes" ]]; then
mkdir -p /tmp/wheels
pip wheel --wheel-dir /tmp/wheels --no-deps -r pip/_vendor/vendor.txt
cp /tmp/wheels/* `echo .tox/$TOXENV/lib/python*/site-packages/pip/_vendor/`
fi

# Remove the vendored dependencies from within the installed pip inside of
# our installed copy of pip.
find .tox/$TOXENV/lib/python*/site-packages/pip/_vendor -d \
-not -regex '.*/pip/_vendor/__init__\.py$' \
-not -regex '.*/pip/_vendor$' \
-exec rm -rf {} \;

# Patch our installed pip/_vendor/__init__.py so that it knows to look for
# the vendored dependencies instead of only looking for the vendored.
sed -i 's/DEBUNDLED = False/DEBUNDLED = True/' \
.tox/$TOXENV/lib/python*/site-packages/pip/_vendor/__init__.py

# Test to make sure that we successfully installed without vendoring
if [ -f .tox/$TOXENV/lib/python*/site-packages/pip/_vendor/six.py ]; then
echo "Did not successfully unvendor"
exit 1
fi
fi

if [[ $TOXENV == py* ]]; then
# Run unit tests
tox -- -m unit
Expand Down
8 changes: 4 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ include LICENSE.txt
include NEWS.rst
include README.rst
include pyproject.toml
include pip/_vendor/README.rst
include pip/_vendor/vendor.txt
include src/pip/_vendor/README.rst
include src/pip/_vendor/vendor.txt

exclude .coveragerc
exclude .mailmap
exclude .travis.yml
exclude .landscape.yml
exclude pip/_vendor/Makefile
exclude src/pip/_vendor/Makefile
exclude tox.ini
exclude dev-requirements.txt
exclude appveyor.yml

recursive-include pip/_vendor *.pem
recursive-include src/pip/_vendor *.pem
recursive-include docs Makefile *.rst *.py *.bat

prune .github
Expand Down
6 changes: 3 additions & 3 deletions docs/pipext.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from docutils.parsers import rst
from docutils.statemachine import ViewList
from textwrap import dedent
from pip.commands import commands_dict as commands
from pip import cmdoptions
from pip.utils import get_prog
from pip._internal import cmdoptions
from pip._internal.commands import commands_dict as commands
from pip._internal.utils.misc import get_prog


class PipCommandUsage(rst.Directive):
Expand Down
2 changes: 2 additions & 0 deletions news/4696.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Move all of pip's APIs into the pip._internal package, properly reflecting the
fact that pip does not currently have any public APIs.
2 changes: 2 additions & 0 deletions news/4700.removal
Original file line number Diff line number Diff line change
@@ -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.

fact that pip does not currently have any public APIs.
4 changes: 0 additions & 4 deletions pip/models/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude = .tox,.idea,*.egg,build,_vendor,data
select = E,W,F

[tool:pytest]
addopts = --ignore pip/_vendor --ignore tests/tests_cache
addopts = --ignore src/pip/_vendor --ignore tests/tests_cache

[bdist_wheel]
universal=1
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def find_version(*file_paths):

setup(
name="pip",
version=find_version("pip", "__init__.py"),
version=find_version("src", "pip", "__init__.py"),
description="The PyPA recommended tool for installing Python packages.",
long_description=long_description,
classifiers=[
Expand All @@ -60,7 +60,11 @@ def find_version(*file_paths):
author_email='[email protected]',
url='https://pip.pypa.io/',
license='MIT',
packages=find_packages(exclude=["contrib", "docs", "tests*", "tasks"]),
package_dir={"": "src"},
packages=find_packages(
where="src",
exclude=["contrib", "docs", "tests*", "tasks"],
),
package_data={
"pip._vendor.certifi": ["*.pem"],
"pip._vendor.requests": ["*.pem"],
Expand All @@ -69,9 +73,9 @@ def find_version(*file_paths):
},
entry_points={
"console_scripts": [
"pip=pip:main",
"pip%s=pip:main" % sys.version[:1],
"pip%s=pip:main" % sys.version[:3],
"pip=pip._internal:main",
"pip%s=pip._internal:main" % sys.version[:1],
"pip%s=pip._internal:main" % sys.version[:3],
],
},
tests_require=tests_require,
Expand Down
1 change: 1 addition & 0 deletions src/pip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "10.0.0.dev0"
4 changes: 2 additions & 2 deletions pip/__main__.py → src/pip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

import pip # noqa
from pip._internal import main as _main # noqa

if __name__ == '__main__':
sys.exit(pip.main())
sys.exit(_main())
30 changes: 13 additions & 17 deletions pip/__init__.py → src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
else:
securetransport.inject_into_urllib3()

from pip.exceptions import CommandError, PipError
from pip.utils import get_installed_distributions, get_prog
from pip.utils import deprecation
from pip.vcs import git, mercurial, subversion, bazaar # noqa
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.commands import get_summaries, get_similar_commands
from pip.commands import commands_dict
from pip import __version__
from pip._internal import cmdoptions
from pip._internal.exceptions import CommandError, PipError
from pip._internal.utils.misc import get_installed_distributions, get_prog
from pip._internal.utils import deprecation
from pip._internal.vcs import git, mercurial, subversion, bazaar # noqa
from pip._internal.baseparser import (
ConfigOptionParser, UpdatingDefaultsHelpFormatter,
)
from pip._internal.commands import get_summaries, get_similar_commands
from pip._internal.commands import commands_dict
from pip._vendor.requests.packages.urllib3.exceptions import (
InsecureRequestWarning,
)
Expand All @@ -57,12 +61,8 @@
# This fixes a peculiarity when importing via __import__ - as we are
# initialising the pip module, "from pip import cmdoptions" is recursive
# and appears not to work properly in that situation.
import pip.cmdoptions
cmdoptions = pip.cmdoptions

# The version as used in the setup.py and the docs conf.py
__version__ = "10.0.0.dev0"

# import pip._internal.cmdoptions
# cmdoptions = pip._internal.cmdoptions

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -249,7 +249,3 @@ def main(args=None):
logger.debug("Ignoring error %s when setting locale", e)
command = commands_dict[cmd_name](isolated=check_isolated(cmd_args))
return command.main(cmd_args)


if __name__ == '__main__':
sys.exit(main())
39 changes: 23 additions & 16 deletions pip/basecommand.py → src/pip/_internal/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@
import sys
import warnings

from pip import cmdoptions
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.compat import WINDOWS
from pip.download import PipSession
from pip.exceptions import (
from pip._internal import cmdoptions
from pip._internal.baseparser import (
ConfigOptionParser, UpdatingDefaultsHelpFormatter
)
from pip._internal.compat import WINDOWS
from pip._internal.download import PipSession
from pip._internal.exceptions import (
BadCommand, CommandError, InstallationError, PreviousBuildDirError,
UninstallationError
)
from pip.index import PackageFinder
from pip.locations import running_under_virtualenv
from pip.req import InstallRequirement, parse_requirements
from pip.status_codes import (
from pip._internal.index import PackageFinder
from pip._internal.locations import running_under_virtualenv
from pip._internal.req import InstallRequirement, parse_requirements
from pip._internal.status_codes import (
ERROR, PREVIOUS_BUILD_DIR_ERROR, SUCCESS, UNKNOWN_ERROR,
VIRTUALENV_NOT_FOUND
)
from pip.utils import deprecation, get_prog, normalize_path
from pip.utils.logging import IndentingFormatter
from pip.utils.outdated import pip_version_check
from pip._internal.utils import deprecation
from pip._internal.utils.logging import IndentingFormatter
from pip._internal.utils.misc import get_prog, normalize_path
from pip._internal.utils.outdated import pip_version_check

__all__ = ['Command']

Expand Down Expand Up @@ -130,7 +133,7 @@ def main(self, args):
"disable_existing_loggers": False,
"filters": {
"exclude_warnings": {
"()": "pip.utils.logging.MaxLevelFilter",
"()": "pip._internal.utils.logging.MaxLevelFilter",
"level": logging.WARNING,
},
},
Expand All @@ -143,20 +146,24 @@ def main(self, args):
"handlers": {
"console": {
"level": level,
"class": "pip.utils.logging.ColorizedStreamHandler",
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"stream": self.log_streams[0],
"filters": ["exclude_warnings"],
"formatter": "indent",
},
"console_errors": {
"level": "WARNING",
"class": "pip.utils.logging.ColorizedStreamHandler",
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"stream": self.log_streams[1],
"formatter": "indent",
},
"user_log": {
"level": "DEBUG",
"class": "pip.utils.logging.BetterRotatingFileHandler",
"class":
("pip._internal.utils.logging"
".BetterRotatingFileHandler"),
"filename": options.log or "/dev/null",
"delay": True,
"formatter": "indent",
Expand Down
4 changes: 2 additions & 2 deletions pip/baseparser.py → src/pip/_internal/baseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from pip._vendor.six import string_types

from pip.configuration import Configuration
from pip.utils import get_terminal_size
from pip._internal.configuration import Configuration
from pip._internal.utils.misc import get_terminal_size

logger = logging.getLogger(__name__)

Expand Down
12 changes: 6 additions & 6 deletions pip/cache.py → src/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from pip._vendor.packaging.utils import canonicalize_name

import pip.index
from pip.compat import expanduser
from pip.download import path_to_url
from pip.wheel import InvalidWheelFilename, Wheel
from pip._internal import index
from pip._internal.compat import expanduser
from pip._internal.download import path_to_url
from pip._internal.wheel import InvalidWheelFilename, Wheel

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -71,7 +71,7 @@ def _get_candidates(self, link, package_name):
return []

canonical_name = canonicalize_name(package_name)
formats = pip.index.fmt_ctl_formats(
formats = index.fmt_ctl_formats(
self.format_control, canonical_name
)
if not self.allowed_formats.intersection(formats):
Expand Down Expand Up @@ -100,7 +100,7 @@ def _link_for_candidate(self, link, candidate):
root = self.get_path_for_link(link)
path = os.path.join(root, candidate)

return pip.index.Link(path_to_url(path))
return index.Link(path_to_url(path))


class WheelCache(Cache):
Expand Down
10 changes: 5 additions & 5 deletions pip/cmdoptions.py → src/pip/_internal/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from functools import partial
from optparse import SUPPRESS_HELP, Option, OptionGroup

from pip.index import (
from pip._internal.index import (
FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_binary
)
from pip.locations import USER_CACHE_DIR, src_prefix
from pip.models import PyPI
from pip.utils.hashes import STRONG_HASHES
from pip.utils.ui import BAR_TYPES
from pip._internal.locations import USER_CACHE_DIR, src_prefix
from pip._internal.models import PyPI
from pip._internal.utils.hashes import STRONG_HASHES
from pip._internal.utils.ui import BAR_TYPES


def make_option_group(group, parser):
Expand Down
26 changes: 13 additions & 13 deletions pip/commands/__init__.py → src/pip/_internal/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"""
from __future__ import absolute_import

from pip.commands.completion import CompletionCommand
from pip.commands.configuration import ConfigurationCommand
from pip.commands.download import DownloadCommand
from pip.commands.freeze import FreezeCommand
from pip.commands.hash import HashCommand
from pip.commands.help import HelpCommand
from pip.commands.list import ListCommand
from pip.commands.check import CheckCommand
from pip.commands.search import SearchCommand
from pip.commands.show import ShowCommand
from pip.commands.install import InstallCommand
from pip.commands.uninstall import UninstallCommand
from pip.commands.wheel import WheelCommand
from pip._internal.commands.completion import CompletionCommand
from pip._internal.commands.configuration import ConfigurationCommand
from pip._internal.commands.download import DownloadCommand
from pip._internal.commands.freeze import FreezeCommand
from pip._internal.commands.hash import HashCommand
from pip._internal.commands.help import HelpCommand
from pip._internal.commands.list import ListCommand
from pip._internal.commands.check import CheckCommand
from pip._internal.commands.search import SearchCommand
from pip._internal.commands.show import ShowCommand
from pip._internal.commands.install import InstallCommand
from pip._internal.commands.uninstall import UninstallCommand
from pip._internal.commands.wheel import WheelCommand

commands_order = [
InstallCommand,
Expand Down
6 changes: 3 additions & 3 deletions pip/commands/check.py → src/pip/_internal/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging

from pip.basecommand import Command
from pip.operations.check import check_requirements
from pip.utils import get_installed_distributions
from pip._internal.basecommand import Command
from pip._internal.operations.check import check_requirements
from pip._internal.utils.misc import get_installed_distributions

logger = logging.getLogger(__name__)

Expand Down
Loading