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
Fix bug that prevents packages.find.exclude
to take effect when include_package_data=True
#3261
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34ae9d8
Test options.packages.find.exclude with include_package_data for buil…
abravalheri 3c1c734
Fix options.packages.find.exclude with include_package_data for build_py
abravalheri a41e0a0
Add news fragment
abravalheri f9cf824
Fix misspelling in setuptools/tests/test_build_py.py
abravalheri File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Projects that were abusing ``include_package_data=True`` to automatically add | ||
sub-packages and sub-modules will find the built wheel distribution no longer | ||
including some files. | ||
|
||
These projects are encouraged to properly configure ``packages`` to include all | ||
sub-packages. More information can be found in :doc:`userguide/package_discovery`. | ||
|
||
The previous behaviour was unintentional and caused a bug (#3260). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixed bug (#3260) that prevented configuration for ``packages.find.exclude`` to take effect | ||
when ``include_package_data = True``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import distutils.errors | ||
import itertools | ||
import stat | ||
from pathlib import Path | ||
from setuptools.extern.more_itertools import unique_everseen | ||
|
||
|
||
|
@@ -134,10 +135,20 @@ def analyze_manifest(self): | |
d, f = os.path.split(assert_relative(path)) | ||
prev = None | ||
oldf = f | ||
|
||
# Climb the hierarchy to find a parent package included in the distribution | ||
while d and d != prev and d not in src_dirs: | ||
if has_valid_modules(d): | ||
# The given directory contains Python modules, and therefore can be | ||
# considered a package (or namespace) itself, not a simple container | ||
# for data files. | ||
# If the intention is to include it in the distribution, then it | ||
# should be added to `packages`, and therefore appear in `src_dirs`. | ||
break | ||
prev = d | ||
d, df = os.path.split(d) | ||
f = os.path.join(df, f) | ||
|
||
if d in src_dirs: | ||
if path.endswith('.py') and f == oldf: | ||
continue # it's a module, not data | ||
|
@@ -240,3 +251,13 @@ def assert_relative(path): | |
% path | ||
) | ||
raise DistutilsSetupError(msg) | ||
|
||
|
||
def has_valid_modules(directory): | ||
return any( | ||
all( | ||
part.isidentifier() | ||
for part in potential_module.relative_to(directory).with_suffix("").parts | ||
) | ||
for potential_module in Path(directory).glob("**/*.py") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I thought about checking against (Maybe the |
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note
This
f == oldf
condition is a bit odd.According to the git history (f01c17e), the original intention of this code was to:
To me that sounds a little bit as a misuse. My opinion is that modules should not be affected by
include_package_data
...Unfortunately, I cannot find the original repository (I guess it was bitbucket) to check if it was associated with a PR or feature request to understand the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the issues and PRs were migrated from Bitbucket, but that commit comes from when Setuptools was hosted on Sourceforge and Subversion, where issues and merges weren't tracked as easily, so the commit history is the best we have.