From 16a4d74fb5c112ca3c1aadeee4042a0a798df346 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 30 Mar 2023 20:57:39 +0200 Subject: [PATCH 1/9] Work around setuptools 63 deprecations. --- changelogs/fragments/502-setup.py.yml | 2 ++ src/antsibull/data/ansible-setup_py.j2 | 27 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/502-setup.py.yml diff --git a/changelogs/fragments/502-setup.py.yml b/changelogs/fragments/502-setup.py.yml new file mode 100644 index 00000000..eda002a4 --- /dev/null +++ b/changelogs/fragments/502-setup.py.yml @@ -0,0 +1,2 @@ +minor_changes: + - "Make compatible with deprecations issued by newer setuptools releases (https://github.com/ansible-community/antsibull/issues/433, https://github.com/ansible-community/antsibull/pull/502)." diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index d2cb8560..0af24d66 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -5,7 +5,11 @@ import os import sys +{%- if version.major >= 8 %} +from setuptools import setup, find_namespace_packages +{%- else %} from setuptools import setup +{%- endif %} {%- if version.major < 6 %} @@ -174,17 +178,32 @@ setup( }, license='GPLv3+', python_requires='{{ python_requires }}', +{%- if version.major >= 8 %} + packages=find_namespace_packages( + '.', + include=[ + 'ansible_collections*', + ], + exclude=[ + 'ansible_collections.*.*.tests', + 'ansible_collections.*.*.docs', + ], + ), + package_dir={'': '.'}, + package_data={'': ['*', '*/*/*/**/.*']}, +{%- else %} packages=['ansible_collections'], -{% if version.major >= 6 and collection_exclude_paths %} +{%- if version.major >= 6 and collection_exclude_paths %} exclude_package_data={ 'ansible_collections': [ -{%- for path in collection_exclude_paths %} +{%- for path in collection_exclude_paths %} '{{ path }}', -{%- endfor %} +{%- endfor %} ], }, -{%- endif %} +{%- endif %} include_package_data=True, +{%- endif %} install_requires=[ '{{ ansible_core_package_name }} ~= {{ ansible_core_version }}',{{ collection_deps }} ], From 85d6cf25728d1312212de01da51aef9028a349d3 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 30 Mar 2023 21:04:04 +0200 Subject: [PATCH 2/9] Forgot excludes. --- src/antsibull/data/ansible-setup_py.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 0af24d66..0d7eb0fe 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -185,7 +185,9 @@ setup( 'ansible_collections*', ], exclude=[ + 'ansible_collections.*.*.tests.*', 'ansible_collections.*.*.tests', + 'ansible_collections.*.*.docs.*', 'ansible_collections.*.*.docs', ], ), From f8dca7619e5c02c458364d0407538169719a0edb Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 30 Mar 2023 22:59:13 +0200 Subject: [PATCH 3/9] Work around some of the problems. --- src/antsibull/build_ansible_commands.py | 18 +++++++++++++++--- src/antsibull/data/ansible-setup_py.j2 | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 5d275cf8..45d690c0 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -211,6 +211,8 @@ def write_setup(ansible_version: PypiVer, ansible_core_version: PypiVer, collection_exclude_paths: list[str], collection_deps: str, + collection_names: list[str], + collection_namespaces: list[str], package_dir: str, python_requires: str) -> None: setup_filename = os.path.join(package_dir, 'setup.py') @@ -222,6 +224,8 @@ def write_setup(ansible_version: PypiVer, ansible_core_version=ansible_core_version, collection_exclude_paths=collection_exclude_paths, collection_deps=collection_deps, + collection_names=collection_names, + collection_namespaces=collection_namespaces, python_requires=python_requires, PypiVer=PypiVer, ) @@ -240,6 +244,8 @@ def write_python_build_files(ansible_version: PypiVer, ansible_core_version: PypiVer, collection_exclude_paths: list[str], collection_deps: str, + collection_names: list[str], + collection_namespaces: list[str], package_dir: str, release_notes: ReleaseNotes | None = None, debian: bool = False, @@ -250,7 +256,7 @@ def write_python_build_files(ansible_version: PypiVer, write_manifest(package_dir, release_notes, debian, tags_file) write_setup( ansible_version, ansible_core_version, collection_exclude_paths, collection_deps, - package_dir, python_requires) + collection_names, collection_namespaces, package_dir, python_requires) def write_debian_directory(ansible_version: PypiVer, @@ -576,6 +582,11 @@ def rebuild_single_command() -> int: # TODO: do something with collection_ignored_files + # Collect collection namespaces + collection_namespaces: set[str] = set() + for collection in dependency_data.deps: + collection_namespaces.add(collection.split('.', 1)[0]) + # Write build scripts and files tags_path: str | None = None if app_ctx.extra['tags_file']: @@ -583,7 +594,8 @@ def rebuild_single_command() -> int: app_ctx.extra['tags_file']) write_build_script(app_ctx.extra['ansible_version'], ansible_core_version, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version, - collection_exclude_paths, '', package_dir, release_notes, + collection_exclude_paths, '', sorted(dependency_data.deps), + sorted(collection_namespaces), package_dir, release_notes, app_ctx.extra['debian'], python_requires, tags_path) if app_ctx.extra['debian']: write_debian_directory(app_ctx.extra['ansible_version'], ansible_core_version, @@ -719,7 +731,7 @@ def build_multiple_command() -> int: collection_deps_str = '\n' + ',\n'.join(collection_deps) write_build_script(app_ctx.extra['ansible_version'], ansible_core_version_obj, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version_obj, - [], collection_deps_str, package_dir, + [], collection_deps_str, [], [], package_dir, python_requires=python_requires) make_dist(package_dir, app_ctx.extra['sdist_dir']) diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 0d7eb0fe..6530082e 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -185,14 +185,25 @@ setup( 'ansible_collections*', ], exclude=[ - 'ansible_collections.*.*.tests.*', - 'ansible_collections.*.*.tests', - 'ansible_collections.*.*.docs.*', - 'ansible_collections.*.*.docs', +{%- for collection in collection_names %} + 'ansible_collections.{{ collection }}.tests.*', + 'ansible_collections.{{ collection }}.tests', + 'ansible_collections.{{ collection }}.docs.*', + 'ansible_collections.{{ collection }}.docs', +{%- endfor %} ], ), package_dir={'': '.'}, package_data={'': ['*', '*/*/*/**/.*']}, + exclude_package_data={ + 'ansible_collections': ['*/*/tests/.*', '*/*/tests/**/.*', '*/*/docs/.*', '*/*/docs/**/.*'], +{%- for namespace in collection_namespaces %} + 'ansible_collections.{{ namespace }}': ['*/tests/.*', '*/tests/**/.*', '*/docs/.*', '*/docs/**/.*'], +{%- endfor %} +{%- for collection in collection_names %} + 'ansible_collections.{{ collection }}': ['tests/.*', 'tests/**/.*', 'docs/.*', 'docs/**/.*'], +{%- endfor %} + }, {%- else %} packages=['ansible_collections'], {%- if version.major >= 6 and collection_exclude_paths %} From 1f3b92d6efac1041395adef90504f83f347d3fa2 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 1 Apr 2023 21:33:01 +0200 Subject: [PATCH 4/9] Improve handling of dotfiles. --- src/antsibull/build_ansible_commands.py | 14 ++++++++------ src/antsibull/data/ansible-setup_py.j2 | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 45d690c0..7c3ee720 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -11,6 +11,7 @@ import os.path import shutil import tempfile +from collections import defaultdict from collections.abc import Collection, Mapping from typing import TYPE_CHECKING @@ -212,7 +213,7 @@ def write_setup(ansible_version: PypiVer, collection_exclude_paths: list[str], collection_deps: str, collection_names: list[str], - collection_namespaces: list[str], + collection_namespaces: Mapping[str, list[str]], package_dir: str, python_requires: str) -> None: setup_filename = os.path.join(package_dir, 'setup.py') @@ -245,7 +246,7 @@ def write_python_build_files(ansible_version: PypiVer, collection_exclude_paths: list[str], collection_deps: str, collection_names: list[str], - collection_namespaces: list[str], + collection_namespaces: Mapping[str, list[str]], package_dir: str, release_notes: ReleaseNotes | None = None, debian: bool = False, @@ -583,9 +584,10 @@ def rebuild_single_command() -> int: # TODO: do something with collection_ignored_files # Collect collection namespaces - collection_namespaces: set[str] = set() + collection_namespaces: dict[str, list[str]] = defaultdict(list) for collection in dependency_data.deps: - collection_namespaces.add(collection.split('.', 1)[0]) + namespace, name = collection.split('.', 1) + collection_namespaces[namespace].append(name) # Write build scripts and files tags_path: str | None = None @@ -595,7 +597,7 @@ def rebuild_single_command() -> int: write_build_script(app_ctx.extra['ansible_version'], ansible_core_version, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version, collection_exclude_paths, '', sorted(dependency_data.deps), - sorted(collection_namespaces), package_dir, release_notes, + collection_namespaces, package_dir, release_notes, app_ctx.extra['debian'], python_requires, tags_path) if app_ctx.extra['debian']: write_debian_directory(app_ctx.extra['ansible_version'], ansible_core_version, @@ -731,7 +733,7 @@ def build_multiple_command() -> int: collection_deps_str = '\n' + ',\n'.join(collection_deps) write_build_script(app_ctx.extra['ansible_version'], ansible_core_version_obj, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version_obj, - [], collection_deps_str, [], [], package_dir, + [], collection_deps_str, [], {}, package_dir, python_requires=python_requires) make_dist(package_dir, app_ctx.extra['sdist_dir']) diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index 6530082e..b49ae9c5 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -196,9 +196,20 @@ setup( package_dir={'': '.'}, package_data={'': ['*', '*/*/*/**/.*']}, exclude_package_data={ - 'ansible_collections': ['*/*/tests/.*', '*/*/tests/**/.*', '*/*/docs/.*', '*/*/docs/**/.*'], -{%- for namespace in collection_namespaces %} - 'ansible_collections.{{ namespace }}': ['*/tests/.*', '*/tests/**/.*', '*/docs/.*', '*/docs/**/.*'], + 'ansible_collections': [ +{%- for collection in collection_names %} + '{{ collection.replace('.', '/') }}/tests/.*', + '{{ collection.replace('.', '/') }}/tests/**/.*', + '{{ collection.replace('.', '/') }}/docs/.*', + '{{ collection.replace('.', '/') }}/docs/**/.*', +{%- endfor %} + ], +{%- for namespace, names in collection_namespaces | dictsort %} + 'ansible_collections.{{ namespace }}': [ +{%- for name in names %} + '{{ name }}/tests/.*', '{{ name }}/tests/**/.*', '{{ name }}/docs/.*', '{{ name }}/docs/**/.*', +{%- endfor %} + ], {%- endfor %} {%- for collection in collection_names %} 'ansible_collections.{{ collection }}': ['tests/.*', 'tests/**/.*', 'docs/.*', 'docs/**/.*'], From f78175cbbb71080cafe2c20e51f6e08c5d8c79f1 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 4 Apr 2023 21:30:00 +0200 Subject: [PATCH 5/9] Be more expicit with what to include, so that exclusion is less complex. --- src/antsibull/build_ansible_commands.py | 20 +++++++++++++++----- src/antsibull/data/ansible-setup_py.j2 | 25 ++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 7c3ee720..56f7b7fe 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -214,6 +214,7 @@ def write_setup(ansible_version: PypiVer, collection_deps: str, collection_names: list[str], collection_namespaces: Mapping[str, list[str]], + collection_directories: Mapping[str, list[str]], package_dir: str, python_requires: str) -> None: setup_filename = os.path.join(package_dir, 'setup.py') @@ -227,6 +228,7 @@ def write_setup(ansible_version: PypiVer, collection_deps=collection_deps, collection_names=collection_names, collection_namespaces=collection_namespaces, + collection_directories=collection_directories, python_requires=python_requires, PypiVer=PypiVer, ) @@ -247,6 +249,7 @@ def write_python_build_files(ansible_version: PypiVer, collection_deps: str, collection_names: list[str], collection_namespaces: Mapping[str, list[str]], + collection_directories: Mapping[str, list[str]], package_dir: str, release_notes: ReleaseNotes | None = None, debian: bool = False, @@ -257,7 +260,8 @@ def write_python_build_files(ansible_version: PypiVer, write_manifest(package_dir, release_notes, debian, tags_file) write_setup( ansible_version, ansible_core_version, collection_exclude_paths, collection_deps, - collection_names, collection_namespaces, package_dir, python_requires) + collection_names, collection_namespaces, collection_directories, package_dir, + python_requires) def write_debian_directory(ansible_version: PypiVer, @@ -583,11 +587,16 @@ def rebuild_single_command() -> int: # TODO: do something with collection_ignored_files - # Collect collection namespaces + # Collect collection namespaces and collection root subdirectories collection_namespaces: dict[str, list[str]] = defaultdict(list) + collection_directories: dict[str, list[str]] = {} for collection in dependency_data.deps: namespace, name = collection.split('.', 1) collection_namespaces[namespace].append(name) + collection_directories[collection] = [ + dir for dir in os.listdir(os.path.join(ansible_collections_dir, namespace, name)) + if dir not in ('tests', 'docs') and not dir.startswith('.') + ] # Write build scripts and files tags_path: str | None = None @@ -597,8 +606,9 @@ def rebuild_single_command() -> int: write_build_script(app_ctx.extra['ansible_version'], ansible_core_version, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version, collection_exclude_paths, '', sorted(dependency_data.deps), - collection_namespaces, package_dir, release_notes, - app_ctx.extra['debian'], python_requires, tags_path) + collection_namespaces, collection_directories, package_dir, + release_notes, app_ctx.extra['debian'], python_requires, + tags_path) if app_ctx.extra['debian']: write_debian_directory(app_ctx.extra['ansible_version'], ansible_core_version, package_dir) @@ -733,7 +743,7 @@ def build_multiple_command() -> int: collection_deps_str = '\n' + ',\n'.join(collection_deps) write_build_script(app_ctx.extra['ansible_version'], ansible_core_version_obj, package_dir) write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version_obj, - [], collection_deps_str, [], {}, package_dir, + [], collection_deps_str, [], {}, {}, package_dir, python_requires=python_requires) make_dist(package_dir, app_ctx.extra['sdist_dir']) diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index b49ae9c5..bcb721ef 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -182,7 +182,8 @@ setup( packages=find_namespace_packages( '.', include=[ - 'ansible_collections*', + 'ansible_collections', + 'ansible_collections.*', ], exclude=[ {%- for collection in collection_names %} @@ -194,25 +195,19 @@ setup( ], ), package_dir={'': '.'}, - package_data={'': ['*', '*/*/*/**/.*']}, - exclude_package_data={ - 'ansible_collections': [ + package_data={ {%- for collection in collection_names %} - '{{ collection.replace('.', '/') }}/tests/.*', - '{{ collection.replace('.', '/') }}/tests/**/.*', - '{{ collection.replace('.', '/') }}/docs/.*', - '{{ collection.replace('.', '/') }}/docs/**/.*', -{%- endfor %} - ], -{%- for namespace, names in collection_namespaces | dictsort %} - 'ansible_collections.{{ namespace }}': [ -{%- for name in names %} - '{{ name }}/tests/.*', '{{ name }}/tests/**/.*', '{{ name }}/docs/.*', '{{ name }}/docs/**/.*', + 'ansible_collections.{{ collection }}': [ + '*', +{%- for dir in collection_directories[collection] %} + '{{ dir }}/**/*', '{{ dir }}/**/.*', {%- endfor %} ], {%- endfor %} + }, + exclude_package_data={ {%- for collection in collection_names %} - 'ansible_collections.{{ collection }}': ['tests/.*', 'tests/**/.*', 'docs/.*', 'docs/**/.*'], + 'ansible_collections.{{ collection }}': ['tests/**/*', 'docs/**/*'], {%- endfor %} }, {%- else %} From 6a4a271a70f59e9c60bcdc14ed7acbde0fc02625 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 5 Apr 2023 07:27:09 +0200 Subject: [PATCH 6/9] Stick to only directories (and not random files). --- src/antsibull/build_ansible_commands.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 56f7b7fe..4f06e1e0 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -593,9 +593,12 @@ def rebuild_single_command() -> int: for collection in dependency_data.deps: namespace, name = collection.split('.', 1) collection_namespaces[namespace].append(name) + collection_path = os.path.join(ansible_collections_dir, namespace, name) collection_directories[collection] = [ - dir for dir in os.listdir(os.path.join(ansible_collections_dir, namespace, name)) - if dir not in ('tests', 'docs') and not dir.startswith('.') + 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)) ] # Write build scripts and files From 0b01b53b8eb08a72803095b19bc58adef6f978fa Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 5 Apr 2023 07:34:28 +0200 Subject: [PATCH 7/9] exclude_package_data is no longer needed. --- src/antsibull/data/ansible-setup_py.j2 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/antsibull/data/ansible-setup_py.j2 b/src/antsibull/data/ansible-setup_py.j2 index bcb721ef..45c53dcd 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -203,11 +203,6 @@ setup( '{{ dir }}/**/*', '{{ dir }}/**/.*', {%- endfor %} ], -{%- endfor %} - }, - exclude_package_data={ -{%- for collection in collection_names %} - 'ansible_collections.{{ collection }}': ['tests/**/*', 'docs/**/*'], {%- endfor %} }, {%- else %} From 0cbec2dbf04f8a78cceffaebb1b4db5ccf4bc480 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 6 Apr 2023 20:57:01 +0200 Subject: [PATCH 8/9] Only run compile_collection_exclude_paths() when the result is used. --- src/antsibull/build_ansible_commands.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index 4f06e1e0..ff6fb984 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -517,7 +517,7 @@ def ignore_directory(prefix: str, directory: str): return sorted(result), sorted(ignored_files) -def rebuild_single_command() -> int: +def rebuild_single_command() -> int: # noqa: C901 app_ctx = app_context.app_ctx.get() deps_filename = os.path.join(app_ctx.extra['data_dir'], app_ctx.extra['deps_file']) @@ -581,11 +581,13 @@ def rebuild_single_command() -> int: release_notes.write_changelog_to(app_ctx.extra['dest_data_dir']) release_notes.write_porting_guide_to(app_ctx.extra['dest_data_dir']) - # pylint:disable-next=unused-variable - collection_exclude_paths, collection_ignored_files = compile_collection_exclude_paths( - dependency_data.deps, ansible_collections_dir) - - # TODO: do something with collection_ignored_files + if app_ctx.extra['ansible_version'].major >= 8: + collection_exclude_paths: list[str] = [] + else: + # pylint:disable-next=unused-variable + collection_exclude_paths, collection_ignored_files = compile_collection_exclude_paths( + dependency_data.deps, ansible_collections_dir) + # TODO: do something with collection_ignored_files # Collect collection namespaces and collection root subdirectories collection_namespaces: dict[str, list[str]] = defaultdict(list) From f63694b9dc722f877c2cffc6bcec6fe7da08e3e0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 7 Apr 2023 14:38:27 +0200 Subject: [PATCH 9/9] Refactor. --- src/antsibull/build_ansible_commands.py | 55 +++++++++++++++---------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index ff6fb984..7f4c27d4 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -517,7 +517,36 @@ def ignore_directory(prefix: str, directory: str): return sorted(result), sorted(ignored_files) -def rebuild_single_command() -> int: # noqa: C901 +def collect_collection_info( + ansible_version: PypiVer, + dependency_data: DependencyFileData, + ansible_collections_dir: str, +) -> tuple[list[str], dict[str, list[str]], dict[str, list[str]]]: + collection_exclude_paths: list[str] = [] + collection_namespaces: dict[str, list[str]] = defaultdict(list) + collection_directories: dict[str, list[str]] = {} + + if ansible_version.major >= 8: + for collection in dependency_data.deps: + 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)) + ] + else: + # pylint:disable-next=unused-variable + collection_exclude_paths, collection_ignored_files = compile_collection_exclude_paths( + dependency_data.deps, ansible_collections_dir) + # TODO: do something with collection_ignored_files + + return collection_exclude_paths, collection_namespaces, collection_directories + + +def rebuild_single_command() -> int: app_ctx = app_context.app_ctx.get() deps_filename = os.path.join(app_ctx.extra['data_dir'], app_ctx.extra['deps_file']) @@ -581,27 +610,9 @@ def rebuild_single_command() -> int: # noqa: C901 release_notes.write_changelog_to(app_ctx.extra['dest_data_dir']) release_notes.write_porting_guide_to(app_ctx.extra['dest_data_dir']) - if app_ctx.extra['ansible_version'].major >= 8: - collection_exclude_paths: list[str] = [] - else: - # pylint:disable-next=unused-variable - collection_exclude_paths, collection_ignored_files = compile_collection_exclude_paths( - dependency_data.deps, ansible_collections_dir) - # TODO: do something with collection_ignored_files - - # Collect collection namespaces and collection root subdirectories - collection_namespaces: dict[str, list[str]] = defaultdict(list) - collection_directories: dict[str, list[str]] = {} - for collection in dependency_data.deps: - 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_exclude_paths, collection_namespaces, collection_directories = \ + collect_collection_info( + app_ctx.extra['ansible_version'], dependency_data, ansible_collections_dir) # Write build scripts and files tags_path: str | None = None