Skip to content

Commit

Permalink
Stop auto-migrating projects (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Feb 16, 2022
1 parent d764c9d commit b37a3ec
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 93 deletions.
1 change: 1 addition & 0 deletions news/912.removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop auto-migrating projects from PDM 0.x format.
52 changes: 0 additions & 52 deletions pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,58 +748,6 @@ def print_pep582_command(ui: termui.UI, shell: str = "AUTO") -> None:
ui.echo(result)


def migrate_pyproject(project: Project) -> None:
"""Migrate the legacy pyproject format to PEP 621"""

if project.pyproject and "project" in project.pyproject:
pyproject = project.pyproject
settings = {}
updated_fields = []
for field in ("includes", "excludes", "build", "package-dir"):
if field in pyproject["project"]:
updated_fields.append(field)
settings[field] = pyproject["project"].pop(field)
if "dev-dependencies" in pyproject["project"]:
if pyproject["project"]["dev-dependencies"]:
settings["dev-dependencies"] = {
"dev": pyproject["project"]["dev-dependencies"]
}
del pyproject["project"]["dev-dependencies"]
updated_fields.append("dev-dependencies")
if updated_fields:
if "tool" not in pyproject or "pdm" not in pyproject["tool"]:
pyproject.setdefault("tool", {})["pdm"] = tomlkit.table()
pyproject["tool"]["pdm"].update(settings)
project.pyproject = pyproject
project.write_pyproject()
project.core.ui.echo(
f"{termui.yellow('[AUTO-MIGRATION]')} These fields are moved from "
f"[project] to [tool.pdm] table: {updated_fields}",
err=True,
)
return

if not project.pyproject_file.exists() or not FORMATS["legacy"].check_fingerprint(
project, project.pyproject_file
):
return

project.core.ui.echo(
f"{termui.yellow('[AUTO-MIGRATION]')} Legacy pdm 0.x metadata detected, "
"migrating to PEP 621...",
err=True,
)
do_import(project, str(project.pyproject_file), "legacy")
project.core.ui.echo(
termui.green("pyproject.toml")
+ termui.yellow(
" has been migrated to PEP 621 successfully. "
"Now you can safely delete the legacy metadata under [tool.pdm] table."
),
err=True,
)


def get_latest_version(project: Project) -> str | None:
"""Get the latest version of PDM from PyPI, cache for 7 days"""
from pdm.utils import get_finder
Expand Down
4 changes: 1 addition & 3 deletions pdm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from resolvelib import Resolver

from pdm import termui
from pdm.cli.actions import check_update, migrate_pyproject, print_pep582_command
from pdm.cli.actions import check_update, print_pep582_command
from pdm.cli.commands.base import BaseCommand
from pdm.cli.options import ignore_python_option, pep582_option, verbose_option
from pdm.cli.utils import PdmFormatter
Expand Down Expand Up @@ -104,8 +104,6 @@ def ensure_project(
)
options.project = project

migrate_pyproject(options.project)

def create_project(
self, root_path: str | Path | None = None, is_global: bool = False
) -> Project:
Expand Down
10 changes: 0 additions & 10 deletions tests/cli/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ def test_build_src_package_by_include(fixture_project):
assert "my_package/data.json" in zip_names


def test_build_legacy_package(fixture_project, invoke):
project = fixture_project("demo-legacy")
result = invoke(["build"], obj=project)
assert project.meta.name == "demo-module"
assert result.exit_code == 0
assert "demo-module-0.1.0/foo_module.py" in get_tarball_names(
project.root / "dist/demo-module-0.1.0.tar.gz"
)


def test_build_with_config_settings(fixture_project):
project = fixture_project("demo-src-package")
actions.do_build(project, config_settings={"--plat-name": "win_amd64"})
Expand Down
7 changes: 0 additions & 7 deletions tests/cli/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ def test_completion_command(invoke):
assert "(completion)" in result.output


def test_lock_legacy_project(invoke, fixture_project, repository):
project = fixture_project("demo-legacy")
result = invoke(["lock"], obj=project)
assert result.exit_code == 0
assert "urllib3" in project.locked_repository.all_candidates


def test_lock_refresh(invoke, project, repository):
project.add_dependencies({"requests": parse_requirement("requests")})
result = invoke(["lock"], obj=project)
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/projects/demo-legacy/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/projects/demo-legacy/README.md

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/projects/demo-legacy/bar_module.py

This file was deleted.

2 changes: 0 additions & 2 deletions tests/fixtures/projects/demo-legacy/foo_module.py

This file was deleted.

16 changes: 0 additions & 16 deletions tests/fixtures/projects/demo-legacy/pyproject.toml

This file was deleted.

0 comments on commit b37a3ec

Please sign in to comment.