From 019ad8960825babb5cf322394a0ad5a70f510736 Mon Sep 17 00:00:00 2001 From: nullableVoidPtr <30564701+nullableVoidPtr@users.noreply.github.com> Date: Sat, 7 May 2022 21:25:55 +0800 Subject: [PATCH] Allow recursive globs for package_data --- setuptools/command/build_py.py | 3 ++- setuptools/tests/test_build_py.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index c3fdc0927c5..ac7cff95da9 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -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 @@ -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) diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py index 19c8b780b85..58fee83192e 100644 --- a/setuptools/tests/test_build_py.py +++ b/setuptools/tests/test_build_py.py @@ -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_IREG(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