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

Fix sdist build #495

Merged
merged 1 commit into from
Oct 7, 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
2 changes: 1 addition & 1 deletion src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def build(
)

try:
tar_dir = f"{self._package.pretty_name}-{self._meta.version}"
tar_dir = f"{name}-{self._meta.version}"

files_to_add = self.find_files_to_add(exclude_build=False)

Expand Down
56 changes: 28 additions & 28 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def test_module_src() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "module-src-0.1/src/module_src.py" in tar.getnames()
assert "module_src-0.1/src/module_src.py" in tar.getnames()

whl = module_path / "dist" / "module_src-0.1-py2.py3-none-any.whl"

Expand All @@ -456,7 +456,7 @@ def test_package_src() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "package-src-0.1/src/package_src/module.py" in tar.getnames()
assert "package_src-0.1/src/package_src/module.py" in tar.getnames()

whl = module_path / "dist" / "package_src-0.1-py2.py3-none-any.whl"

Expand All @@ -481,8 +481,8 @@ def test_split_source() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "split-source-0.1/lib_a/module_a/__init__.py" in tar.getnames()
assert "split-source-0.1/lib_b/module_b/__init__.py" in tar.getnames()
assert "split_source-0.1/lib_a/module_a/__init__.py" in tar.getnames()
assert "split_source-0.1/lib_b/module_b/__init__.py" in tar.getnames()

whl = module_path / "dist" / "split_source-0.1-py3-none-any.whl"

Expand Down Expand Up @@ -529,23 +529,23 @@ def test_package_with_include(mocker: MockerFixture) -> None:
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert len(names) == len(set(names))
assert "with-include-1.2.3/LICENSE" in names
assert "with-include-1.2.3/README.rst" in names
assert "with-include-1.2.3/extra_dir/__init__.py" in names
assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/__init__.py" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt" not in names
assert "with-include-1.2.3/my_module.py" in names
assert "with-include-1.2.3/notes.txt" in names
assert "with-include-1.2.3/package_with_include/__init__.py" in names
assert "with-include-1.2.3/tests/__init__.py" in names
assert "with-include-1.2.3/pyproject.toml" in names
assert "with-include-1.2.3/setup.py" in names
assert "with-include-1.2.3/PKG-INFO" in names
assert "with-include-1.2.3/for_wheel_only/__init__.py" not in names
assert "with-include-1.2.3/src/src_package/__init__.py" in names

file = tar.extractfile("with-include-1.2.3/setup.py")
assert "with_include-1.2.3/LICENSE" in names
assert "with_include-1.2.3/README.rst" in names
assert "with_include-1.2.3/extra_dir/__init__.py" in names
assert "with_include-1.2.3/extra_dir/vcs_excluded.txt" in names
assert "with_include-1.2.3/extra_dir/sub_pkg/__init__.py" in names
assert "with_include-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt" not in names
assert "with_include-1.2.3/my_module.py" in names
assert "with_include-1.2.3/notes.txt" in names
assert "with_include-1.2.3/package_with_include/__init__.py" in names
assert "with_include-1.2.3/tests/__init__.py" in names
assert "with_include-1.2.3/pyproject.toml" in names
assert "with_include-1.2.3/setup.py" in names
assert "with_include-1.2.3/PKG-INFO" in names
assert "with_include-1.2.3/for_wheel_only/__init__.py" not in names
assert "with_include-1.2.3/src/src_package/__init__.py" in names

