diff --git a/backend/src/hatchling/builders/sdist.py b/backend/src/hatchling/builders/sdist.py index ec656f344..d8ae66f43 100644 --- a/backend/src/hatchling/builders/sdist.py +++ b/backend/src/hatchling/builders/sdist.py @@ -228,6 +228,7 @@ def construct_setup_py_file(self, packages): return contents def get_default_build_data(self): + # Check for inclusion first to avoid redundant pattern matching build_data = {'artifacts': []} if not self.config.include_path('pyproject.toml'): build_data['artifacts'].append('/pyproject.toml') @@ -242,7 +243,12 @@ def get_default_build_data(self): if not self.config.include_path(license_file): build_data['artifacts'].append('/{}'.format(license_file)) - build_data['artifacts'].append('/{}'.format(DEFAULT_BUILD_SCRIPT)) + if not self.config.include_path(DEFAULT_BUILD_SCRIPT): + build_data['artifacts'].append('/{}'.format(DEFAULT_BUILD_SCRIPT)) + + if not self.config.include_path('.gitignore'): + build_data['artifacts'].append('/.gitignore') + return build_data @property diff --git a/docs/meta/history.md b/docs/meta/history.md index e99a6b765..d7e5ccbd2 100644 --- a/docs/meta/history.md +++ b/docs/meta/history.md @@ -114,6 +114,10 @@ This is the first release candidate for Hatch v1, a complete rewrite. ### Unreleased +***Added:*** + +- Always include any root `.gitignore` file for source distributions so recursive builds are guaranteed to be identical + ***Fixed:*** - Fix metadata handling of non-ASCII characters in README files for source distributions on Python 2 diff --git a/tests/backend/builders/test_sdist.py b/tests/backend/builders/test_sdist.py index 9d88ae04d..93137fed8 100644 --- a/tests/backend/builders/test_sdist.py +++ b/tests/backend/builders/test_sdist.py @@ -759,7 +759,9 @@ def initialize(self, version, build_data): 'hatch': { 'version': {'path': 'my_app/__about__.py'}, 'build': { - 'targets': {'sdist': {'versions': ['standard'], 'exclude': [DEFAULT_BUILD_SCRIPT]}}, + 'targets': { + 'sdist': {'versions': ['standard'], 'exclude': [DEFAULT_BUILD_SCRIPT, '.gitignore']} + }, 'artifacts': ['my_app/lib.so'], 'hooks': {'custom': {'path': DEFAULT_BUILD_SCRIPT}}, },