From 0b79e5e31c86188b1b0c23f07c1b7b2742d4e7da Mon Sep 17 00:00:00 2001 From: "finswimmer77@gmail.com" Date: Tue, 19 Nov 2019 06:08:32 +0100 Subject: [PATCH 1/4] 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. --- poetry/masonry/builders/builder.py | 27 +++++++------------ poetry/masonry/builders/wheel.py | 8 +++--- poetry/vcs/git.py | 2 +- .../exclude_nested_data_toml/pyproject.toml | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/poetry/masonry/builders/builder.py b/poetry/masonry/builders/builder.py index af1a05a29d4..ebfc9e7c0f2 100644 --- a/poetry/masonry/builders/builder.py +++ b/poetry/masonry/builders/builder.py @@ -2,26 +2,21 @@ import re import shutil import tempfile - from collections import defaultdict from contextlib import contextmanager -from typing import Set -from typing import Union +from typing import Set, Union 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 from poetry.vcs import get_vcs - from ..metadata import Metadata from ..utils.module import Module from ..utils.package_include import PackageInclude - AUTHOR_REGEX = re.compile(r"(?u)^(?P[- .,\w\d'’\"()]+) <(?P.+?)>$") METADATA_BASE = """\ @@ -84,15 +79,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 +98,15 @@ 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 exclude_path.as_posix() not in (".", "/"): + if exclude_path.as_posix() in self.find_excluded_files(): + return True + else: + exclude_path = exclude_path.parent - 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" From 8f2f0e6bbff581b502c29b51ca1f7bfbd7718988 Mon Sep 17 00:00:00 2001 From: "finswimmer77@gmail.com" Date: Tue, 19 Nov 2019 06:28:24 +0100 Subject: [PATCH 2/4] making isort happy --- poetry/masonry/builders/builder.py | 6 +++++- pyproject.toml | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/poetry/masonry/builders/builder.py b/poetry/masonry/builders/builder.py index ebfc9e7c0f2..303c548aaa1 100644 --- a/poetry/masonry/builders/builder.py +++ b/poetry/masonry/builders/builder.py @@ -2,9 +2,11 @@ import re import shutil import tempfile + from collections import defaultdict from contextlib import contextmanager -from typing import Set, Union +from typing import Set +from typing import Union from clikit.api.io.flags import VERY_VERBOSE @@ -13,10 +15,12 @@ from poetry.utils._compat import lru_cache from poetry.utils._compat import to_str from poetry.vcs import get_vcs + from ..metadata import Metadata from ..utils.module import Module from ..utils.package_include import PackageInclude + AUTHOR_REGEX = re.compile(r"(?u)^(?P[- .,\w\d'’\"()]+) <(?P.+?)>$") METADATA_BASE = """\ diff --git a/pyproject.toml b/pyproject.toml index 1a9970bb214..dfe6e14734c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ pre-commit = "^1.10" tox = "^3.0" pytest-sugar = "^0.9.2" httpretty = "^0.9.6" +isort = "^4.3.21" [tool.poetry.scripts] poetry = "poetry.console:main" From f7634af1695995f479f7690036ff2a53ece90130 Mon Sep 17 00:00:00 2001 From: Tobias Klare Date: Tue, 19 Nov 2019 14:10:30 +0100 Subject: [PATCH 3/4] revert accidentally made changes to pyproject.toml/poetry.lock --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index dfe6e14734c..1a9970bb214 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,6 @@ pre-commit = "^1.10" tox = "^3.0" pytest-sugar = "^0.9.2" httpretty = "^0.9.6" -isort = "^4.3.21" [tool.poetry.scripts] poetry = "poetry.console:main" From c73e19f8bc98e1bd43f13e458b34e94ff7b5e087 Mon Sep 17 00:00:00 2001 From: "finswimmer77@gmail.com" Date: Tue, 19 Nov 2019 19:16:57 +0100 Subject: [PATCH 4/4] fix: change condition for breaking loop, as previous version could lead to infinite loop --- poetry/masonry/builders/builder.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/poetry/masonry/builders/builder.py b/poetry/masonry/builders/builder.py index 303c548aaa1..97f9bb70fd7 100644 --- a/poetry/masonry/builders/builder.py +++ b/poetry/masonry/builders/builder.py @@ -104,11 +104,14 @@ def find_excluded_files(self): # type: () -> Set[str] def is_excluded(self, filepath): # type: (Union[str, Path]) -> bool exclude_path = Path(filepath) - while exclude_path.as_posix() not in (".", "/"): + while True: if exclude_path.as_posix() in self.find_excluded_files(): return True - else: + + if len(exclude_path.parts) > 1: exclude_path = exclude_path.parent + else: + break return False