Skip to content

Allow recursive globs for package_data #3309

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

Merged
Merged
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
1 change: 1 addition & 0 deletions changelog.d/1806.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allowed recursive globs (`**`) in `package_data`. -- by :user:`nullableVoidPtr`
3 changes: 2 additions & 1 deletion setuptools/command/build_py.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import partial
from glob import glob
from distutils.util import convert_path
import distutils.command.build_py as orig
Expand Down Expand Up @@ -98,7 +99,7 @@ def find_data_files(self, package, src_dir):
package,
src_dir,
)
globs_expanded = map(glob, patterns)
globs_expanded = map(partial(glob, recursive=True), patterns)
# flatten the expanded globs into an iterable of matches
globs_matches = itertools.chain.from_iterable(globs_expanded)
glob_files = filter(os.path.isfile, globs_matches)
Expand Down
23 changes: 23 additions & 0 deletions setuptools/tests/test_build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ def test_directories_in_package_data_glob(tmpdir_cwd):
dist.run_commands()


def test_recursive_in_package_data_glob(tmpdir_cwd):
"""
Files matching recursive globs (**) in package_data should
be included in the package data.

#1806
"""
dist = Distribution(dict(
script_name='setup.py',
script_args=['build_py'],
packages=[''],
package_data={'': ['path/**/data']},
))
os.makedirs('path/subpath/subsubpath')
open('path/subpath/subsubpath/data', 'w').close()

dist.parse_command_line()
dist.run_commands()

assert stat.S_ISREG(os.stat('build/lib/path/subpath/subsubpath/data').st_mode), \
"File is not included"


def test_read_only(tmpdir_cwd):
"""
Ensure read-only flag is not preserved in copy
Expand Down