-
Notifications
You must be signed in to change notification settings - Fork 260
Allow non-existent path dependencies - reloaded #520
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
neersighted
merged 4 commits into
python-poetry:main
from
radoering:non-existing-path-deps
Jan 22, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e0c288b
refactor: introduce abstract PathDependency base class for FileDepend…
radoering 6cfe239
chore: remove error handling for Python < 3.6
radoering 549f7e2
dependencies: allow path dependencies with non-existent paths
radoering 5a2dd36
performance: cache validation result to avoid unnecessary file system…
radoering 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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from abc import ABC | ||
| from abc import abstractmethod | ||
| from pathlib import Path | ||
| from typing import Iterable | ||
|
|
||
| from poetry.core.packages.dependency import Dependency | ||
| from poetry.core.packages.utils.utils import path_to_url | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class PathDependency(Dependency, ABC): | ||
| @abstractmethod | ||
| def __init__( | ||
| self, | ||
| name: str, | ||
| path: Path, | ||
| *, | ||
| source_type: str, | ||
| groups: Iterable[str] | None = None, | ||
| optional: bool = False, | ||
| base: Path | None = None, | ||
| extras: Iterable[str] | None = None, | ||
| ) -> None: | ||
| assert source_type in ("file", "directory") | ||
| self._path = path | ||
| self._base = base or Path.cwd() | ||
| self._full_path = path | ||
|
|
||
| if not self._path.is_absolute(): | ||
| self._full_path = self._base.joinpath(self._path).resolve() | ||
|
|
||
| super().__init__( | ||
| name, | ||
| "*", | ||
| groups=groups, | ||
| optional=optional, | ||
| allows_prereleases=True, | ||
| source_type=source_type, | ||
| source_url=self._full_path.as_posix(), | ||
| extras=extras, | ||
| ) | ||
| # cache validation result to avoid unnecessary file system access | ||
| self._validation_error = self._validate() | ||
| self.validate(raise_error=False) | ||
|
|
||
| @property | ||
| def path(self) -> Path: | ||
| return self._path | ||
|
|
||
| @property | ||
| def full_path(self) -> Path: | ||
| return self._full_path | ||
|
|
||
| @property | ||
| def base(self) -> Path: | ||
| return self._base | ||
|
|
||
| def is_file(self) -> bool: | ||
| return self._source_type == "file" | ||
|
|
||
| def is_directory(self) -> bool: | ||
| return self._source_type == "directory" | ||
|
|
||
| def validate(self, *, raise_error: bool) -> bool: | ||
| if not self._validation_error: | ||
| return True | ||
| if raise_error: | ||
| raise ValueError(self._validation_error) | ||
| logger.warning(self._validation_error) | ||
| return False | ||
|
|
||
| @property | ||
| def base_pep_508_name(self) -> str: | ||
| requirement = self.pretty_name | ||
|
|
||
| if self.extras: | ||
| extras = ",".join(sorted(self.extras)) | ||
| requirement += f"[{extras}]" | ||
|
|
||
| path = path_to_url(self.full_path) | ||
| requirement += f" @ {path}" | ||
|
|
||
| return requirement | ||
|
|
||
| def _validate(self) -> str: | ||
| if not self._full_path.exists(): | ||
| return f"Path {self._full_path} for {self.pretty_name} does not exist" | ||
| return "" | ||
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
Oops, something went wrong.
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.