Skip to content

Commit

Permalink
Rework the list of files included in build artifacts (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Jan 2, 2024
1 parent 842033f commit 21b0033
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
7 changes: 5 additions & 2 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +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
additional_files: set[Path] = set(self._path.glob("LICENSE*"))
# add any additional files
additional_files: set[Path] = set()

# add legal files
additional_files.update(self._get_legal_files())

# add script files
additional_files.update(self.convert_script_files())
Expand Down
17 changes: 5 additions & 12 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,14 @@ 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 + ".*"))

license_files.update(self._path.joinpath("LICENSES").glob("**/*"))

for license_file in license_files:
if not license_file.is_file():
logger.debug(f"Skipping: {license_file.as_posix()}")
for legal_file in self._get_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 21b0033

Please sign in to comment.