Skip to content

Commit 5f7189b

Browse files
authored
Merge pull request #10187 from harupy/type-annotations-operations
2 parents f0323c7 + 860ba76 commit 5f7189b

File tree

10 files changed

+237
-284
lines changed

10 files changed

+237
-284
lines changed

src/pip/_internal/operations/build/metadata.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from pip._internal.utils.temp_dir import TempDirectory
1111

1212

13-
def generate_metadata(build_env, backend):
14-
# type: (BuildEnvironment, Pep517HookCaller) -> str
13+
def generate_metadata(build_env: BuildEnvironment, backend: Pep517HookCaller) -> str:
1514
"""Generate metadata using mechanisms described in PEP 517.
1615
1716
Returns the generated metadata directory.

src/pip/_internal/operations/build/metadata_legacy.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16-
def _find_egg_info(directory):
17-
# type: (str) -> str
16+
def _find_egg_info(directory: str) -> str:
1817
"""Find an .egg-info subdirectory in `directory`.
1918
"""
2019
filenames = [
@@ -37,13 +36,12 @@ def _find_egg_info(directory):
3736

3837

3938
def generate_metadata(
40-
build_env, # type: BuildEnvironment
41-
setup_py_path, # type: str
42-
source_dir, # type: str
43-
isolated, # type: bool
44-
details, # type: str
45-
):
46-
# type: (...) -> str
39+
build_env: BuildEnvironment,
40+
setup_py_path: str,
41+
source_dir: str,
42+
isolated: bool,
43+
details: str,
44+
) -> str:
4745
"""Generate metadata using setup.py-based defacto mechanisms.
4846
4947
Returns the generated metadata directory.

src/pip/_internal/operations/build/wheel.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111

1212
def build_wheel_pep517(
13-
name, # type: str
14-
backend, # type: Pep517HookCaller
15-
metadata_directory, # type: str
16-
tempd, # type: str
17-
):
18-
# type: (...) -> Optional[str]
13+
name: str,
14+
backend: Pep517HookCaller,
15+
metadata_directory: str,
16+
tempd: str,
17+
) -> Optional[str]:
1918
"""Build one InstallRequirement using the PEP 517 build process.
2019
2120
Returns path to wheel if successfully built. Otherwise, returns None.

src/pip/_internal/operations/build/wheel_legacy.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515

1616
def format_command_result(
17-
command_args, # type: List[str]
18-
command_output, # type: str
19-
):
20-
# type: (...) -> str
17+
command_args: List[str],
18+
command_output: str,
19+
) -> str:
2120
"""Format command information for logging."""
2221
command_desc = format_command_args(command_args)
2322
text = f'Command arguments: {command_desc}\n'
@@ -35,13 +34,12 @@ def format_command_result(
3534

3635

3736
def get_legacy_build_wheel_path(
38-
names, # type: List[str]
39-
temp_dir, # type: str
40-
name, # type: str
41-
command_args, # type: List[str]
42-
command_output, # type: str
43-
):
44-
# type: (...) -> Optional[str]
37+
names: List[str],
38+
temp_dir: str,
39+
name: str,
40+
command_args: List[str],
41+
command_output: str,
42+
) -> Optional[str]:
4543
"""Return the path to the wheel in the temporary build directory."""
4644
# Sort for determinism.
4745
names = sorted(names)
@@ -65,14 +63,13 @@ def get_legacy_build_wheel_path(
6563

6664

6765
def build_wheel_legacy(
68-
name, # type: str
69-
setup_py_path, # type: str
70-
source_dir, # type: str
71-
global_options, # type: List[str]
72-
build_options, # type: List[str]
73-
tempd, # type: str
74-
):
75-
# type: (...) -> Optional[str]
66+
name: str,
67+
setup_py_path: str,
68+
source_dir: str,
69+
global_options: List[str],
70+
build_options: List[str],
71+
tempd: str,
72+
) -> Optional[str]:
7673
"""Build one unpacked package using the "legacy" build process.
7774
7875
Returns path to wheel if successfully built. Otherwise, returns None.

src/pip/_internal/operations/check.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def create_package_set_from_installed() -> Tuple[PackageSet, bool]:
5151
return package_set, problems
5252

5353

