Skip to content
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

Add type annotations to most of the files in pip/_internal #6038

Closed
wants to merge 16 commits into from
Closed
34 changes: 25 additions & 9 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
from pip import __file__ as pip_location
from pip._internal.utils.misc import call_subprocess
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.utils.ui import open_spinner

if MYPY_CHECK_RUNNING:
from typing import Tuple, Set, Iterable, Optional, List # noqa: F401
from pip._internal.index import PackageFinder # noqa: F401

logger = logging.getLogger(__name__)


class _Prefix:

def __init__(self, path):
# type: (str) -> None
self.path = path
self.setup = False
self.bin_dir = get_paths(
Expand All @@ -30,8 +36,8 @@ def __init__(self, path):
)['scripts']
# Note: prefer distutils' sysconfig to get the
# library paths so PyPy is correctly supported.
purelib = get_python_lib(plat_specific=0, prefix=path)
platlib = get_python_lib(plat_specific=1, prefix=path)
purelib = get_python_lib(plat_specific=False, prefix=path)
platlib = get_python_lib(plat_specific=True, prefix=path)
if purelib == platlib:
self.lib_dirs = [purelib]
else:
Expand All @@ -43,6 +49,7 @@ class BuildEnvironment(object):
"""

def __init__(self):
# type: () -> None
self._temp_dir = TempDirectory(kind="build-env")
self._temp_dir.create()

Expand All @@ -51,8 +58,8 @@ def __init__(self):
for name in ('normal', 'overlay')
))

self._bin_dirs = []
self._lib_dirs = []
self._bin_dirs = [] # type: List[str]
self._lib_dirs = [] # type: List[str]
for prefix in reversed(list(self._prefixes.values())):
self._bin_dirs.append(prefix.bin_dir)
self._lib_dirs.extend(prefix.lib_dirs)
Expand All @@ -62,8 +69,8 @@ def __init__(self):
# - prevent access to system site packages
system_sites = {
os.path.normcase(site) for site in (
get_python_lib(plat_specific=0),
get_python_lib(plat_specific=1),
get_python_lib(plat_specific=False),
get_python_lib(plat_specific=True),
)
}
self._site_dir = os.path.join(self._temp_dir.path, 'site')
Expand Down Expand Up @@ -124,9 +131,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
os.environ[varname] = old_value

def cleanup(self):
# type: () -> None
self._temp_dir.cleanup()

def check_requirements(self, reqs):
# type: (Iterable[str]) -> Tuple[Set[Tuple[str, str]], Set[str]]
"""Return 2 sets:
- conflicting requirements: set of (installed, wanted) reqs tuples
- missing requirements: set of reqs
Expand All @@ -144,8 +153,15 @@ def check_requirements(self, reqs):
str(e.args[1])))
return conflicting, missing

def install_requirements(self, finder, requirements, prefix, message):
prefix = self._prefixes[prefix]
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: Optional[str]
):
# type: (...) -> None
prefix = self._prefixes[prefix_as_string]
assert not prefix.setup
prefix.setup = True
if not requirements:
Expand All @@ -154,7 +170,7 @@ def install_requirements(self, finder, requirements, prefix, message):
sys.executable, os.path.dirname(pip_location), 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
]
] # type: List[str]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append('-v')
for format_control in ('no_binary', 'only_binary'):
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Optional, List, Union, Tuple, Any # noqa: F401
from typing import Optional, List, Tuple, Any # noqa: F401
from optparse import Values # noqa: F401
from pip._internal.cache import WheelCache # noqa: F401
from pip._internal.req.req_set import RequirementSet # noqa: F401
Expand Down
Loading