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

setup.py: avoid using recursive globs for package_data #520

Merged
merged 2 commits into from May 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/520-setup.py.yml
@@ -0,0 +1,2 @@
bugfixes:
- "For ``setup.py`` generated for Ansible 8+, do not use recursive globs (``**``) as these are only supported since setuptools 62.3.0 (https://github.com/ansible-community/antsibull/pull/520)."
22 changes: 16 additions & 6 deletions src/antsibull/build_ansible_commands.py
Expand Up @@ -518,6 +518,21 @@ def ignore_directory(prefix: str, directory: str):
return sorted(result), sorted(ignored_files)


def _collect_collection_data_dirs(collection_path: str) -> list[str]:
directories = []
for root, dirs, _ in os.walk(collection_path, topdown=True, followlinks=True):
if root == collection_path:
# Make sure that all directories starting with '.', and all
# directories called 'tests' or 'docs', are not traversed into.
for dirname in list(dirs):
if dirname in ('tests', 'docs') or dirname.startswith('.'):
dirs.remove(dirname)
continue
relative_dir = os.path.relpath(root, collection_path)
directories.append(relative_dir)
return sorted(directories)


def collect_collection_info(
ansible_version: PypiVer,
dependency_data: DependencyFileData,
Expand All @@ -532,12 +547,7 @@ def collect_collection_info(
namespace, name = collection.split('.', 1)
collection_namespaces[namespace].append(name)
collection_path = os.path.join(ansible_collections_dir, namespace, name)
collection_directories[collection] = [
file for file in os.listdir(collection_path)
if file not in ('tests', 'docs')
and not file.startswith('.')
and os.path.isdir(os.path.join(collection_path, file))
]
collection_directories[collection] = _collect_collection_data_dirs(collection_path)
else:
# pylint:disable-next=unused-variable
collection_exclude_paths, collection_ignored_files = compile_collection_exclude_paths(
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull/data/ansible-setup_py.j2
Expand Up @@ -200,7 +200,7 @@ setup(
'ansible_collections.{{ collection }}': [
'*',
{%- for dir in collection_directories[collection] %}
'{{ dir }}/**/*', '{{ dir }}/**/.*',
'{{ dir }}/*', '{{ dir }}/.*',
{%- endfor %}
],
{%- endfor %}
Expand Down