Skip to content

Commit

Permalink
feat: don't add '+editable' to the editable version
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Feb 6, 2024
1 parent 940d129 commit e6fcd5f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 54 deletions.
29 changes: 10 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@ 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
hooks:
- 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
31 changes: 18 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
6 changes: 3 additions & 3 deletions src/pdm/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 []
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions src/pdm/backend/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 11 additions & 7 deletions src/pdm/backend/intree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])

Expand Down Expand Up @@ -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", [])

Expand All @@ -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
Expand Down

0 comments on commit e6fcd5f

Please sign in to comment.