Skip to content

Commit

Permalink
setup.py: avoid using recursive globs for package_data (#520)
Browse files Browse the repository at this point in the history
* Avoid using recursive globs.

* setuptools apparently follows directory links.
  • Loading branch information
felixfontein committed May 1, 2023
1 parent 57bc589 commit 56e8381
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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

0 comments on commit 56e8381

Please sign in to comment.