Skip to content

Commit 21b0033

Browse files
authored
Rework the list of files included in build artifacts (#666)
1 parent 842033f commit 21b0033

File tree

8 files changed

+26
-14
lines changed

8 files changed

+26
-14
lines changed

src/poetry/core/masonry/builders/builder.py

+10
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,16 @@ def convert_author(cls, author: str) -> dict[str, str]:
379379

380380
return {"name": name, "email": email}
381381

382+
def _get_legal_files(self) -> set[Path]:
383+
include_files_patterns = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"}
384+
files: set[Path] = set()
385+
386+
for pattern in include_files_patterns:
387+
files.update(self._path.glob(pattern))
388+
389+
files.update(self._path.joinpath("LICENSES").glob("**/*"))
390+
return files
391+
382392

383393
class BuildIncludeFile:
384394
def __init__(

src/poetry/core/masonry/builders/sdist.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,11 @@ def find_nearest_pkg(rel_path: str) -> tuple[str, str]:
320320
def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile]:
321321
to_add = super().find_files_to_add(exclude_build)
322322

323-
# add any additional files, starting with all LICENSE files
324-
additional_files: set[Path] = set(self._path.glob("LICENSE*"))
323+
# add any additional files
324+
additional_files: set[Path] = set()
325+
326+
# add legal files
327+
additional_files.update(self._get_legal_files())
325328

326329
# add script files
327330
additional_files.update(self.convert_script_files())

src/poetry/core/masonry/builders/wheel.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,14 @@ def prepare_metadata(self, metadata_directory: Path) -> Path:
288288
with (dist_info / "METADATA").open("w", encoding="utf-8", newline="\n") as f:
289289
self._write_metadata_file(f)
290290

291-
license_files = set()
292-
for base in ("COPYING", "LICENSE"):
293-
license_files.add(self._path / base)
294-
license_files.update(self._path.glob(base + ".*"))
295-
296-
license_files.update(self._path.joinpath("LICENSES").glob("**/*"))
297-
298-
for license_file in license_files:
299-
if not license_file.is_file():
300-
logger.debug(f"Skipping: {license_file.as_posix()}")
291+
for legal_file in self._get_legal_files():
292+
if not legal_file.is_file():
293+
logger.debug(f"Skipping: {legal_file.as_posix()}")
301294
continue
302295

303-
dest = dist_info / license_file.relative_to(self._path)
296+
dest = dist_info / legal_file.relative_to(self._path)
304297
dest.parent.mkdir(parents=True, exist_ok=True)
305-
shutil.copy(license_file, dest)
298+
shutil.copy(legal_file, dest)
306299

307300
return dist_info
308301

tests/masonry/builders/fixtures/complete/AUTHORS

Whitespace-only changes.

tests/masonry/builders/fixtures/complete/COPYING

Whitespace-only changes.

tests/masonry/builders/fixtures/complete/LICENCE

Whitespace-only changes.

tests/masonry/builders/test_complete.py

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def test_complete(no_vcs: bool) -> None:
133133
"my_package-1.2.3.dist-info/LICENSE",
134134
"my_package-1.2.3.dist-info/METADATA",
135135
"my_package-1.2.3.dist-info/WHEEL",
136+
"my_package-1.2.3.dist-info/COPYING",
137+
"my_package-1.2.3.dist-info/LICENCE",
138+
"my_package-1.2.3.dist-info/AUTHORS",
136139
],
137140
key=lambda x: Path(x),
138141
),

tests/masonry/builders/test_sdist.py

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def test_find_files_to_add() -> None:
178178
result = {f.relative_to_source_root() for f in builder.find_files_to_add()}
179179

180180
assert result == {
181+
Path("AUTHORS"),
182+
Path("COPYING"),
183+
Path("LICENCE"),
181184
Path("LICENSE"),
182185
Path("README.rst"),
183186
Path("bin/script.sh"),

0 commit comments

Comments
 (0)