file = tar.extractfile("with_include-1.2.3/setup.py")
assert file
setup = file.read()
setup_ast = ast.parse(setup)
Expand Down Expand Up @@ -596,24 +596,24 @@ def test_respect_format_for_explicit_included_files() -> None:
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert (
"exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/__init__.py"
"exclude_whl_include_sdist-0.1.0/exclude_whl_include_sdist/__init__.py"
in names
)
assert (
"exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/compiled/source.c"
"exclude_whl_include_sdist-0.1.0/exclude_whl_include_sdist/compiled/source.c"
in names
)
assert (
"exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/compiled/source.h"
"exclude_whl_include_sdist-0.1.0/exclude_whl_include_sdist/compiled/source.h"
in names
)
assert (
"exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/cython_code.pyx"
"exclude_whl_include_sdist-0.1.0/exclude_whl_include_sdist/cython_code.pyx"
in names
)
assert "exclude-whl-include-sdist-0.1.0/pyproject.toml" in names
assert "exclude-whl-include-sdist-0.1.0/setup.py" in names
assert "exclude-whl-include-sdist-0.1.0/PKG-INFO" in names
assert "exclude_whl_include_sdist-0.1.0/pyproject.toml" in names
assert "exclude_whl_include_sdist-0.1.0/setup.py" in names
assert "exclude_whl_include_sdist-0.1.0/PKG-INFO" in names

whl = module_path / "dist" / "exclude_whl_include_sdist-0.1.0-py3-none-any.whl"

Expand Down
80 changes: 40 additions & 40 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_package() -> None:
assert sdist.exists()

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


def test_sdist_reproducibility() -> None:
Expand Down Expand Up @@ -393,7 +393,7 @@ def test_with_src_module_file() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "module-src-0.1/src/module_src.py" in tar.getnames()
assert "module_src-0.1/src/module_src.py" in tar.getnames()


def test_with_src_module_dir() -> None:
Expand All @@ -418,8 +418,8 @@ def test_with_src_module_dir() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "package-src-0.1/src/package_src/__init__.py" in tar.getnames()
assert "package-src-0.1/src/package_src/module.py" in tar.getnames()
assert "package_src-0.1/src/package_src/__init__.py" in tar.getnames()
assert "package_src-0.1/src/package_src/module.py" in tar.getnames()


def test_default_with_excluded_data(mocker: MockerFixture) -> None:
Expand Down Expand Up @@ -473,18 +473,18 @@ def get_ignored_files(self, folder: Path | None = None) -> list[str]:
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert len(names) == len(set(names))
assert "my-package-1.2.3/LICENSE" in names
assert "my-package-1.2.3/README.rst" in names
assert "my-package-1.2.3/my_package/__init__.py" in names
assert "my-package-1.2.3/my_package/data/data1.txt" in names
assert "my-package-1.2.3/pyproject.toml" in names
assert "my-package-1.2.3/setup.py" in names
assert "my-package-1.2.3/PKG-INFO" in names
assert "my_package-1.2.3/LICENSE" in names
assert "my_package-1.2.3/README.rst" in names
assert "my_package-1.2.3/my_package/__init__.py" in names
assert "my_package-1.2.3/my_package/data/data1.txt" in names
assert "my_package-1.2.3/pyproject.toml" in names
assert "my_package-1.2.3/setup.py" in names
assert "my_package-1.2.3/PKG-INFO" in names
# all last modified times should be set to a valid timestamp
for tarinfo in tar.getmembers():
if tarinfo.name in [
"my-package-1.2.3/setup.py",
"my-package-1.2.3/PKG-INFO",
"my_package-1.2.3/setup.py",
"my_package-1.2.3/PKG-INFO",
]:
# generated files have timestamp set to 0
assert tarinfo.mtime == 0
Expand All @@ -506,23 +506,23 @@ def test_src_excluded_nested_data() -> None:
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert len(names) == len(set(names))
assert "my-package-1.2.3/LICENSE" in names
assert "my-package-1.2.3/README.rst" in names
assert "my-package-1.2.3/pyproject.toml" in names
assert "my-package-1.2.3/setup.py" in names
assert "my-package-1.2.3/PKG-INFO" in names
assert "my-package-1.2.3/my_package/__init__.py" in names
assert "my-package-1.2.3/my_package/data/sub_data/data2.txt" not in names
assert "my-package-1.2.3/my_package/data/sub_data/data3.txt" not in names
assert "my-package-1.2.3/my_package/data/data1.txt" not in names
assert "my-package-1.2.3/my_package/data/data2.txt" in names
assert "my-package-1.2.3/my_package/puplic/publicdata.txt" in names
assert "my-package-1.2.3/my_package/public/item1/itemdata1.txt" not in names
assert "my_package-1.2.3/LICENSE" in names
assert "my_package-1.2.3/README.rst" in names
assert "my_package-1.2.3/pyproject.toml" in names
assert "my_package-1.2.3/setup.py" in names
assert "my_package-1.2.3/PKG-INFO" in names
assert "my_package-1.2.3/my_package/__init__.py" in names
assert "my_package-1.2.3/my_package/data/sub_data/data2.txt" not in names
assert "my_package-1.2.3/my_package/data/sub_data/data3.txt" not in names
assert "my_package-1.2.3/my_package/data/data1.txt" not in names
assert "my_package-1.2.3/my_package/data/data2.txt" in names
assert "my_package-1.2.3/my_package/puplic/publicdata.txt" in names
assert "my_package-1.2.3/my_package/public/item1/itemdata1.txt" not in names
assert (
"my-package-1.2.3/my_package/public/item1/subitem/subitemdata.txt"
"my_package-1.2.3/my_package/public/item1/subitem/subitemdata.txt"
not in names
)
assert "my-package-1.2.3/my_package/public/item2/itemdata2.txt" not in names
assert "my_package-1.2.3/my_package/public/item2/itemdata2.txt" not in names


