Skip to content

Commit

Permalink
feat(cli): add info messages about applied migration
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Nov 7, 2024
1 parent 04b8b90 commit 7e6db62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/poetry/config/config_source.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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:
Expand All @@ -43,8 +53,17 @@ def apply(self, config_source: ConfigSource) -> None:

config_source.remove_property(self.old_key)

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>"
config_source.add_property(self.new_key, new_value)
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)


def drop_empty_config_category(
Expand Down
6 changes: 5 additions & 1 deletion src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

0 comments on commit 7e6db62

Please sign in to comment.