diff --git a/poetry/masonry/builders/builder.py b/poetry/masonry/builders/builder.py index af1a05a29d4..97f9bb70fd7 100644 --- a/poetry/masonry/builders/builder.py +++ b/poetry/masonry/builders/builder.py @@ -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 @@ -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 @@ -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 """ diff --git a/poetry/masonry/builders/wheel.py b/poetry/masonry/builders/wheel.py index 058679edb4e..24efb2f7d7d 100644 --- a/poetry/masonry/builders/wheel.py +++ b/poetry/masonry/builders/wheel.py @@ -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)) @@ -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: @@ -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": diff --git a/poetry/vcs/git.py b/poetry/vcs/git.py index e3138b77fb3..06ff9d03b23 100644 --- a/poetry/vcs/git.py +++ b/poetry/vcs/git.py @@ -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( diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml b/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml index 21efcba30eb..421d32f43dc 100644 --- a/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml +++ b/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml @@ -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"