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

Exclude nested items (#784) #1464

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
13 changes: 7 additions & 6 deletions poetry/masonry/builders/builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import itertools
import os
import re
import shutil
Expand Down Expand Up @@ -86,12 +87,12 @@ def find_excluded_files(self): # type: () -> Set[str]

explicitely_excluded = set()
for excluded_glob in self._package.exclude:
for excluded in glob(
os.path.join(self._path.as_posix(), str(excluded_glob)), recursive=True
):
explicitely_excluded.add(
Path(excluded).relative_to(self._path).as_posix()
)
excluded_path = Path(self._path, excluded_glob)
if excluded_path.is_dir():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if excluded_path.is_dir():
try:
is_dir = excluded_path.is_dir()
except OSError:
# On Windows, testing if a path with a glob is a directory will raise an OSError
is_dir = False
if is_dir:

excluded_glob = str(Path(excluded_glob, "**/*"))

for excluded in self._path.glob(excluded_glob):
explicitely_excluded.add(excluded.relative_to(self._path).as_posix())

ignored = vcs_ignored_files | explicitely_excluded
result = set()
Expand Down
20 changes: 20 additions & 0 deletions tests/masonry/builders/fixtures/exclude_nested_data_toml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2018 Sébastien Eustace

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"

readme = "README.rst"

exclude = ["my_package/data/", "**/*/item*"]

homepage = "https://poetry.eustace.io/"
repository = "https://github.com/sdispater/poetry"
documentation = "https://poetry.eustace.io/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
[tool.poetry.dependencies]
python = "^3.6"
cleo = "^0.6"
cachy = { version = "^0.2.0", extras = ["msgpack"] }

pendulum = { version = "^1.4", optional = true }

[tool.poetry.dev-dependencies]
pytest = "~3.4"

[tool.poetry.extras]
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
32 changes: 32 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,38 @@ 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 / "exclude_nested_data_toml"
poetry = Factory().create_poetry(module_path)

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/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/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"
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():
poetry = Factory().create_poetry(project("simple_version"))

Expand Down
20 changes: 20 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ 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 / "exclude_nested_data_toml"
poetry = Factory().create_poetry(module_path)
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()
assert "my_package/puplic/publicdata.txt" in z.namelist()
assert "my_package/public/item1/itemdata1.txt" not in z.namelist()
assert "my_package/public/item1/subitem/subitemdata.txt" not in z.namelist()
assert "my_package/public/item2/itemdata2.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