-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Use strict optional checking in req_install.py #11379
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
63e13c7
Use strict optional checking in req_install.py
hauntsaninja 44ffeb2
news
hauntsaninja ef6152d
black
hauntsaninja 156ba98
inline asserts
hauntsaninja f1b4be9
code review
hauntsaninja 12e95f6
Merge remote-tracking branch 'upstream/main' into strict-optional-ins…
hauntsaninja 339a31b
fix up merge issue
hauntsaninja 0d82e5d
fix specifier bug
hauntsaninja 9b0400e
Merge branch 'main' into strict-optional-install
hauntsaninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| # The following comment should be removed at some point in the future. | ||
| # mypy: strict-optional=False | ||
|
|
||
| import functools | ||
| import logging | ||
| import os | ||
|
|
@@ -244,6 +241,7 @@ def supports_pyproject_editable(self) -> bool: | |
|
|
||
| @property | ||
| def specifier(self) -> SpecifierSet: | ||
| assert self.req is not None | ||
| return self.req.specifier | ||
|
|
||
| @property | ||
|
|
@@ -257,7 +255,8 @@ def is_pinned(self) -> bool: | |
|
|
||
| For example, some-package==1.2 is pinned; some-package>1.2 is not. | ||
| """ | ||
| specifiers = self.specifier | ||
| assert self.req is not None | ||
| specifiers = self.req.specifier | ||
| return len(specifiers) == 1 and next(iter(specifiers)).operator in {"==", "==="} | ||
|
|
||
| def match_markers(self, extras_requested: Optional[Iterable[str]] = None) -> bool: | ||
|
|
@@ -305,6 +304,7 @@ def hashes(self, trust_internet: bool = True) -> Hashes: | |
| else: | ||
| link = None | ||
| if link and link.hash: | ||
| assert link.hash_name is not None | ||
| good_hashes.setdefault(link.hash_name, []).append(link.hash) | ||
| return Hashes(good_hashes) | ||
|
|
||
|
|
@@ -314,6 +314,7 @@ def from_path(self) -> Optional[str]: | |
| return None | ||
| s = str(self.req) | ||
| if self.comes_from: | ||
| comes_from: Optional[str] | ||
| if isinstance(self.comes_from, str): | ||
| comes_from = self.comes_from | ||
| else: | ||
|
|
@@ -345,7 +346,7 @@ def ensure_build_location( | |
|
|
||
| # When parallel builds are enabled, add a UUID to the build directory | ||
| # name so multiple builds do not interfere with each other. | ||
| dir_name: str = canonicalize_name(self.name) | ||
| dir_name: str = canonicalize_name(self.req.name) | ||
uranusjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if parallel_builds: | ||
| dir_name = f"{dir_name}_{uuid.uuid4().hex}" | ||
|
|
||
|
|
@@ -388,6 +389,7 @@ def _set_requirement(self) -> None: | |
| ) | ||
|
|
||
| def warn_on_mismatching_name(self) -> None: | ||
| assert self.req is not None | ||
| metadata_name = canonicalize_name(self.metadata["Name"]) | ||
| if canonicalize_name(self.req.name) == metadata_name: | ||
| # Everything is fine. | ||
|
|
@@ -457,6 +459,7 @@ def is_wheel_from_cache(self) -> bool: | |
| # Things valid for sdists | ||
| @property | ||
| def unpacked_source_directory(self) -> str: | ||
| assert self.source_dir, f"No source dir for {self}" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is one place where we could raise an AssertionError where the existing code would not fail: if |
||
| return os.path.join( | ||
| self.source_dir, self.link and self.link.subdirectory_fragment or "" | ||
| ) | ||
|
|
@@ -543,7 +546,7 @@ def prepare_metadata(self) -> None: | |
| Under PEP 517 and PEP 660, call the backend hook to prepare the metadata. | ||
| Under legacy processing, call setup.py egg-info. | ||
| """ | ||
| assert self.source_dir | ||
| assert self.source_dir, f"No source dir for {self}" | ||
| details = self.name or f"from {self.link}" | ||
|
|
||
| if self.use_pep517: | ||
|
|
@@ -592,18 +595,20 @@ def get_dist(self) -> BaseDistribution: | |
| if self.metadata_directory: | ||
| return get_directory_distribution(self.metadata_directory) | ||
| elif self.local_file_path and self.is_wheel: | ||
| assert self.req is not None | ||
| return get_wheel_distribution( | ||
| FilesystemWheel(self.local_file_path), canonicalize_name(self.name) | ||
| FilesystemWheel(self.local_file_path), | ||
| canonicalize_name(self.req.name), | ||
| ) | ||
| raise AssertionError( | ||
| f"InstallRequirement {self} has no metadata directory and no wheel: " | ||
| f"can't make a distribution." | ||
| ) | ||
|
|
||
| def assert_source_matches_version(self) -> None: | ||
| assert self.source_dir | ||
| assert self.source_dir, f"No source dir for {self}" | ||
| version = self.metadata["version"] | ||
| if self.req.specifier and version not in self.req.specifier: | ||
| if self.req and self.req.specifier and version not in self.req.specifier: | ||
| logger.warning( | ||
| "Requested %s, but installing version %s", | ||
| self, | ||
|
|
@@ -696,9 +701,10 @@ def _clean_zip_name(name: str, prefix: str) -> str: | |
| name = name.replace(os.path.sep, "/") | ||
| return name | ||
|
|
||
| assert self.req is not None | ||
| path = os.path.join(parentdir, path) | ||
| name = _clean_zip_name(path, rootdir) | ||
| return self.name + "/" + name | ||
| return self.req.name + "/" + name | ||
|
|
||
| def archive(self, build_dir: Optional[str]) -> None: | ||
| """Saves archive to provided build_dir. | ||
|
|
@@ -777,8 +783,9 @@ def install( | |
| use_user_site: bool = False, | ||
| pycompile: bool = True, | ||
| ) -> None: | ||
| assert self.req is not None | ||
| scheme = get_scheme( | ||
| self.name, | ||
| self.req.name, | ||
| user=use_user_site, | ||
| home=home, | ||
| root=root, | ||
|
|
@@ -792,7 +799,7 @@ def install( | |
| prefix=prefix, | ||
| home=home, | ||
| use_user_site=use_user_site, | ||
| name=self.name, | ||
| name=self.req.name, | ||
| setup_py_path=self.setup_py_path, | ||
| isolated=self.isolated, | ||
| build_env=self.build_env, | ||
|
|
@@ -805,7 +812,7 @@ def install( | |
| assert self.local_file_path | ||
|
|
||
| install_wheel( | ||
| self.name, | ||
| self.req.name, | ||
| self.local_file_path, | ||
| scheme=scheme, | ||
| req_description=str(self.req), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.