def test_proper_python_requires_if_two_digits_precision_version_specified() -> None:
Expand Down Expand Up @@ -559,8 +559,8 @@ def test_includes() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in tar.getnames()
assert "with-include-1.2.3/notes.txt" in tar.getnames()
assert "with_include-1.2.3/extra_dir/vcs_excluded.txt" in tar.getnames()
assert "with_include-1.2.3/notes.txt" in tar.getnames()


def test_includes_with_inline_table() -> None:
Expand All @@ -580,10 +580,10 @@ def test_includes_with_inline_table() -> None:
assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "with-include-1.2.3/both.txt" in tar.getnames()
assert "with-include-1.2.3/wheel_only.txt" not in tar.getnames()
assert "with-include-1.2.3/tests/__init__.py" in tar.getnames()
assert "with-include-1.2.3/tests/test_foo/test.py" in tar.getnames()
assert "with_include-1.2.3/both.txt" in tar.getnames()
assert "with_include-1.2.3/wheel_only.txt" not in tar.getnames()
assert "with_include-1.2.3/tests/__init__.py" in tar.getnames()
assert "with_include-1.2.3/tests/test_foo/test.py" in tar.getnames()


def test_excluded_subpackage() -> None:
Expand Down Expand Up @@ -614,9 +614,9 @@ def test_sdist_package_pep_561_stub_only() -> None:

with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert "pep-561-stubs-0.1/pkg-stubs/__init__.pyi" in names
assert "pep-561-stubs-0.1/pkg-stubs/module.pyi" in names
assert "pep-561-stubs-0.1/pkg-stubs/subpkg/__init__.pyi" in names
assert "pep_561_stubs-0.1/pkg-stubs/__init__.pyi" in names
assert "pep_561_stubs-0.1/pkg-stubs/module.pyi" in names
assert "pep_561_stubs-0.1/pkg-stubs/subpkg/__init__.pyi" in names


def test_sdist_disable_setup_py() -> None:
Expand All @@ -632,10 +632,10 @@ def test_sdist_disable_setup_py() -> None:

with tarfile.open(str(sdist), "r") as tar:
assert set(tar.getnames()) == {
"my-package-1.2.3/README.rst",
"my-package-1.2.3/pyproject.toml",
"my-package-1.2.3/PKG-INFO",
"my-package-1.2.3/my_package/__init__.py",
"my_package-1.2.3/README.rst",
"my_package-1.2.3/pyproject.toml",
"my_package-1.2.3/PKG-INFO",
"my_package-1.2.3/my_package/__init__.py",
}


Expand Down
3 changes: 2 additions & 1 deletion tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def validate_wheel_contents(
def validate_sdist_contents(
name: str, version: str, path: str, files: list[str]
) -> None:
escaped_name = name.replace("-", "_")
with tarfile.open(path) as tar:
namelist = tar.getnames()
for filename in files:
assert f"{name}-{version}/{filename}" in namelist
assert f"{escaped_name}-{version}/{filename}" in namelist