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

Conceptual fix for issue #3589 #126

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 6 additions & 5 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ def find_files_to_add(
if "__pycache__" in str(file):
continue

# this should be moved to Include.check_elements(), similar
# to PackageInclude.check_elements()
if file.is_dir():
if self.format in formats:
if self.format in formats: # why check this only for dirs?
for current_file in file.glob("**/*"):
include_file = BuildIncludeFile(
path=current_file,
Expand All @@ -163,8 +165,9 @@ def find_files_to_add(
)

if not current_file.is_dir() and not self.is_excluded(
include_file.relative_to_source_root()
current_file.relative_to(self._path)
):
logger.debug("Adding: {}".format(str(current_file)))
to_add.add(include_file)
continue

Expand All @@ -181,9 +184,7 @@ def find_files_to_add(
path=file, project_root=self._path, source_root=source_root
)

if self.is_excluded(
include_file.relative_to_project_root()
) and isinstance(include, PackageInclude):
if self.is_excluded(file.relative_to(source_root)):
Copy link
Author

@brechtm brechtm Jan 21, 2021

Choose a reason for hiding this comment

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

This changes include/exclude behavior, breaking three tests. Currently, include always trumps exclude (see also python-poetry/poetry#1336 and python-poetry/poetry#1750), which is too limiting for some use cases.

One solution, without introducing order-dependent include/exclude rules as in a a MANIFEST.in, is to give globbed paths a lower priority than fully-qualified paths. I feel this offers more flexibility while being intuitive at the same time. This would work for the examples given in python-poetry/poetry#1336, such as:

exclude = [
    "assets/sample/**/*"
]
include = [
    "assets/sample/subdir/one.yaml",
    "assets/sample/subdir/two.yaml"
]

But the following would now also work:

include = [
    "**/*"
]
exclude = [
    ".travis.yml"
]

It might be worth looking into assigning different priorities to glob patterns based on how specific they are.

continue

if file.suffix == ".pyc":
Expand Down
3 changes: 2 additions & 1 deletion poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def get_ignored_files(self, folder=None): # type: (...) -> list

args += ["ls-files", "--others", "-i", "--exclude-standard"]
output = self.run(*args)
dotgit = list(str(path.relative_to(folder)) for path in folder.rglob(".git/*"))

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

def remote_urls(self, folder=None): # type: (...) -> dict
output = self.run(
Expand Down