-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix global licensing being ignored with a .license file
Fixes #1057
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,3 +151,4 @@ Contributors | |
- Сергій <[email protected]> | ||
- Mersho <[email protected]> | ||
- Skyler Grey <[email protected]> | ||
- Linnea Gräf <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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. | ||
|