forked from python-poetry/poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sources: introduce "priority" key for sources and deprecate flags "de…
…fault" and "secondary", adjust cli accordingly (python-poetry#7658) Co-authored-by: Randy Döring <[email protected]>
- Loading branch information
1 parent
3a31f2d
commit 5806b42
Showing
38 changed files
with
1,014 additions
and
199 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,14 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
import warnings | ||
|
||
from poetry.repositories.repository_pool import Priority | ||
|
||
|
||
@dataclasses.dataclass(order=True, eq=True) | ||
class Source: | ||
name: str | ||
url: str | ||
default: bool = dataclasses.field(default=False) | ||
secondary: bool = dataclasses.field(default=False) | ||
default: dataclasses.InitVar[bool] = False | ||
secondary: dataclasses.InitVar[bool] = False | ||
priority: Priority = ( | ||
Priority.PRIMARY | ||
) # cheating in annotation: str will be converted to Priority in __post_init__ | ||
|
||
def __post_init__(self, default: bool, secondary: bool) -> None: | ||
if isinstance(self.priority, str): | ||
self.priority = Priority[self.priority.upper()] | ||
if default or secondary: | ||
warnings.warn( | ||
( | ||
"Parameters 'default' and 'secondary' to" | ||
" 'Source' are deprecated. Please provide" | ||
" 'priority' instead." | ||
), | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
if default: | ||
self.priority = Priority.DEFAULT | ||
elif secondary: | ||
self.priority = Priority.SECONDARY | ||
|
||
def to_dict(self) -> dict[str, str | bool]: | ||
return dataclasses.asdict(self) | ||
return dataclasses.asdict( | ||
self, | ||
dict_factory=lambda x: { | ||
k: v if not isinstance(v, Priority) else v.name.lower() for (k, v) in x | ||
}, | ||
) |
This file contains 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 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.