Skip to content

Commit

Permalink
FIX: Regression of not excluding files from build (#1606)
Browse files Browse the repository at this point in the history
* FIX: To find excluded files, no additional glob is used to build a complete list of excluded files. Instead when checking if a file is excluded, it is looked up if one of the parent folder is in the excluded list.

* making isort happy

* revert accidentally made changes to pyproject.toml/poetry.lock

* fix: change condition for breaking loop, as previous version could lead to infinite loop
  • Loading branch information
finswimmer authored and sdispater committed Nov 22, 2019
1 parent b29999c commit 12f981c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
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:
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

0 comments on commit 12f981c

Please sign in to comment.