Skip to content

Commit 7e6db62

Browse files
committed
feat(cli): add info messages about applied migration
1 parent 04b8b90 commit 7e6db62

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/poetry/config/config_source.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from __future__ import annotations
22

33
import dataclasses
4+
import json
45

56
from abc import ABC
67
from abc import abstractmethod
8+
from typing import TYPE_CHECKING
79
from typing import Any
810

11+
from cleo.io.null_io import NullIO
12+
13+
14+
if TYPE_CHECKING:
15+
from cleo.io.io import IO
16+
917

1018
UNSET = object()
1119

@@ -31,7 +39,9 @@ class ConfigSourceMigration:
3139
new_key: str | None
3240
value_migration: dict[Any, Any] = dataclasses.field(default_factory=dict)
3341

34-
def apply(self, config_source: ConfigSource) -> None:
42+
def apply(self, config_source: ConfigSource, io: IO | None = None) -> None:
43+
io = io or NullIO()
44+
3545
try:
3646
old_value = config_source.get_property(self.old_key)
3747
except PropertyNotFoundError:
@@ -43,8 +53,17 @@ def apply(self, config_source: ConfigSource) -> None:
4353

4454
config_source.remove_property(self.old_key)
4555

56+
msg = f"<c1>{self.old_key}</c1> = <c2>{json.dumps(old_value)}</c2>"
57+
4658
if self.new_key is not None and new_value is not UNSET:
59+
msg += f" -> <c1>{self.new_key}</c1> = <c2>{json.dumps(new_value)}</c2>"
4760
config_source.add_property(self.new_key, new_value)
61+
elif self.new_key is None:
62+
msg += " -> <c1>Removed from config</c1>"
63+
elif self.new_key and new_value is UNSET:
64+
msg += f" -> <c1>{self.new_key}</c1> = <c2>Not explicit set</c2>"
65+
66+
io.write_line(msg)
4867

4968

5069
def drop_empty_config_category(

src/poetry/console/commands/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,9 @@ def _migrate(self) -> None:
356356

357357
config_source = FileConfigSource(config_file)
358358

359+
self.io.write_line("Starting config migration ...")
360+
359361
for migration in CONFIG_MIGRATIONS:
360-
migration.apply(config_source)
362+
migration.apply(config_source, io=self.io)
363+
364+
self.io.write_line("Config migration successfully done.")

0 commit comments

Comments
 (0)