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 1fba09b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
14 changes: 9 additions & 5 deletions 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_globs = {"COPYING*", "LICEN[SC]E*", "AUTHORS*", "NOTICE*"}

for file in include_files_globs:
additional_files.update(self._path.glob(file))

# add script files
additional_files.update(self.convert_script_files())
Expand All @@ -338,12 +342,12 @@ def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile
additional_files.update(Path(r) for r in readme)

for additional_file in additional_files:
file = BuildIncludeFile(
include_file = BuildIncludeFile(
path=additional_file, project_root=self._path, source_root=self._path
)
if file.path.exists():
logger.debug(f"Adding: {file.relative_to_source_root()}")
to_add.add(file)
if include_file.path.exists():
logger.debug(f"Adding: {include_file.relative_to_source_root()}")
to_add.add(include_file)

return to_add

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 1fba09b

Please sign in to comment.