Skip to content

Commit

Permalink
feat(cli): add support for --local for --migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Nov 7, 2024
1 parent 20c0be1 commit f8307cb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ def _migrate(self) -> None:
from poetry.toml.file import TOMLFile

config_file = TOMLFile(CONFIG_DIR / "config.toml")

if self.option("local"):
config_file = TOMLFile(self.poetry.file.path.parent / "poetry.toml")
if not config_file.exists():
raise RuntimeError("No local config file found")

config_source = FileConfigSource(config_file)

for migration in CONFIG_MIGRATIONS:
Expand Down
34 changes: 34 additions & 0 deletions tests/console/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pytest_mock import MockerFixture

from poetry.config.dict_config_source import DictConfigSource
from poetry.poetry import Poetry
from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
from tests.types import ProjectFactory
Expand Down Expand Up @@ -590,3 +591,36 @@ def test_config_migrate(

with config_file.open("r") as fh:
assert fh.read() == expected_config


def test_config_migrate_local_config(tester: CommandTester, poetry: Poetry) -> None:
local_config = poetry.file.path.parent / "poetry.toml"
config_data = textwrap.dedent("""\
[experimental]
system-git-client = true
[virtualenvs]
prefer-active-python = false
""")

with local_config.open("w") as fh:
fh.write(config_data)

tester.execute("--migrate --local")

expected_config = textwrap.dedent("""\
system-git-client = true
[virtualenvs]
use-poetry-python = true
""")

with local_config.open("r") as fh:
assert fh.read() == expected_config


def test_config_migrate_local_config_should_raise_if_not_found(
tester: CommandTester,
) -> None:
with pytest.raises(RuntimeError, match="No local config file found"):
tester.execute("--migrate --local")

0 comments on commit f8307cb

Please sign in to comment.