Skip to content

Commit

Permalink
feat: remove legacy pdm-pep517 backend (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Aug 4, 2023
1 parent c815118 commit 446f2af
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 91 deletions.
14 changes: 0 additions & 14 deletions docs/docs/reference/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ If you run [`pdm init`](../reference/cli.md#init), PDM will let you choose the b

[:book: Read the docs](https://hatch.pypa.io/)

=== "pdm-pep517(deprecated)"

*This backend is deprecated, please migrate to `pdm-backend`.*

`pyproject.toml` configuration:

```toml
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
```

[:book: Read the docs](https://pypi.org/project/pdm-pep517/)


Apart from the above mentioned backends, you can also use any other backend that supports PEP 621, however, [poetry-core](https://python-poetry.org/) is not supported because it does not support reading PEP 621 metadata.

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/reference/pep621.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Depending on which build backend you are using, PDM will expand some variables i

### Environment variables

=== "pdm-pep517"
=== "pdm-backend"

```toml
[project]
Expand All @@ -160,11 +160,11 @@ Don't worry about credential leakage, the environment variables will be expanded

### Relative paths

When you add a package from a relative path, PDM will automatically save it as a relative path for `pdm-pep517` and `hatchling`.
When you add a package from a relative path, PDM will automatically save it as a relative path for `pdm-backend` and `hatchling`.

For example, if you run `pdm add ./my-package`, it will result in the following line in `pyproject.toml`.

=== "pdm-pep517"
=== "pdm-backend"

```toml
[project]
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/usage/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ The value of `requires-python` is a [version specifier as defined in PEP 440](ht

## Working with Python < 3.7

Although PDM run on Python 3.7 and above, you can still have lower Python versions for your **working project**. But remember, if your project is a library, which needs to be built, published or installed, you make sure the PEP 517 build backend being used supports the lowest Python version you need. For instance, the default backend `pdm-pep517` only works on Python 3.7+, so if you run [`pdm build`](../reference/cli.md#build) on a project with Python 3.6, you will get an error. Most modern build backends have dropped the support for Python 3.6 and lower, so it is highly recommended to upgrade the Python version to 3.7+. Here are the supported Python range for some commonly used build backends, we only list those that support PEP 621 since otherwise PDM can't work with them.
Although PDM run on Python 3.7 and above, you can still have lower Python versions for your **working project**. But remember, if your project is a library, which needs to be built, published or installed, you make sure the PEP 517 build backend being used supports the lowest Python version you need. For instance, the default backend `pdm-backend` only works on Python 3.7+, so if you run [`pdm build`](../reference/cli.md#build) on a project with Python 3.6, you will get an error. Most modern build backends have dropped the support for Python 3.6 and lower, so it is highly recommended to upgrade the Python version to 3.7+. Here are the supported Python range for some commonly used build backends, we only list those that support PEP 621 since otherwise PDM can't work with them.

| Backend | Supported Python | Support PEP 621 |
| --------------------- | ---------------- | --------------- |
| `pdm-pep517` | `>=3.7` | Yes |
| `pdm-backend` | `>=3.7` | Yes |
| `setuptools>=60` | `>=3.7` | Experimental |
| `hatchling` | `>=3.7` | Yes |
| `flit-core>=3.4` | `>=3.6` | Yes |
Expand Down
1 change: 1 addition & 0 deletions news/2167.removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the legacy build backend `pdm-pep517`.
2 changes: 1 addition & 1 deletion src/pdm/cli/completions/pdm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function TabExpansion($line, $lastWord) {
[Option]::new(@("-g", "--global", "--non-interactive", "-n", "--python", "--lib", "--copier", "--cookiecutter", "--overwrite")),
$projectOption,
$skipOption,
[Option]::new(@("--backend")).WithValues(@("pdm-backend", "setuptools", "flit", "hatching", "pdm-pep517"))
[Option]::new(@("--backend")).WithValues(@("pdm-backend", "setuptools", "flit", "hatching"))
))
break
}
Expand Down
2 changes: 1 addition & 1 deletion src/pdm/cli/completions/pdm.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ _pdm() {
{-n,--non-interactive}"[Don't ask questions but use default values]"
{-k,--skip}'[Skip some tasks and/or hooks by their comma-separated names]'
{-r,--overwrite}'[Overwrite existing files]'
'--backend[Specify the build backend]:backend:(pdm-backend setuptools hatchling flit pdm-pep517)'
'--backend[Specify the build backend]:backend:(pdm-backend setuptools hatchling flit)'
'--lib[Create a library project]'
'--python[Specify the Python version/path to use]:python:'
'--copier[Use Copier to generate project]'
Expand Down
10 changes: 0 additions & 10 deletions src/pdm/models/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ def build_system(cls) -> BuildSystem:
}


class PDMLegacyBackend(PDMBackend):
@classmethod
def build_system(cls) -> BuildSystem:
return {
"requires": ["pdm-pep517>=1.0"],
"build-backend": "pdm.pep517.api",
}


# Context formatting helpers for hatch
class PathContext:
def __init__(self, path: Path) -> None:
Expand Down Expand Up @@ -135,7 +126,6 @@ def build_system(cls) -> BuildSystem:
"setuptools": SetuptoolsBackend,
"flit-core": FlitBackend,
"hatchling": HatchBackend,
"pdm-pep517": PDMLegacyBackend,
}
# Fallback to the first backend
DEFAULT_BACKEND = next(iter(_BACKENDS.values()))
Expand Down
45 changes: 23 additions & 22 deletions tests/cli/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def test_build_single_module(fixture_project):
project = fixture_project("demo-module")

Command.do_build(project)
tar_names = get_tarball_names(project.root / "dist/demo-module-0.1.0.tar.gz")
tar_names = get_tarball_names(project.root / "dist/demo_module-0.1.0.tar.gz")
for name in [
"foo_module.py",
"bar_module.py",
"LICENSE",
"pyproject.toml",
"PKG-INFO",
]:
assert f"demo-module-0.1.0/{name}" in tar_names
assert f"demo_module-0.1.0/{name}" in tar_names

zip_names = get_wheel_names(project.root / "dist/demo_module-0.1.0-py3-none-any.whl")
for name in ["foo_module.py", "bar_module.py"]:
Expand All @@ -56,18 +56,18 @@ def test_build_single_module_with_readme(fixture_project):
project.pyproject.metadata["readme"] = "README.md"
project.pyproject.write()
Command.do_build(project)
assert "demo-module-0.1.0/README.md" in get_tarball_names(project.root / "dist/demo-module-0.1.0.tar.gz")
assert "demo_module-0.1.0/README.md" in get_tarball_names(project.root / "dist/demo_module-0.1.0.tar.gz")


def test_build_package(fixture_project):
project = fixture_project("demo-package")
Command.do_build(project)

tar_names = get_tarball_names(project.root / "dist/my-package-0.1.0.tar.gz")
assert "my-package-0.1.0/my_package/__init__.py" in tar_names
assert "my-package-0.1.0/my_package/data.json" in tar_names
assert "my-package-0.1.0/single_module.py" not in tar_names
assert "my-package-0.1.0/data_out.json" not in tar_names
tar_names = get_tarball_names(project.root / "dist/my_package-0.1.0.tar.gz")
assert "my_package-0.1.0/my_package/__init__.py" in tar_names
assert "my_package-0.1.0/my_package/data.json" in tar_names
assert "my_package-0.1.0/single_module.py" not in tar_names
assert "my_package-0.1.0/data_out.json" not in tar_names

zip_names = get_wheel_names(project.root / "dist/my_package-0.1.0-py3-none-any.whl")
assert "my_package/__init__.py" in zip_names
Expand All @@ -80,9 +80,9 @@ def test_build_src_package(fixture_project):
project = fixture_project("demo-src-package")
Command.do_build(project)

tar_names = get_tarball_names(project.root / "dist/demo-package-0.1.0.tar.gz")
assert "demo-package-0.1.0/src/my_package/__init__.py" in tar_names
assert "demo-package-0.1.0/src/my_package/data.json" in tar_names
tar_names = get_tarball_names(project.root / "dist/demo_package-0.1.0.tar.gz")
assert "demo_package-0.1.0/src/my_package/__init__.py" in tar_names
assert "demo_package-0.1.0/src/my_package/data.json" in tar_names

zip_names = get_wheel_names(project.root / "dist/demo_package-0.1.0-py3-none-any.whl")
assert "my_package/__init__.py" in zip_names
Expand All @@ -91,20 +91,21 @@ def test_build_src_package(fixture_project):

def test_build_package_include(fixture_project):
project = fixture_project("demo-package")
project.pyproject.settings["includes"] = [
build_config = project.pyproject.settings.setdefault("build", {})
build_config["includes"] = [
"my_package/",
"single_module.py",
"data_out.json",
]
project.pyproject.settings["excludes"] = ["my_package/*.json"]
build_config["excludes"] = ["my_package/*.json"]
project.pyproject.write()
Command.do_build(project)

tar_names = get_tarball_names(project.root / "dist/my-package-0.1.0.tar.gz")
assert "my-package-0.1.0/my_package/__init__.py" in tar_names
assert "my-package-0.1.0/my_package/data.json" not in tar_names
assert "my-package-0.1.0/single_module.py" in tar_names
assert "my-package-0.1.0/data_out.json" in tar_names
tar_names = get_tarball_names(project.root / "dist/my_package-0.1.0.tar.gz")
assert "my_package-0.1.0/my_package/__init__.py" in tar_names
assert "my_package-0.1.0/my_package/data.json" not in tar_names
assert "my_package-0.1.0/single_module.py" in tar_names
assert "my_package-0.1.0/data_out.json" in tar_names

zip_names = get_wheel_names(project.root / "dist/my_package-0.1.0-py3-none-any.whl")
assert "my_package/__init__.py" in zip_names
Expand All @@ -115,13 +116,13 @@ def test_build_package_include(fixture_project):

def test_build_src_package_by_include(fixture_project):
project = fixture_project("demo-src-package")
project.pyproject.settings["includes"] = ["src/my_package"]
project.pyproject.settings.setdefault("build", {})["includes"] = ["src/my_package"]
project.pyproject.write()
Command.do_build(project)

tar_names = get_tarball_names(project.root / "dist/demo-package-0.1.0.tar.gz")
assert "demo-package-0.1.0/src/my_package/__init__.py" in tar_names
assert "demo-package-0.1.0/src/my_package/data.json" in tar_names
tar_names = get_tarball_names(project.root / "dist/demo_package-0.1.0.tar.gz")
assert "demo_package-0.1.0/src/my_package/__init__.py" in tar_names
assert "demo_package-0.1.0/src/my_package/data.json" in tar_names

zip_names = get_wheel_names(project.root / "dist/demo_package-0.1.0-py3-none-any.whl")
assert "my_package/__init__.py" in zip_names
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_publish_and_build_in_one_run(fixture_project, pdm, mock_pypi):

mock_pypi.assert_called()
assert "Uploading demo_module-0.1.0-py3-none-any.whl" in result
assert "Uploading demo-module-0.1.0.tar.gz" in result
assert "Uploading demo_module-0.1.0.tar.gz" in result, result
assert "https://pypi.org/project/demo-module/0.1.0/" in result


Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def test_package_project_template(project_no_init):
assert project_no_init.pyproject._data["build-system"] == metadata["build-system"]
assert (project_no_init.root / "foo").is_dir()
assert (project_no_init.root / "foo/__init__.py").exists()
assert project_no_init.pyproject.settings["version"] == {"from": "foo/__init__.py"}
assert project_no_init.pyproject.settings["version"] == {"path": "foo/__init__.py", "source": "file"}
4 changes: 2 additions & 2 deletions tests/fixtures/projects/demo-combined-extras/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ te = ["chardet"]
all = ["idna", "chardet"]

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
9 changes: 5 additions & 4 deletions tests/fixtures/projects/demo-module/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
# PEP 621 project metadata
Expand All @@ -17,5 +17,6 @@ name = "demo-module"

[project.optional-dependencies]

[tool.pdm]
version = { from = "foo_module.py" }
[tool.pdm.version]
source = "file"
path = "foo_module.py"
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ requires-python = ">=3.6"
license = {text = "MIT"}

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool]
[tool.pdm]
9 changes: 5 additions & 4 deletions tests/fixtures/projects/demo-package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
# PEP 621 project metadata
Expand All @@ -18,8 +18,9 @@ readme = "README.md"

[project.optional-dependencies]

[tool.pdm]
version = { from = "my_package/__init__.py" }
[tool.pdm.version]
source = "file"
path = "my_package/__init__.py"

[[tool.pdm.source]]
url = "https://test.pypi.org/simple"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[build-system]
requires = ["pdm-pep517>=0.3.0"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
name = "package-b"
dependencies = ["django"]
dynamic = ["version"]

[tool.pdm]
version = {from="bar.py"}
[tool.pdm.version]
source = "file"
path = "bar.py"
9 changes: 5 additions & 4 deletions tests/fixtures/projects/demo-src-package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
# PEP 621 project metadata
Expand All @@ -17,5 +17,6 @@ name = "demo-package"

[project.optional-dependencies]

[tool.pdm]
version = { from = "src/my_package/__init__.py" }
[tool.pdm.version]
source = "file"
path = "src/my_package/__init__.py"
4 changes: 2 additions & 2 deletions tests/fixtures/projects/test-monorepo/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ requires-python = ">= 3.7"
dependencies = []

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ dependencies = [
]

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ dependencies = [
]

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
4 changes: 0 additions & 4 deletions tests/fixtures/projects/test-monorepo/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ dependencies = [
"package_a @ file:///${PROJECT_ROOT}/package_a",
"package_b @ file:///${PROJECT_ROOT}/package_b",
]

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
4 changes: 2 additions & 2 deletions tests/fixtures/projects/test-plugin-pdm/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project]
# PEP 621 project metadata
Expand Down
6 changes: 3 additions & 3 deletions tests/models/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_project_backend(project, working_set, backend, pdm):
dep = project.pyproject.metadata["dependencies"][0]
demo_path = project.root.joinpath("demo").as_posix()
demo_url = path_to_url(demo_path)
if backend in ("pdm-pep517", "pdm-backend"):
if backend == "pdm-backend":
assert dep == "demo @ file:///${PROJECT_ROOT}/demo"
elif backend == "hatchling":
assert dep == "demo @ {root:uri}/demo"
Expand All @@ -63,10 +63,10 @@ def test_hatch_expand_variables(monkeypatch):
assert backend.relative_path_to_url("../demo") == "{root:uri}/../demo"


def test_pdm_pep517_expand_variables(monkeypatch):
def test_pdm_backend_expand_variables(monkeypatch):
root = Path().absolute()
root_url = path_to_url(root.as_posix())
backend = get_backend("pdm-pep517")(root)
backend = get_backend("pdm-backend")(root)
monkeypatch.setenv("BAR", "bar")
assert backend.expand_line("demo @ file:///${PROJECT_ROOT}/demo") == f"demo @ {root_url}/demo"
assert backend.expand_line("demo==${BAR}") == "demo==bar"
Expand Down
3 changes: 2 additions & 1 deletion tests/models/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def test_vcs_candidate_in_subdirectory(project, is_editable):
candidate = Candidate(req)
expected_deps = ["django"]
assert candidate.prepare(project.environment).get_dependencies_from_metadata() == expected_deps
assert candidate.version == "0.1.0"
tail = "+editable" if is_editable else ""
assert candidate.version == f"0.1.0{tail}"


@pytest.mark.usefixtures("local_finder")
Expand Down

0 comments on commit 446f2af

Please sign in to comment.