Skip to content

Commit

Permalink
respect metadata_directory at editable builds (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
  • Loading branch information
dimbleby and radoering committed Dec 20, 2022
1 parent 43fd7fe commit 2bc219b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/poetry/core/masonry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def build_editable(
metadata_directory: str | None = None,
) -> str:
poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
metadata_path = None if metadata_directory is None else Path(metadata_directory)

return WheelBuilder.make_in(poetry, Path(wheel_directory), editable=True)
return WheelBuilder.make_in(
poetry, Path(wheel_directory), metadata_directory=metadata_path, editable=True
)


get_requires_for_build_editable = get_requires_for_build_wheel
Expand Down
45 changes: 41 additions & 4 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,56 @@ def test_build_editable_wheel() -> None:


def test_build_wheel_with_metadata_directory() -> None:
with temporary_directory() as metadata_tmp_dir, cwd(
os.path.join(fixtures, "complete")
):
pkg_dir = Path(fixtures) / "complete"

with temporary_directory() as metadata_tmp_dir, cwd(pkg_dir):
metadata_directory = api.prepare_metadata_for_build_wheel(metadata_tmp_dir)

with temporary_directory() as wheel_tmp_dir:
dist_info_path = Path(metadata_tmp_dir) / metadata_directory
open(dist_info_path / "CUSTOM", "w").close() # noqa: SIM115
filename = api.build_wheel(
wheel_tmp_dir, metadata_directory=str(dist_info_path)
)
wheel_pth = Path(wheel_tmp_dir) / filename

validate_wheel_contents(
name="my_package",
version="1.2.3",
path=str(os.path.join(wheel_tmp_dir, filename)),
path=str(wheel_pth),
files=["entry_points.txt"],
)

with zipfile.ZipFile(wheel_pth) as z:
namelist = z.namelist()

assert f"{metadata_directory}/CUSTOM" in namelist


def test_build_editable_wheel_with_metadata_directory() -> None:
pkg_dir = Path(fixtures) / "complete"

with temporary_directory() as metadata_tmp_dir, cwd(pkg_dir):
metadata_directory = api.prepare_metadata_for_build_editable(metadata_tmp_dir)

with temporary_directory() as wheel_tmp_dir:
dist_info_path = Path(metadata_tmp_dir) / metadata_directory
open(dist_info_path / "CUSTOM", "w").close() # noqa: SIM115
filename = api.build_editable(
wheel_tmp_dir, metadata_directory=str(dist_info_path)
)
wheel_pth = Path(wheel_tmp_dir) / filename

validate_wheel_contents(
name="my_package",
version="1.2.3",
path=str(wheel_pth),
files=["entry_points.txt"],
)

with zipfile.ZipFile(wheel_pth) as z:
namelist = z.namelist()

assert "my_package.pth" in namelist
assert pkg_dir.as_posix() == z.read("my_package.pth").decode().strip()
assert f"{metadata_directory}/CUSTOM" in namelist

0 comments on commit 2bc219b

Please sign in to comment.