Skip to content
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
24 changes: 11 additions & 13 deletions poetry/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from clikit.api.io.flags import VERY_VERBOSE

from poetry.utils._compat import Path
from poetry.utils._compat import basestring
from poetry.utils._compat import glob
from poetry.utils._compat import lru_cache
from poetry.utils._compat import to_str
Expand Down Expand Up @@ -84,15 +83,6 @@ def find_excluded_files(self): # type: () -> Set[str]

explicitely_excluded = set()
for excluded_glob in self._package.exclude:
excluded_path = Path(self._path, excluded_glob)

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 = Path(excluded_glob, "**/*")

for excluded in glob(
Path(self._path, excluded_glob).as_posix(), recursive=True
Expand All @@ -112,10 +102,18 @@ def find_excluded_files(self): # type: () -> Set[str]
return result

def is_excluded(self, filepath): # type: (Union[str, Path]) -> bool
if not isinstance(filepath, basestring):
filepath = filepath.as_posix()
exclude_path = Path(filepath)

while True:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not while len(exclude_path.parts) > 1?

I try to avoid while True statements to have a more explicit condition.

Copy link
Copy Markdown
Member Author

@finswimmer finswimmer Nov 22, 2019

Choose a reason for hiding this comment

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

Because - at least in theory - the root folder could be excluded as well. (Which doesn't make sense, if you want to build a package, but people have sometimes strange ideas).

Of course I could check this if I leave the loop. If you would like this more, I could implement it.

For things like this a native do-while implementation in python would be nice. But AFAIK there isn't such a thing 😞 .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You know what? We can leave it like this for now. I don't think this is too much of an issue.

if exclude_path.as_posix() in self.find_excluded_files():
return True

if len(exclude_path.parts) > 1:
exclude_path = exclude_path.parent
else:
break

return filepath in self.find_excluded_files()
return False

def find_files_to_add(self, exclude_build=True): # type: (bool) -> list
"""
Expand Down
8 changes: 4 additions & 4 deletions poetry/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def _build(self, wheel):
return

lib = lib[0]
excluded = self.find_excluded_files()

for pkg in lib.glob("**/*"):
if pkg.is_dir() or pkg in excluded:
if pkg.is_dir() or self.is_excluded(pkg):
continue

rel_path = str(pkg.relative_to(lib))
Expand All @@ -132,7 +132,7 @@ def _build(self, wheel):
self._add_file(wheel, pkg, rel_path)

def _copy_module(self, wheel):
excluded = self.find_excluded_files()

to_add = []

for include in self._module.includes:
Expand All @@ -153,7 +153,7 @@ def _copy_module(self, wheel):
else:
rel_file = file.relative_to(self._path)

if rel_file.as_posix() in excluded:
if self.is_excluded(rel_file.as_posix()):
continue

if file.suffix == ".pyc":
Expand Down
2 changes: 1 addition & 1 deletion poetry/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def get_ignored_files(self, folder=None): # type: (...) -> list
args += ["ls-files", "--others", "-i", "--exclude-standard"]
output = self.run(*args)

return output.split("\n")
return output.strip().split("\n")

def remote_urls(self, folder=None): # type: (...) -> dict
output = self.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"

readme = "README.rst"

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

homepage = "https://poetry.eustace.io/"
repository = "https://github.com/sdispater/poetry"
Expand Down