Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

masonry: write PEP 610 metadata for editable builds #5703

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import hashlib
import json
import os
import shutil

Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import os
import shutil

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