diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 3f19b697c..692c189f2 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -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") diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index fc4ba4a7a..6a9e60d19 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -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)) diff --git a/tests/masonry/builders/test_wheel.py b/tests/masonry/builders/test_wheel.py index f6bb27eca..6c840c73d 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -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))