Skip to content

Commit

Permalink
Rework the list of files included in build artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Nov 26, 2023
1 parent 1ee19a5 commit c3f5ef0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
21 changes: 11 additions & 10 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
3 changes: 3 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit c3f5ef0

Please sign in to comment.