diff --git a/src/poetry/masonry/builders/editable.py b/src/poetry/masonry/builders/editable.py index 795dafc5651..396e1359001 100644 --- a/src/poetry/masonry/builders/editable.py +++ b/src/poetry/masonry/builders/editable.py @@ -1,6 +1,7 @@ from __future__ import annotations import hashlib +import json import os import shutil @@ -241,6 +242,18 @@ def _add_dist_info(self, added_files: list[Path]) -> None: added_files.append(dist_info.joinpath("entry_points.txt")) + # write PEP 610 metadata + direct_url_json = dist_info.joinpath("direct_url.json") + direct_url_json.write_text( + json.dumps( + { + "dir_info": {"editable": True}, + "url": self._poetry.file.path.parent.as_uri(), + } + ) + ) + added_files.append(direct_url_json) + record = dist_info.joinpath("RECORD") with record.open("w", encoding="utf-8") as f: for path in added_files: diff --git a/tests/masonry/builders/test_editable_builder.py b/tests/masonry/builders/test_editable_builder.py index 64b52bddc9a..940c2f8c17e 100644 --- a/tests/masonry/builders/test_editable_builder.py +++ b/tests/masonry/builders/test_editable_builder.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json import os import shutil @@ -9,6 +10,7 @@ import pytest from cleo.io.null_io import NullIO +from deepdiff import DeepDiff from poetry.factory import Factory from poetry.masonry.builders.editable import EditableBuilder @@ -105,6 +107,15 @@ def test_builder_installs_proper_files_for_standard_packages( assert dist_info.joinpath("METADATA").exists() assert dist_info.joinpath("RECORD").exists() assert dist_info.joinpath("entry_points.txt").exists() + assert dist_info.joinpath("direct_url.json").exists() + + assert not DeepDiff( + { + "dir_info": {"editable": True}, + "url": simple_poetry.file.path.parent.as_uri(), + }, + json.loads(dist_info.joinpath("direct_url.json").read_text()), + ) assert dist_info.joinpath("INSTALLER").read_text() == "poetry" assert ( @@ -157,6 +168,7 @@ def test_builder_installs_proper_files_for_standard_packages( assert str(dist_info.joinpath("INSTALLER")) in records assert str(dist_info.joinpath("entry_points.txt")) in records assert str(dist_info.joinpath("RECORD")) in records + assert str(dist_info.joinpath("direct_url.json")) in records baz_script = f"""\ #!{tmp_venv.python}