Skip to content

Commit

Permalink
Merge pull request #7107 from mkurnikov/disallow-untyped-defs-wheel
Browse files Browse the repository at this point in the history
Define untyped defs in pip._internal.wheel
  • Loading branch information
pradyunsg authored Oct 30, 2019
2 parents 0597a6d + 3d3f663 commit 644ff6c
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# The following comment should be removed at some point in the future.
# mypy: strict-optional=False
# mypy: disallow-untyped-defs=False

from __future__ import absolute_import

Expand Down Expand Up @@ -57,7 +56,7 @@
if MYPY_CHECK_RUNNING:
from typing import (
Dict, List, Optional, Sequence, Mapping, Tuple, IO, Text, Any,
Iterable, Callable, Set, Union,
Iterable, Callable, Set, Pattern, Union,
)
from pip._internal.req.req_install import InstallRequirement
from pip._internal.operations.prepare import (
Expand All @@ -78,6 +77,7 @@


def normpath(src, p):
# type: (str, str) -> str
return os.path.relpath(src, p).replace(os.path.sep, '/')


Expand Down Expand Up @@ -185,10 +185,12 @@ def get_entrypoints(filename):
gui = entry_points.get('gui_scripts', {})

def _split_ep(s):
# type: (pkg_resources.EntryPoint) -> Tuple[str, str]
"""get the string representation of EntryPoint,
remove space and split on '='
"""
return str(s).replace(" ", "").split("=")
split_parts = str(s).replace(" ", "").split("=")
return split_parts[0], split_parts[1]

# convert the EntryPoint objects into strings with module:function
console = dict(_split_ep(v) for v in console.values())
Expand Down Expand Up @@ -317,13 +319,15 @@ class MissingCallableSuffix(Exception):


def _raise_for_invalid_entrypoint(specification):
# type: (str) -> None
entry = get_export_entry(specification)
if entry is not None and entry.suffix is None:
raise MissingCallableSuffix(str(entry))


class PipScriptMaker(ScriptMaker):
def make(self, specification, options=None):
# type: (str, Dict[str, Any]) -> List[str]
_raise_for_invalid_entrypoint(specification)
return super(PipScriptMaker, self).make(specification, options)

Expand Down Expand Up @@ -378,14 +382,22 @@ def install_unpacked_wheel(
logger.debug(stdout.getvalue())

def record_installed(srcfile, destfile, modified=False):
# type: (str, str, bool) -> None
"""Map archive RECORD paths to installation RECORD paths."""
oldpath = normpath(srcfile, wheeldir)
newpath = normpath(destfile, lib_dir)
installed[oldpath] = newpath
if modified:
changed.add(destfile)

def clobber(source, dest, is_base, fixer=None, filter=None):
def clobber(
source, # type: str
dest, # type: str
is_base, # type: bool
fixer=None, # type: Optional[Callable[[str], Any]]
filter=None # type: Optional[Callable[[str], bool]]
):
# type: (...) -> None
ensure_dir(dest) # common for the 'include' path

for dir, subdirs, files in os.walk(source):
Expand Down Expand Up @@ -469,6 +481,7 @@ def clobber(source, dest, is_base, fixer=None, filter=None):
console, gui = get_entrypoints(ep_file)

def is_entrypoint_wrapper(name):
# type: (str) -> bool
# EP, EP.exe and EP-script.py are scripts generated for
# entry point EP by setuptools
if name.lower().endswith('.exe'):
Expand Down Expand Up @@ -765,6 +778,7 @@ def supported(self, tags):

def _contains_egg_info(
s, _egg_info_re=re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.I)):
# type: (str, Pattern) -> bool
"""Determine whether the string looks like an egg_info.
:param s: The string to parse. E.g. foo-2.1
Expand Down Expand Up @@ -869,7 +883,7 @@ def should_use_ephemeral_cache(

def format_command_result(
command_args, # type: List[str]
command_output, # type: str
command_output, # type: Text
):
# type: (...) -> str
"""Format command information for logging."""
Expand All @@ -893,7 +907,7 @@ def get_legacy_build_wheel_path(
temp_dir, # type: str
req, # type: InstallRequirement
command_args, # type: List[str]
command_output, # type: str
command_output, # type: Text
):
# type: (...) -> Optional[str]
"""Return the path to the wheel in the temporary build directory."""
Expand All @@ -919,6 +933,7 @@ def get_legacy_build_wheel_path(


def _always_true(_):
# type: (Any) -> bool
return True


Expand Down Expand Up @@ -954,7 +969,13 @@ def __init__(
# file names of built wheel names
self.wheel_filenames = [] # type: List[Union[bytes, Text]]

def _build_one(self, req, output_dir, python_tag=None):
def _build_one(
self,
req, # type: InstallRequirement
output_dir, # type: str
python_tag=None, # type: Optional[str]
):
# type: (...) -> Optional[str]
"""Build one wheel.
:return: The filename of the built wheel, or None if the build failed.
Expand All @@ -964,7 +985,13 @@ def _build_one(self, req, output_dir, python_tag=None):
return self._build_one_inside_env(req, output_dir,
python_tag=python_tag)

def _build_one_inside_env(self, req, output_dir, python_tag=None):
def _build_one_inside_env(
self,
req, # type: InstallRequirement
output_dir, # type: str
python_tag=None, # type: Optional[str]
):
# type: (...) -> Optional[str]
with TempDirectory(kind="wheel") as temp_dir:
if req.use_pep517:
builder = self._build_one_pep517
Expand All @@ -989,7 +1016,13 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None):
self._clean_one(req)
return None

def _build_one_pep517(self, req, tempd, python_tag=None):
def _build_one_pep517(
self,
req, # type: InstallRequirement
tempd, # type: str
python_tag=None, # type: Optional[str]
):
# type: (...) -> Optional[str]
"""Build one InstallRequirement using the PEP 517 build process.
Returns path to wheel if successfully built. Otherwise, returns None.
Expand Down Expand Up @@ -1028,7 +1061,13 @@ def _build_one_pep517(self, req, tempd, python_tag=None):
return None
return os.path.join(tempd, wheel_name)

def _build_one_legacy(self, req, tempd, python_tag=None):
def _build_one_legacy(
self,
req, # type: InstallRequirement
tempd, # type: str
python_tag=None, # type: Optional[str]
):
# type: (...) -> Optional[str]
"""Build one InstallRequirement using the "legacy" build process.
Returns path to wheel if successfully built. Otherwise, returns None.
Expand Down Expand Up @@ -1067,6 +1106,7 @@ def _build_one_legacy(self, req, tempd, python_tag=None):
return wheel_path

def _clean_one(self, req):
# type: (InstallRequirement) -> bool
clean_args = make_setuptools_clean_args(
req.setup_py_path,
global_options=self.global_options,
Expand Down

0 comments on commit 644ff6c

Please sign in to comment.