From 44d6e18e156cfd11abd5db573f2839b3226c1d16 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 24 Nov 2021 22:45:11 +0100 Subject: [PATCH] Exclude certain unnecessary files from the bdist. --- src/antsibull/build_ansible_commands.py | 14 ++++++++++---- src/antsibull/data/ansible-setup_py.j2 | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/antsibull/build_ansible_commands.py b/src/antsibull/build_ansible_commands.py index abc03f70a..203ee501c 100644 --- a/src/antsibull/build_ansible_commands.py +++ b/src/antsibull/build_ansible_commands.py @@ -127,6 +127,7 @@ def write_release_py(ansible_version: PypiVer, ansible_collections_dir: str) -> def write_setup(ansible_version: PypiVer, ansible_core_version: PypiVer, + collections: t.List[t.Tuple[str, str]], collection_deps: str, package_dir: str) -> None: setup_filename = os.path.join(package_dir, 'setup.py') @@ -136,6 +137,7 @@ def write_setup(ansible_version: PypiVer, version=ansible_version, ansible_core_package_name=get_ansible_core_package_name(ansible_core_version), ansible_core_version=ansible_core_version, + collections=collections, collection_deps=collection_deps) with open(setup_filename, 'w') as f: @@ -144,13 +146,14 @@ def write_setup(ansible_version: PypiVer, def write_python_build_files(ansible_version: PypiVer, ansible_core_version: PypiVer, + collections: t.List[t.Tuple[str, str]], collection_deps: str, package_dir: str, release_notes: t.Optional[ReleaseNotes] = None, debian: bool = False) -> None: copy_boilerplate_files(package_dir) write_manifest(package_dir, release_notes, debian) - write_setup(ansible_version, ansible_core_version, collection_deps, package_dir) + write_setup(ansible_version, ansible_core_version, collections, collection_deps, package_dir) def write_debian_directory(ansible_version: PypiVer, @@ -353,10 +356,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']) + collections = [name.split('.', 1) for name in sorted(dependency_data.deps)] + # Write build scripts and files 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, '', - package_dir, release_notes, app_ctx.extra['debian']) + write_python_build_files(app_ctx.extra['ansible_version'], ansible_core_version, + collections, '', package_dir, release_notes, + app_ctx.extra['debian']) if app_ctx.extra['debian']: write_debian_directory(app_ctx.extra['ansible_version'], ansible_core_version, package_dir) @@ -484,7 +490,7 @@ def build_multiple_command() -> int: collection_deps = '\n' + ',\n'.join(collection_deps) 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_deps, package_dir) + [], collection_deps, package_dir) 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 9155734e0..62ab86939 100644 --- a/src/antsibull/data/ansible-setup_py.j2 +++ b/src/antsibull/data/ansible-setup_py.j2 @@ -176,6 +176,20 @@ setup( python_requires='>=3.8', {%- endif %} packages=['ansible_collections'], +{% if version.major >= 6 %} + exclude_package_data={ + 'ansible_collections': [ +{% for name, namespace in collections %} + '{{ name }}/{{ namespace }}/.gitignore', + '{{ name }}/{{ namespace }}/.github/*', + '{{ name }}/{{ namespace }}/.azure-pipelines/*', + '{{ name }}/{{ namespace }}/changelogs/*', + '{{ name }}/{{ namespace }}/docs/*', + '{{ name }}/{{ namespace }}/tests/*', +{% endfor %} + ], + }, +{% endif %} include_package_data=True, install_requires=[ '{{ ansible_core_package_name }} ~= {{ ansible_core_version }}',{{ collection_deps }}