54-
def check_package_set(package_set, should_ignore=None):
55-
# type: (PackageSet, Optional[Callable[[str], bool]]) -> CheckResult
54+
def check_package_set(
55+
package_set: PackageSet, should_ignore: Optional[Callable[[str], bool]] = None
56+
) -> CheckResult:
5657
"""Check if a package set is consistent
5758
5859
If should_ignore is passed, it should be a callable that takes a
@@ -64,8 +65,8 @@ def check_package_set(package_set, should_ignore=None):
6465

6566
for package_name, package_detail in package_set.items():
6667
# Info about dependencies of package_name
67-
missing_deps = set() # type: Set[Missing]
68-
conflicting_deps = set() # type: Set[Conflicting]
68+
missing_deps: Set[Missing] = set()
69+
conflicting_deps: Set[Conflicting] = set()
6970

7071
if should_ignore and should_ignore(package_name):
7172
continue
@@ -95,8 +96,7 @@ def check_package_set(package_set, should_ignore=None):
9596
return missing, conflicting
9697

9798

98-
def check_install_conflicts(to_install):
99-
# type: (List[InstallRequirement]) -> ConflictDetails
99+
def check_install_conflicts(to_install: List[InstallRequirement]) -> ConflictDetails:
100100
"""For checking if the dependency graph would be consistent after \
101101
installing given requirements
102102
"""
@@ -116,8 +116,9 @@ def check_install_conflicts(to_install):
116116
)
117117

118118

119-
def _simulate_installation_of(to_install, package_set):
120-
# type: (List[InstallRequirement], PackageSet) -> Set[NormalizedName]
119+
def _simulate_installation_of(
120+
to_install: List[InstallRequirement], package_set: PackageSet
121+
) -> Set["NormalizedName"]:
121122
"""Computes the version of packages after installing to_install.
122123
"""
123124
# Keep track of packages that were installed
@@ -137,8 +138,9 @@ def _simulate_installation_of(to_install, package_set):
137138
return installed
138139

139140

140-
def _create_whitelist(would_be_installed, package_set):
141-
# type: (Set[NormalizedName], PackageSet) -> Set[NormalizedName]
141+
def _create_whitelist(
142+
would_be_installed: Set["NormalizedName"], package_set: PackageSet
143+
) -> Set["NormalizedName"]:
142144
packages_affected = set(would_be_installed)
143145

144146
for package_name in package_set:

src/pip/_internal/operations/freeze.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ class _EditableInfo(NamedTuple):
3636

3737

3838
def freeze(
39-
requirement=None, # type: Optional[List[str]]
40-
local_only=False, # type: bool
41-
user_only=False, # type: bool
42-
paths=None, # type: Optional[List[str]]
43-
isolated=False, # type: bool
44-
exclude_editable=False, # type: bool
45-
skip=() # type: Container[str]
46-
):
47-
# type: (...) -> Iterator[str]
48-
installations = {} # type: Dict[str, FrozenRequirement]
39+
requirement: Optional[List[str]] = None,
40+
local_only: bool = False,
41+
user_only: bool = False,
42+
paths: Optional[List[str]] = None,
43+
isolated: bool = False,
44+
exclude_editable: bool = False,
45+
skip: Container[str] = ()
46+
) -> Iterator[str]:
47+
installations: Dict[str, FrozenRequirement] = {}
4948

5049
dists = get_environment(paths).iter_installed_distributions(
5150
local_only=local_only,
@@ -63,10 +62,10 @@ def freeze(
6362
# should only be emitted once, even if the same option is in multiple
6463
# requirements files, so we need to keep track of what has been emitted
6564
# so that we don't emit it again if it's seen again
66-
emitted_options = set() # type: Set[str]
65+
emitted_options: Set[str] = set()
6766
# keep track of which files a requirement is in so that we can
6867
# give an accurate warning if a requirement appears multiple times.
69-
req_files = collections.defaultdict(list) # type: Dict[str, List[str]]
68+
req_files: Dict[str, List[str]] = collections.defaultdict(list)
7069
for req_file_path in requirement:
7170
with open(req_file_path) as req_file:
7271
for line in req_file:
@@ -241,8 +240,13 @@ def _get_editable_info(dist: BaseDistribution) -> _EditableInfo:
241240

242241

243242
class FrozenRequirement:
244-
def __init__(self, name, req, editable, comments=()):
245-
# type: (str, Union[str, Requirement], bool, Iterable[str]) -> None
243+
def __init__(
244+
self,
245+
name: str,
246+
req: Union[str, Requirement],
247+
editable: bool,
248+
comments: Iterable[str] = (),
249+
) -> None:
246250
self.name = name
247251
self.canonical_name = canonicalize_name(name)
248252
self.req = req
@@ -269,8 +273,7 @@ def from_dist(cls, dist: BaseDistribution) -> "FrozenRequirement":
269273

270274
return cls(dist.raw_name, req, editable, comments=comments)
271275

272-
def __str__(self):
273-
# type: () -> str
276+
def __str__(self) -> str:
274277
req = self.req
275278
if self.editable:
276279
req = f'-e {req}'

src/pip/_internal/operations/install/editable_legacy.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212

1313

1414
def install_editable(
15-
install_options, # type: List[str]
16-
global_options, # type: Sequence[str]
17-
prefix, # type: Optional[str]
18-
home, # type: Optional[str]
19-
use_user_site, # type: bool
20-
name, # type: str
21-
setup_py_path, # type: str
22-
isolated, # type: bool
23-
build_env, # type: BuildEnvironment
24-
unpacked_source_directory, # type: str
25-
):
26-
# type: (...) -> None
15+
install_options: List[str],
16+
global_options: Sequence[str],
17+
prefix: Optional[str],
18+
home: Optional[str],
19+
use_user_site: bool,
20+
name: str,
21+
setup_py_path: str,
22+
isolated: bool,
23+
build_env: BuildEnvironment,
24+
unpacked_source_directory: str,
25+
) -> None:
2726
"""Install a package in editable mode. Most arguments are pass-through
2827
to setuptools.
2928
"""

src/pip/_internal/operations/install/legacy.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121

2222
class LegacyInstallFailure(Exception):
23-
def __init__(self):
24-
# type: () -> None
23+
def __init__(self) -> None:
2524
self.parent = sys.exc_info()
2625

2726

@@ -30,8 +29,7 @@ def write_installed_files_from_setuptools_record(
3029
root: Optional[str],
3130
req_description: str,
3231
) -> None:
33-
def prepend_root(path):
34-
# type: (str) -> str
32+
def prepend_root(path: str) -> str:
3533
if root is None or not os.path.isabs(path):
3634
return path
3735
else:
@@ -55,9 +53,7 @@ def prepend_root(path):
5553
filename = line.strip()
5654
if os.path.isdir(filename):
5755
filename += os.path.sep
58-
new_lines.append(
59-
os.path.relpath(prepend_root(filename), egg_info_dir)
60-
)
56+
new_lines.append(os.path.relpath(prepend_root(filename), egg_info_dir))
6157
new_lines.sort()
6258
ensure_dir(egg_info_dir)
6359
inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
@@ -66,22 +62,21 @@ def prepend_root(path):
6662

6763

6864
def install(
69-
install_options, # type: List[str]
70-
global_options, # type: Sequence[str]
71-
root, # type: Optional[str]
72-
home, # type: Optional[str]
73-
prefix, # type: Optional[str]
74-
use_user_site, # type: bool
75-
pycompile, # type: bool
76-
scheme, # type: Scheme
77-
setup_py_path, # type: str
78-
isolated, # type: bool
79-
req_name, # type: str
80-
build_env, # type: BuildEnvironment
81-
unpacked_source_directory, # type: str
82-
req_description, # type: str
83-
):
84-
# type: (...) -> bool
65+
install_options: List[str],
66+
global_options: Sequence[str],
67+
root: Optional[str],
68+
home: Optional[str],
69+
prefix: Optional[str],
70+
use_user_site: bool,
71+
pycompile: bool,
72+
scheme: Scheme,
73+
setup_py_path: str,
74+
isolated: bool,
75+
req_name: str,
76+
build_env: BuildEnvironment,
77+
unpacked_source_directory: str,
78+
req_description: str,
79+
) -> bool:
8580

8681
header_dir = scheme.headers
8782

0 commit comments

Comments
 (0)