From f509a33e31f55a6dee75a781b1b1a2215c9ef197 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 29 Apr 2023 21:39:08 +0200 Subject: [PATCH 1/2] Avoid using recursive globs. --- changelogs/fragments/520-setup.py.yml | 2 ++ src/antsibull/build_ansible_commands.py | 22 ++++++++++++++++------ src/antsibull/data/ansible-setup_py.j2 | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/520-setup.py.yml diff --git a/changelogs/fragments/520-setup.py.yml b/changelogs/fragments/520-setup.py.yml new file mode 100644 index 00000000..c60d2b80 --- /dev/null +++ b/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)." diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 505ceb72..472ed96e 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -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): + 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, @@ -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( diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 45c53dcd..1ffb75c4 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -200,7 +200,7 @@ setup( 'ansible_collections.{{ collection }}': [ '*', {%- for dir in collection_directories[collection] %} - '{{ dir }}/**/*', '{{ dir }}/**/.*', + '{{ dir }}/*', '{{ dir }}/.*', {%- endfor %} ], {%- endfor %} From 8f71485800dcfa17d142d3336c22c493f7dd1454 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 29 Apr 2023 22:00:06 +0200 Subject: [PATCH 2/2] setuptools apparently follows directory links. --- src/antsibull/build_ansible_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 472ed96e..08afced6 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -520,7 +520,7 @@ def ignore_directory(prefix: str, directory: str): def _collect_collection_data_dirs(collection_path: str) -> list[str]: directories = [] - for root, dirs, _ in os.walk(collection_path, topdown=True): + 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.