-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
package_data not doing recursive glob calls #1806
Comments
Yes, I can confirm that without calling What this issue needs is more background. What is a use-case where having recursive globbing support would be helpful? More importantly, this routine is for |
Thanks for getting back. I have a nested directory of configuration files (.yml) and a nested directory of validation files (.json). Unfortunately, I have to go through each sub directory in order to include them in the package. This works and is working for my current use case, but every time I add addition sub-directories, I have to remember to add another path.
I would prefer to just have to do this (in fact I originally tried this, but didn't work which is why I reported the issue).
I also tried
|
Agreed, it would be massively helpful if I could use the |
I just found this issue working with Django templates as well. Recursive glob support would be tremendously helpful when packaging Django apps that include templates |
I got the same problem with stub files for typing. These data files are *.pyi and may be spread at multiple folder levels. I have two workarounds to this difficulty. One is with a custom implementation: import os
from typing import List
def find_stubs(top: str) -> List[str]:
stubs = []
for root, _, files in os.walk(top):
dir = root.split(os.path.sep, 1)[-1] # rid of 'top'
for f in files:
if f.endswith('.pyi'):
if os.path.sep in root:
f = os.path.join(dir, f)
stubs.append(f)
return stubs
setup(
…
package_data={'foo': find_stubs('foo')},
…
) Another one is more generic, with a manifest template: setup(
…
include_package_data=True,
…
) MANIFEST.in
Working with Django, I prefer the second way because I also need to include many other data files:
|
I would like to add the issue that for my cython code setuptools does not copy the data files to Sources list my |
It would be possible to switch to setup.cfg declarative config style, if we'd specify the files individually, or add subfolder matching via multiple single star globs, i.e.: *.css, */*.css, */*/*.css, but unless all files are specified or pypa/setuptools#1806 is implemented it would probably cause confusion for a histoqc developer when they're modifying the ui.
Bump. At a glance, the situation looks worse than described when there are multiple packages in a single source tree. Unfortunately I can't quite get resolution on what's happening when I run |
It sounds as if there's a reasonable need for this issue, and now that I see that using
I'm not aware of one. I guess you'll have to go to the source. |
As a workaround while this is implemented, I've done the following, it might be useful to someone else (note the example uses import os
from pathlib import Path
from typing import Dict, List
def _expand_recursive_globs(package_data: Dict[str, List[str]]) -> Dict[str, List[str]]:
root = (Path(__file__).parent / "src").resolve()
for module, patterns in package_data.items():
new_patterns = []
m_root = None
for idx, p in enumerate(patterns):
if "**" in p:
m_root = m_root or root / module.replace(".", os.sep)
for f in m_root.glob("**"): # all subdirectories
if f.name == "__pycache__":
continue
subdir_pattern = p.replace("**", str(f.relative_to(m_root)))
new_patterns.append(subdir_pattern)
else:
new_patterns.append(p)
package_data[module] = new_patterns
return package_data
setup(
name="my-package",
packages=find_packages("src"),
package_dir={"": "src"},
package_data=_expand_recursive_globs({"my_module": ["**/*.csv"]})
) and if you have this project structure:
then the package data will expand to: package_data={"my_module": ["./a/*.csv", "./b/*.csv"]}) |
Bump. |
Hi @mat-rs thanks for the ping. If you would like to give it a try, we would love receiving a PR! Regarding the Alternatively, you can also consider |
Actually I didn't want to add Would it be as simple as replacing:
with
Or would that break anything of the current expected behavior? |
Thank you very much @mat-rs for having a look on that!
It seems like a good shot, by looking at setuptools/setuptools/command/build_py.py Lines 101 to 104 in 0ec53b2
You can start by running the test suite (e.g. via |
Even though glob supports it, glob support for recursive ** searching is not enabled when specifying package_data. This is not clear in the documentation.
setuptools/setuptools/command/build_py.py
Line 106 in a94ccbf
This means that only single
*
searches in a specific directory are supported. By changing theglob
function to support recursive, this would allow us to specify**
patterns to a directory instead of having to specify every sub-directory in the structure.Reference:
https://github.com/python/cpython/blob/master/Lib/glob.py#L18
The text was updated successfully, but these errors were encountered: