Skip to content

Commit

Permalink
Merge pull request #1058 from nea89o/fix/dotlicensewithgloballicensin…
Browse files Browse the repository at this point in the history
…ginfo

Fix global licensing being ignored with a .license file
  • Loading branch information
carmenbianca authored Oct 24, 2024
2 parents 327bc92 + 985bfba commit da35d79
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ Contributors
- Mersho <[email protected]>
- Skyler Grey <[email protected]>
- Emil Velikov <[email protected]>
- Linnea Gräf <[email protected]>
2 changes: 2 additions & 0 deletions changelog.d/fixed/license-overriding-global-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `REUSE.toml` `[[annotations]]` now use the correct path if a `.license` file
is present (#1058)
3 changes: 2 additions & 1 deletion src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-FileCopyrightText: 2023 Matthias Riße
# SPDX-FileCopyrightText: 2023 DB Systel GmbH
# SPDX-FileCopyrightText: 2024 Kerry McAdams <github@klmcadams>
# SPDX-FileCopyrightText: 2024 Linnea Gräf
#
# SPDX-License-Identifier: GPL-3.0-or-later

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

# Search the global licensing file for REUSE information.
if self.global_licensing:
relpath = self.relative_from_root(path)
relpath = self.relative_from_root(original_path)
global_results = defaultdict(
list, self.global_licensing.reuse_info_of(relpath)
)
Expand Down
86 changes: 86 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2023 Carmen Bianca BAKKER <[email protected]>
# SPDX-FileCopyrightText: 2024 Skyler Grey <[email protected]>
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
# SPDX-FileCopyrightText: 2024 Linnea Gräf
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -456,6 +457,91 @@ def test_reuse_info_of_copyright_xor_licensing(empty_directory):
assert not bar_file_info.spdx_expressions


def test_reuse_info_of_reuse_toml_dot_license(empty_directory):
"""Test a corner case where there is REUSE information inside of a file, its
.license file, and REUSE.toml. Only the REUSE information from the .license
file and REUSE.toml should be applied to this file.
"""
(empty_directory / "REUSE.toml").write_text(
cleandoc(
"""
version = 1
[[annotations]]
path = "*.py"
precedence = "aggregate"
SPDX-FileCopyrightText = "2017 Jane Doe"
SPDX-License-Identifier = "CC0-1.0"
"""
)
)
(empty_directory / "foo.py").write_text(
cleandoc(
"""
SPDX-FileCopyrightText: NONE
"""
)
)
(empty_directory / "foo.py.license").write_text(
cleandoc(
"""
SPDX-FileCopyrightText: 2017 John Doe
"""
)
)
project = Project.from_directory(empty_directory)

infos = project.reuse_info_of("foo.py")
assert len(infos) == 2
toml_info = [info for info in infos if info.spdx_expressions][0]
assert toml_info.source_type == SourceType.REUSE_TOML
assert "2017 Jane Doe" in toml_info.copyright_lines
assert "CC0-1.0" in str(toml_info.spdx_expressions)
dot_license_info = [info for info in infos if not info.spdx_expressions][0]
assert dot_license_info.source_type == SourceType.DOT_LICENSE
assert (
"SPDX-FileCopyrightText: 2017 John Doe"
in dot_license_info.copyright_lines
)
assert not dot_license_info.spdx_expressions


def test_reuse_info_of_dot_license_invalid_target(empty_directory):
"""file.license is an invalid target in REUSE.toml."""
(empty_directory / "REUSE.toml").write_text(
cleandoc(
"""
version = 1
[[annotations]]
path = "foo.py.license"
SPDX-FileCopyrightText = "2017 Jane Doe"
SPDX-License-Identifier = "CC0-1.0"
"""
)
)
(empty_directory / "foo.py").write_text(
cleandoc(
"""
SPDX-FileCopyrightText: 2017 John Doe
SPDX-License-Identifier: MIT
"""
)
)
(empty_directory / "foo.py.license").write_text(
cleandoc(
"""
Empty
"""
)
)
project = Project.from_directory(empty_directory)

infos = project.reuse_info_of("foo.py")
assert len(infos) == 0


def test_reuse_info_of_no_duplicates(empty_directory):
"""A file contains the same lines twice. The ReuseInfo only contains those
lines once.
Expand Down

0 comments on commit da35d79

Please sign in to comment.