-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into extra-markers
* origin/main: Upgrade minimal Cleo to 2.2.1 make `allow-prereleases` a tri-state setting to really forbid pre-releases if the setting is `false` and keep default behavior to allow pre-releases only if necessary feat: add confirmation step feat(cli): add info messages about applied migration docs: add information about --migrate feat(cli): add support for --local for --migrate feat(cli): add --migration option to config command feat(config): add ConfigSourceMigration feat(config): provide method to remove empty config category feat(config): add get_property() to ConfigSource Ignore http credentials with empty usernames Fix regression when using empty username/password fix index error for yanked releases without dependencies ignore installed packages during solving vcs: use peeled ref when retrieving tag revision (#9849) chore: update json fixtures and improve generate script so that it produces the same results on Linux and Windows installer: add option to install without re-resolving (just by evaluating locked markers) (#9427) - introduce "installer.re-resolve" config option (default: True) - if the config option is set to False and the lock file is at least version 2.1, the installer will not re-resolve but evaluate locked markers locker: lock transitive marker and groups for each package (#9427) fix: do not ignore local config for implicit PyPI source (#9816) Cleanup, linting, typing (#9839) # Conflicts: # src/poetry/installation/installer.py # src/poetry/puzzle/solver.py
- Loading branch information
Showing
167 changed files
with
3,709 additions
and
2,623 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 +1,99 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
import json | ||
|
||
from abc import ABC | ||
from abc import abstractmethod | ||
from typing import TYPE_CHECKING | ||
from typing import Any | ||
|
||
from cleo.io.null_io import NullIO | ||
|
||
|
||
if TYPE_CHECKING: | ||
from cleo.io.io import IO | ||
|
||
|
||
UNSET = object() | ||
|
||
|
||
class PropertyNotFoundError(ValueError): | ||
pass | ||
|
||
|
||
class ConfigSource(ABC): | ||
@abstractmethod | ||
def get_property(self, key: str) -> Any: ... | ||
|
||
@abstractmethod | ||
def add_property(self, key: str, value: Any) -> None: ... | ||
|
||
@abstractmethod | ||
def remove_property(self, key: str) -> None: ... | ||
|
||
|
||
@dataclasses.dataclass | ||
class ConfigSourceMigration: | ||
old_key: str | ||
new_key: str | None | ||
value_migration: dict[Any, Any] = dataclasses.field(default_factory=dict) | ||
|
||
def dry_run(self, config_source: ConfigSource, io: IO | None = None) -> bool: | ||
io = io or NullIO() | ||
|
||
try: | ||
old_value = config_source.get_property(self.old_key) | ||
except PropertyNotFoundError: | ||
return False | ||
|
||
new_value = ( | ||
self.value_migration[old_value] if self.value_migration else old_value | ||
) | ||
|
||
msg = f"<c1>{self.old_key}</c1> = <c2>{json.dumps(old_value)}</c2>" | ||
|
||
if self.new_key is not None and new_value is not UNSET: | ||
msg += f" -> <c1>{self.new_key}</c1> = <c2>{json.dumps(new_value)}</c2>" | ||
elif self.new_key is None: | ||
msg += " -> <c1>Removed from config</c1>" | ||
elif self.new_key and new_value is UNSET: | ||
msg += f" -> <c1>{self.new_key}</c1> = <c2>Not explicit set</c2>" | ||
|
||
io.write_line(msg) | ||
|
||
return True | ||
|
||
def apply(self, config_source: ConfigSource) -> None: | ||
try: | ||
old_value = config_source.get_property(self.old_key) | ||
except PropertyNotFoundError: | ||
return | ||
|
||
new_value = ( | ||
self.value_migration[old_value] if self.value_migration else old_value | ||
) | ||
|
||
config_source.remove_property(self.old_key) | ||
|
||
if self.new_key is not None and new_value is not UNSET: | ||
config_source.add_property(self.new_key, new_value) | ||
|
||
|
||
def drop_empty_config_category( | ||
keys: list[str], config: dict[Any, Any] | ||
) -> dict[Any, Any]: | ||
config_ = {} | ||
|
||
for key, value in config.items(): | ||
if not keys or key != keys[0]: | ||
config_[key] = value | ||
continue | ||
if keys and key == keys[0]: | ||
if isinstance(value, dict): | ||
value = drop_empty_config_category(keys[1:], value) | ||
|
||
if value != {}: | ||
config_[key] = value | ||
|
||
return config_ |
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
Oops, something went wrong.