Skip to content

Commit

Permalink
fix: nested directory support for wheel (#762)
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
AsifArmanRahman and radoering committed Sep 29, 2024
1 parent 8c878fd commit d066ef6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def build(

target_dir = target_dir or self.default_target_dir
if not target_dir.exists():
target_dir.mkdir()
target_dir.mkdir(parents=True)

fd, temp_path = tempfile.mkstemp(suffix=".whl")

Expand Down
17 changes: 17 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,23 @@ def test_package(project_name: str) -> None:
assert "my_package-1.2.3/LICENSE" in tar.getnames()


@pytest.mark.parametrize("target_dir", [None, "dist", "dist/build"])
def test_package_target_dir(tmp_path: Path, target_dir: str | None) -> None:
poetry = Factory().create_poetry(project("complete"))

builder = SdistBuilder(poetry)
builder.build(target_dir=tmp_path / target_dir if target_dir else None)

sdist = (
tmp_path / target_dir if target_dir else fixtures_dir / "complete" / "dist"
) / "my_package-1.2.3.tar.gz"

assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "my_package-1.2.3/LICENSE" in tar.getnames()


@pytest.mark.parametrize("project_name", ["complete", "complete_new"])
def test_sdist_reproducibility(project_name: str) -> None:
poetry = Factory().create_poetry(project(project_name))
Expand Down
19 changes: 19 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ def test_wheel_package(project: str) -> None:
assert "my_package/sub_pkg1/__init__.py" in z.namelist()


@pytest.mark.parametrize("target_dir", [None, "dist", "dist/build"])
def test_wheel_package_target_dir(tmp_path: Path, target_dir: str | None) -> None:
module_path = fixtures_dir / "complete"

WheelBuilder.make_in(
Factory().create_poetry(module_path),
directory=tmp_path / target_dir if target_dir else None,
)

whl = (
tmp_path / target_dir if target_dir else module_path / "dist"
) / "my_package-1.2.3-py3-none-any.whl"

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
assert "my_package/sub_pkg1/__init__.py" in z.namelist()


def test_wheel_prerelease() -> None:
module_path = fixtures_dir / "prerelease"
WheelBuilder.make(Factory().create_poetry(module_path))
Expand Down

0 comments on commit d066ef6

Please sign in to comment.