Skip to content

Commit

Permalink
masonry: write PEP 610 metadata for editable builds
Browse files Browse the repository at this point in the history
  • Loading branch information
abn authored and neersighted committed May 27, 2022
1 parent e4e5497 commit 2d8ea84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 2d8ea84

Please sign in to comment.