Skip to content

Commit da35d79

Browse files
authored
Merge pull request #1058 from nea89o/fix/dotlicensewithgloballicensinginfo
Fix global licensing being ignored with a .license file
2 parents 327bc92 + 985bfba commit da35d79

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ Contributors
143143
144144
- Skyler Grey <[email protected]>
145145
- Emil Velikov <[email protected]>
146+
- Linnea Gräf <[email protected]>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `REUSE.toml` `[[annotations]]` now use the correct path if a `.license` file
2+
is present (#1058)

src/reuse/project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-FileCopyrightText: 2023 Matthias Riße
55
# SPDX-FileCopyrightText: 2023 DB Systel GmbH
66
# SPDX-FileCopyrightText: 2024 Kerry McAdams <github@klmcadams>
7+
# SPDX-FileCopyrightText: 2024 Linnea Gräf
78
#
89
# SPDX-License-Identifier: GPL-3.0-or-later
910

@@ -243,7 +244,7 @@ def reuse_info_of(self, path: StrPath) -> list[ReuseInfo]:
243244

244245
# Search the global licensing file for REUSE information.
245246
if self.global_licensing:
246-
relpath = self.relative_from_root(path)
247+
relpath = self.relative_from_root(original_path)
247248
global_results = defaultdict(
248249
list, self.global_licensing.reuse_info_of(relpath)
249250
)

tests/test_project.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-FileCopyrightText: 2023 Carmen Bianca BAKKER <[email protected]>
44
# SPDX-FileCopyrightText: 2024 Skyler Grey <[email protected]>
55
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
6+
# SPDX-FileCopyrightText: 2024 Linnea Gräf
67
#
78
# SPDX-License-Identifier: GPL-3.0-or-later
89

@@ -456,6 +457,91 @@ def test_reuse_info_of_copyright_xor_licensing(empty_directory):
456457
assert not bar_file_info.spdx_expressions
457458

458459

460+
def test_reuse_info_of_reuse_toml_dot_license(empty_directory):
461+
"""Test a corner case where there is REUSE information inside of a file, its
462+
.license file, and REUSE.toml. Only the REUSE information from the .license
463+
file and REUSE.toml should be applied to this file.
464+
"""
465+
(empty_directory / "REUSE.toml").write_text(
466+
cleandoc(
467+
"""
468+
version = 1
469+
470+
[[annotations]]
471+
path = "*.py"
472+
precedence = "aggregate"
473+
SPDX-FileCopyrightText = "2017 Jane Doe"
474+
SPDX-License-Identifier = "CC0-1.0"
475+
"""
476+
)
477+
)
478+
(empty_directory / "foo.py").write_text(
479+
cleandoc(
480+
"""
481+
SPDX-FileCopyrightText: NONE
482+
"""
483+
)
484+
)
485+
(empty_directory / "foo.py.license").write_text(
486+
cleandoc(
487+
"""
488+
SPDX-FileCopyrightText: 2017 John Doe
489+
"""
490+
)
491+
)
492+
project = Project.from_directory(empty_directory)
493+
494+
infos = project.reuse_info_of("foo.py")
495+
assert len(infos) == 2
496+
toml_info = [info for info in infos if info.spdx_expressions][0]
497+
assert toml_info.source_type == SourceType.REUSE_TOML
498+
assert "2017 Jane Doe" in toml_info.copyright_lines
499+
assert "CC0-1.0" in str(toml_info.spdx_expressions)
500+
dot_license_info = [info for info in infos if not info.spdx_expressions][0]
501+
assert dot_license_info.source_type == SourceType.DOT_LICENSE
502+
assert (
503+
"SPDX-FileCopyrightText: 2017 John Doe"
504+
in dot_license_info.copyright_lines
505+
)
506+
assert not dot_license_info.spdx_expressions
507+
508+
509+
def test_reuse_info_of_dot_license_invalid_target(empty_directory):
510+
"""file.license is an invalid target in REUSE.toml."""
511+
(empty_directory / "REUSE.toml").write_text(
512+
cleandoc(
513+
"""
514+
version = 1
515+
516+
[[annotations]]
517+
path = "foo.py.license"
518+
SPDX-FileCopyrightText = "2017 Jane Doe"
519+
SPDX-License-Identifier = "CC0-1.0"
520+
"""
521+
)
522+
)
523+
(empty_directory / "foo.py").write_text(
524+
cleandoc(
525+
"""
526+
SPDX-FileCopyrightText: 2017 John Doe
527+
528+
SPDX-License-Identifier: MIT
529+
"""
530+
)
531+
)
532+
(empty_directory / "foo.py.license").write_text(
533+
cleandoc(
534+
"""
535+
Empty
536+
"""
537+
)
538+
)
539+
project = Project.from_directory(empty_directory)
540+
541+
infos = project.reuse_info_of("foo.py")
542+
assert len(infos) == 0
543+
544+
459545
def test_reuse_info_of_no_duplicates(empty_directory):
460546
"""A file contains the same lines twice. The ReuseInfo only contains those
461547
lines once.

0 commit comments

Comments
 (0)