From e6fcd5fcc2abae9ab25a9d69c71fd066de184110 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Tue, 6 Feb 2024 11:27:24 +0800 Subject: [PATCH] feat: don't add '+editable' to the editable version Signed-off-by: Frost Ming --- .pre-commit-config.yaml | 29 ++++++++++------------------- pyproject.toml | 31 ++++++++++++++++++------------- src/pdm/backend/__init__.py | 6 +++--- src/pdm/backend/editable.py | 8 -------- src/pdm/backend/intree.py | 18 +++++++++++------- tests/test_api.py | 8 ++++---- 6 files changed, 46 insertions(+), 54 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4cdba6..d4b18d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,22 +3,19 @@ ci: exclude: ^src/pdm/backend/_vendor repos: - - repo: https://github.com/psf/black - rev: 23.12.1 - hooks: - - id: black - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear + - id: pyupgrade + args: + - --py37-plus - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 'v0.2.0' hooks: - - id: isort - exclude: ^.*/?setup\.py$ + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --show-fixes] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 @@ -26,9 +23,3 @@ repos: - id: mypy exclude: ^(src/pdm/backend/_vendor|tests|scripts) - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: - - --py37-plus diff --git a/pyproject.toml b/pyproject.toml index ada5f49..5e274ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,19 +67,24 @@ requires = [] build-backend = "pdm.backend.intree" backend-path = ["src"] -[tool.black] -line-length = 88 -exclude = ''' -/( - \.eggs - | \.git - | \.mypy_cache - | build - | dist - | __pypackages__ - | pdm/backend/_vendor -)/ -''' +[tool.ruff] +src = ["src"] +target-version = "py38" +exclude = ["tests/fixtures"] + +[tool.ruff.lint] +extend-select = [ + "I", # isort + "C4", # flake8-comprehensions + "W", # pycodestyle + "YTT", # flake8-2020 +] + +[tool.ruff.lint.mccabe] +max-complexity = 10 + +[tool.ruff.lint.isort] +known-first-party = ["pdm.backend"] [tool.vendoring] destination = "src/pdm/backend/_vendor/" diff --git a/src/pdm/backend/__init__.py b/src/pdm/backend/__init__.py index 15f238b..4bbb296 100644 --- a/src/pdm/backend/__init__.py +++ b/src/pdm/backend/__init__.py @@ -8,7 +8,7 @@ def get_requires_for_build_wheel( - config_settings: Mapping[str, Any] | None = None + config_settings: Mapping[str, Any] | None = None, ) -> list[str]: """ Returns an additional list of requirements for building, as PEP508 strings, @@ -26,7 +26,7 @@ def get_requires_for_build_wheel( def get_requires_for_build_sdist( - config_settings: Mapping[str, Any] | None = None + config_settings: Mapping[str, Any] | None = None, ) -> list[str]: """There isn't any requirement for building a sdist at this point.""" return [] @@ -67,7 +67,7 @@ def build_sdist( def get_requires_for_build_editable( - config_settings: Mapping[str, Any] | None = None + config_settings: Mapping[str, Any] | None = None, ) -> list[str]: """ Returns an additional list of requirements for building, as PEP508 strings, diff --git a/src/pdm/backend/editable.py b/src/pdm/backend/editable.py index 2814c6f..9b44db3 100644 --- a/src/pdm/backend/editable.py +++ b/src/pdm/backend/editable.py @@ -18,19 +18,11 @@ def is_subpath(path: str, parent: str) -> bool: class EditableBuildHook: - @staticmethod - def editable_version(version: str) -> str: - if "+" in version: - return f"{version}.editable" - return f"{version}+editable" - def pdm_build_initialize(self, context: Context) -> None: editables = self._prepare_editable(context) context.config.metadata.setdefault("dependencies", []).extend( editables.dependencies() ) - version = context.config.metadata["version"] - context.config.metadata["version"] = self.editable_version(version) context.editables = editables def pdm_build_update_files(self, context: Context, files: dict[str, Path]) -> None: diff --git a/src/pdm/backend/intree.py b/src/pdm/backend/intree.py index 4a77e83..c730c17 100644 --- a/src/pdm/backend/intree.py +++ b/src/pdm/backend/intree.py @@ -3,7 +3,15 @@ import sys from typing import Any, Mapping -import pdm.backend as api +from pdm.backend import build_editable as build_editable +from pdm.backend import build_sdist as build_sdist +from pdm.backend import build_wheel as build_wheel +from pdm.backend import ( + prepare_metadata_for_build_editable as prepare_metadata_for_build_editable, +) +from pdm.backend import ( + prepare_metadata_for_build_wheel as prepare_metadata_for_build_wheel, +) if sys.version_info >= (3, 11): import tomllib @@ -12,7 +20,7 @@ def get_requires_for_build_wheel( - config_settings: Mapping[str, Any] | None = None + config_settings: Mapping[str, Any] | None = None, ) -> list[str]: with open("pyproject.toml", "rb") as fp: config = tomllib.load(fp) @@ -23,10 +31,6 @@ def get_requires_for_build_wheel( def get_requires_for_build_editable( - config_settings: Mapping[str, Any] | None = None + config_settings: Mapping[str, Any] | None = None, ) -> list[str]: return get_requires_for_build_wheel(config_settings) + ["editables"] - - -def __getattr__(name: str) -> Any: - return getattr(api, name) diff --git a/tests/test_api.py b/tests/test_api.py index 145a418..d76311c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -253,10 +253,10 @@ def test_build_editable(dist: Path, fixture_project: Path) -> None: namelist = zf.namelist() assert "demo_package.pth" in namelist assert "_editable_impl_demo_package.py" in namelist - assert "demo_package-0.1.0+editable.dist-info/licenses/LICENSE" in namelist + assert "demo_package-0.1.0.dist-info/licenses/LICENSE" in namelist metadata = email.message_from_bytes( - zf.read("demo_package-0.1.0+editable.dist-info/METADATA") + zf.read("demo_package-0.1.0.dist-info/METADATA") ) assert "editables" in metadata.get_all("Requires-Dist", []) @@ -313,7 +313,7 @@ def test_build_editable_pep420(dist: Path, fixture_project: Path) -> None: assert "__editables_demo_package.py" not in namelist metadata = email.message_from_bytes( - zf.read("demo_package-0.1.0+editable.dist-info/METADATA") + zf.read("demo_package-0.1.0.dist-info/METADATA") ) assert "editables" not in metadata.get_all("Requires-Dist", []) @@ -324,7 +324,7 @@ def test_build_editable_pep420(dist: Path, fixture_project: Path) -> None: @pytest.mark.parametrize("name", ["demo-package"]) def test_prepare_metadata_for_editable(dist: Path) -> None: dist_info = api.prepare_metadata_for_build_editable(dist.as_posix()) - assert dist_info == "demo_package-0.1.0+editable.dist-info" + assert dist_info == "demo_package-0.1.0.dist-info" with (dist / dist_info / "METADATA").open("rb") as metadata: deps = email.message_from_binary_file(metadata).get_all("Requires-Dist") assert "editables" in deps