diff --git a/src/poetry/config/config_source.py b/src/poetry/config/config_source.py index 0172b0271d2..61f7b37b648 100644 --- a/src/poetry/config/config_source.py +++ b/src/poetry/config/config_source.py @@ -1,11 +1,19 @@ 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() @@ -31,7 +39,9 @@ class ConfigSourceMigration: new_key: str | None value_migration: dict[Any, Any] = dataclasses.field(default_factory=dict) - def apply(self, config_source: ConfigSource) -> None: + def apply(self, config_source: ConfigSource, io: IO | None = None) -> None: + io = io or NullIO() + try: old_value = config_source.get_property(self.old_key) except PropertyNotFoundError: @@ -43,8 +53,17 @@ def apply(self, config_source: ConfigSource) -> None: config_source.remove_property(self.old_key) + msg = f"{self.old_key} = {json.dumps(old_value)}" + if self.new_key is not None and new_value is not UNSET: + msg += f" -> {self.new_key} = {json.dumps(new_value)}" config_source.add_property(self.new_key, new_value) + elif self.new_key is None: + msg += " -> Removed from config" + elif self.new_key and new_value is UNSET: + msg += f" -> {self.new_key} = Not explicit set" + + io.write_line(msg) def drop_empty_config_category( diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index ed8cf60811e..cd9eefa2d1f 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -356,5 +356,9 @@ def _migrate(self) -> None: config_source = FileConfigSource(config_file) + self.io.write_line("Starting config migration ...") + for migration in CONFIG_MIGRATIONS: - migration.apply(config_source) + migration.apply(config_source, io=self.io) + + self.io.write_line("Config migration successfully done.")