Skip to content

Commit

Permalink
This PR impliments the feature request python-poetry#784.
Browse files Browse the repository at this point in the history
When a folder is explicit defined in `pyproject.toml` as excluded, all nested data, including subfolder, are excluded. It is no longer neccessary to use the glob `folder/**/*`
  • Loading branch information
Tobias Klare committed Oct 14, 2019
1 parent 3622f8e commit 9982b09
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions poetry/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def find_excluded_files(self): # type: () -> Set[str]

explicitely_excluded = set()
for excluded_glob in self._package.exclude:
if Path(self._path.as_posix(), str(excluded_glob)).is_dir():
excluded_glob = Path(str(excluded_glob), "**/*").as_posix()
for excluded in glob(
os.path.join(self._path.as_posix(), str(excluded_glob)), recursive=True
):
Expand Down
26 changes: 26 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,32 @@ def test_default_with_excluded_data(mocker):
assert "my-package-1.2.3/PKG-INFO" in names


def test_src_excluded_nested_data():
module_path = fixtures_dir / "default_with_excluded_data_toml"
poetry = Factory().create_poetry(module_path)
poetry._package.exclude = ["my_package/data"]

builder = SdistBuilder(poetry, NullEnv(), NullIO())
builder.build()

sdist = module_path / "dist" / "my-package-1.2.3.tar.gz"

assert sdist.exists()

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/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/data/data1.txt" not 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


def test_proper_python_requires_if_two_digits_precision_version_specified():
poetry = Factory().create_poetry(project("simple_version"))

Expand Down
17 changes: 17 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ def test_wheel_excluded_data():
assert "my_package/data/data1.txt" not in z.namelist()


def test_wheel_excluded_nested_data():
module_path = fixtures_dir / "default_with_excluded_data_toml"
poetry = Factory().create_poetry(module_path)
poetry._package.exclude = ["my_package/data"]
WheelBuilder.make(poetry, NullEnv(), NullIO())

whl = 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/__init__.py" in z.namelist()
assert "my_package/data/sub_data/data2.txt" not in z.namelist()
assert "my_package/data/sub_data/data3.txt" not in z.namelist()
assert "my_package/data/data1.txt" not in z.namelist()


def test_wheel_localversionlabel():
module_path = fixtures_dir / "localversionlabel"
WheelBuilder.make(Factory().create_poetry(module_path), NullEnv(), NullIO())
Expand Down

0 comments on commit 9982b09

Please sign in to comment.