Skip to content

Commit

Permalink
Fix global licensing being ignored with a .license file
Browse files Browse the repository at this point in the history
Fixes #1057
  • Loading branch information
nea89o committed Aug 7, 2024
1 parent 37f342d commit 3cd76de
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ Contributors
- Сергій <[email protected]>
- Mersho <[email protected]>
- Skyler Grey <[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 @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2023 Carmen Bianca BAKKER <[email protected]>
# SPDX-FileCopyrightText: 2023 Matthias Riße
# SPDX-FileCopyrightText: 2023 DB Systel GmbH
# SPDX-FileCopyrightText: 2024 Linnea Gräf
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -251,7 +252,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
75 changes: 75 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 @@ -647,6 +648,80 @@ def test_reuse_info_of_copyright_xor_licensing(empty_directory):
assert not bar_file_info.spdx_expressions


def test_reuse_info_of_copyright_xor_licensing_with_license_dot(
empty_directory,
):
"""Test a corner case where partial REUSE information is defined inside of a
.license file (copyright xor licensing). Get the missing information from the
REUSE.toml.
"""
(empty_directory / "REUSE.toml").write_text(
cleandoc(
"""
version = 1
[[annotations]]
path = "*.py"
SPDX-FileCopyrightText = "2017 Jane Doe"
SPDX-License-Identifier = "CC0-1.0"
[[annotations]]
path = "*.py.license"
SPDX-FileCopyrightText = "2017 Jane Doe"
SPDX-License-Identifier = "MIT"
"""
)
)
(empty_directory / "foo.py").write_text(
cleandoc(
"""
print("This is very strictly copyrighted code")
"""
)
)
(empty_directory / "foo.py.license").write_text(
cleandoc(
"""
SPDX-FileCopyrightText: 2017 John Doe
"""
)
)
(empty_directory / "bar.py").write_text(
cleandoc(
"""
print("This is other very strictly copyrighted code")
"""
)
)
(empty_directory / "bar.py.license").write_text(
cleandoc(
"""
SPDX-License-Identifier: 0BSD
"""
)
)
project = Project.from_directory(empty_directory)

foo_infos = project.reuse_info_of("foo.py")
assert len(foo_infos) == 2
foo_toml_info = [info for info in foo_infos if info.spdx_expressions][0]
assert foo_toml_info.source_type == SourceType.REUSE_TOML
assert not foo_toml_info.copyright_lines
assert "MIT" not in str(foo_toml_info.spdx_expressions)
foo_file_info = [info for info in foo_infos if info.copyright_lines][0]
assert foo_file_info.source_type == SourceType.DOT_LICENSE
assert not foo_file_info.spdx_expressions

bar_infos = project.reuse_info_of("bar.py")
assert len(bar_infos) == 2
bar_toml_info = [info for info in bar_infos if info.copyright_lines][0]
assert bar_toml_info.source_type == SourceType.REUSE_TOML
assert not bar_toml_info.spdx_expressions
bar_file_info = [info for info in bar_infos if info.spdx_expressions][0]
assert bar_file_info.source_type == SourceType.DOT_LICENSE
assert not bar_file_info.copyright_lines


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 3cd76de

Please sign in to comment.