From eb92ee4048d24bd89499fdc063ec5cac720a351a Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Sun, 26 Nov 2023 14:57:47 +0100 Subject: [PATCH 1/2] Rework the list of files included in build artifacts --- src/poetry/core/masonry/builders/sdist.py | 6 +++++- src/poetry/core/masonry/builders/wheel.py | 21 ++++++++++--------- .../builders/fixtures/complete/AUTHORS | 0 .../builders/fixtures/complete/COPYING | 0 .../builders/fixtures/complete/LICENCE | 0 tests/masonry/builders/test_complete.py | 3 +++ tests/masonry/builders/test_sdist.py | 3 +++ 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 tests/masonry/builders/fixtures/complete/AUTHORS create mode 100644 tests/masonry/builders/fixtures/complete/COPYING create mode 100644 tests/masonry/builders/fixtures/complete/LICENCE diff --git a/src/poetry/core/masonry/builders/sdist.py b/src/poetry/core/masonry/builders/sdist.py index ae0222cf0..c7e761e37 100644 --- a/src/poetry/core/masonry/builders/sdist.py +++ b/src/poetry/core/masonry/builders/sdist.py @@ -321,7 +321,11 @@ def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile to_add = super().find_files_to_add(exclude_build) # add any additional files, starting with all LICENSE files - additional_files: set[Path] = set(self._path.glob("LICENSE*")) + additional_files: set[Path] = set() + include_files_patterns = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"} + + for pattern in include_files_patterns: + additional_files.update(self._path.glob(pattern)) # add script files additional_files.update(self.convert_script_files()) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 441edd467..5ce28a9b9 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -288,21 +288,22 @@ def prepare_metadata(self, metadata_directory: Path) -> Path: with (dist_info / "METADATA").open("w", encoding="utf-8", newline="\n") as f: self._write_metadata_file(f) - license_files = set() - for base in ("COPYING", "LICENSE"): - license_files.add(self._path / base) - license_files.update(self._path.glob(base + ".*")) + legal_files: set[Path] = set() + include_files_globs = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"} - license_files.update(self._path.joinpath("LICENSES").glob("**/*")) + for file in include_files_globs: + legal_files.update(self._path.glob(file)) - for license_file in license_files: - if not license_file.is_file(): - logger.debug(f"Skipping: {license_file.as_posix()}") + legal_files.update(self._path.joinpath("LICENSES").glob("**/*")) + + for legal_file in legal_files: + if not legal_file.is_file(): + logger.debug(f"Skipping: {legal_file.as_posix()}") continue - dest = dist_info / license_file.relative_to(self._path) + dest = dist_info / legal_file.relative_to(self._path) dest.parent.mkdir(parents=True, exist_ok=True) - shutil.copy(license_file, dest) + shutil.copy(legal_file, dest) return dist_info diff --git a/tests/masonry/builders/fixtures/complete/AUTHORS b/tests/masonry/builders/fixtures/complete/AUTHORS new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/complete/COPYING b/tests/masonry/builders/fixtures/complete/COPYING new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/complete/LICENCE b/tests/masonry/builders/fixtures/complete/LICENCE new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 6581dcbb6..1b518647e 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -133,6 +133,9 @@ def test_complete(no_vcs: bool) -> None: "my_package-1.2.3.dist-info/LICENSE", "my_package-1.2.3.dist-info/METADATA", "my_package-1.2.3.dist-info/WHEEL", + "my_package-1.2.3.dist-info/COPYING", + "my_package-1.2.3.dist-info/LICENCE", + "my_package-1.2.3.dist-info/AUTHORS", ], key=lambda x: Path(x), ), diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index 623ebec8b..dc3591541 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -178,6 +178,9 @@ def test_find_files_to_add() -> None: result = {f.relative_to_source_root() for f in builder.find_files_to_add()} assert result == { + Path("AUTHORS"), + Path("COPYING"), + Path("LICENCE"), Path("LICENSE"), Path("README.rst"), Path("bin/script.sh"), From f6fd865e967e004cc60c72cd9989c4e71a24abf7 Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Tue, 2 Jan 2024 00:02:07 +0100 Subject: [PATCH 2/2] CR fixes --- src/poetry/core/masonry/builders/builder.py | 10 ++++++++++ src/poetry/core/masonry/builders/sdist.py | 7 +++---- src/poetry/core/masonry/builders/wheel.py | 10 +--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/poetry/core/masonry/builders/builder.py b/src/poetry/core/masonry/builders/builder.py index e0eca0829..a07d06e09 100644 --- a/src/poetry/core/masonry/builders/builder.py +++ b/src/poetry/core/masonry/builders/builder.py @@ -379,6 +379,16 @@ def convert_author(cls, author: str) -> dict[str, str]: return {"name": name, "email": email} + def _get_legal_files(self) -> set[Path]: + include_files_patterns = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"} + files: set[Path] = set() + + for pattern in include_files_patterns: + files.update(self._path.glob(pattern)) + + files.update(self._path.joinpath("LICENSES").glob("**/*")) + return files + class BuildIncludeFile: def __init__( diff --git a/src/poetry/core/masonry/builders/sdist.py b/src/poetry/core/masonry/builders/sdist.py index c7e761e37..1062df7fb 100644 --- a/src/poetry/core/masonry/builders/sdist.py +++ b/src/poetry/core/masonry/builders/sdist.py @@ -320,12 +320,11 @@ def find_nearest_pkg(rel_path: str) -> tuple[str, str]: def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile]: to_add = super().find_files_to_add(exclude_build) - # add any additional files, starting with all LICENSE files + # add any additional files additional_files: set[Path] = set() - include_files_patterns = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"} - for pattern in include_files_patterns: - additional_files.update(self._path.glob(pattern)) + # add legal files + additional_files.update(self._get_legal_files()) # add script files additional_files.update(self.convert_script_files()) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 5ce28a9b9..9c00b0413 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -288,15 +288,7 @@ def prepare_metadata(self, metadata_directory: Path) -> Path: with (dist_info / "METADATA").open("w", encoding="utf-8", newline="\n") as f: self._write_metadata_file(f) - legal_files: set[Path] = set() - include_files_globs = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"} - - for file in include_files_globs: - legal_files.update(self._path.glob(file)) - - legal_files.update(self._path.joinpath("LICENSES").glob("**/*")) - - for legal_file in legal_files: + for legal_file in self._get_legal_files(): if not legal_file.is_file(): logger.debug(f"Skipping: {legal_file.as_posix()}") continue