forked from fsfe/reuse-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fsfe#1016 from kbroch-rivosinc/dev/kbroch/copyrigh…
…t-style-to-copyright-prefix change --copyright-style to --copyright-prefix fsfe#973
- Loading branch information
Showing
7 changed files
with
103 additions
and
53 deletions.
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
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
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
# SPDX-FileCopyrightText: 2022 Pietro Albini <[email protected]> | ||
# SPDX-FileCopyrightText: 2023 DB Systel GmbH | ||
# SPDX-FileCopyrightText: 2023 Johannes Zarl-Zierl <[email protected]> | ||
# SPDX-FileCopyrightText: 2024 Rivos Inc. | ||
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
@@ -128,7 +129,7 @@ | |
r"(?P<statement>.*?))" + _END_PATTERN | ||
), | ||
] | ||
_COPYRIGHT_STYLES = { | ||
_COPYRIGHT_PREFIXES = { | ||
"spdx": "SPDX-FileCopyrightText:", | ||
"spdx-c": "SPDX-FileCopyrightText: (C)", | ||
"spdx-symbol": "SPDX-FileCopyrightText: ©", | ||
|
@@ -317,16 +318,16 @@ def merge_copyright_lines(copyright_lines: Set[str]) -> Set[str]: | |
item for item in copyright_in if item["statement"] == statement | ||
] | ||
|
||
# Get the style of the most common prefix | ||
prefix = str( | ||
# Get the most common prefix. | ||
most_common = str( | ||
Counter([item["prefix"] for item in copyright_list]).most_common(1)[ | ||
0 | ||
][0] | ||
) | ||
style = "spdx" | ||
for key, value in _COPYRIGHT_STYLES.items(): | ||
if prefix == value: | ||
style = key | ||
prefix = "spdx" | ||
for key, value in _COPYRIGHT_PREFIXES.items(): | ||
if most_common == value: | ||
prefix = key | ||
break | ||
|
||
# get year range if any | ||
|
@@ -341,7 +342,7 @@ def merge_copyright_lines(copyright_lines: Set[str]) -> Set[str]: | |
else: | ||
year = f"{min(years)} - {max(years)}" | ||
|
||
copyright_out.add(make_copyright_line(statement, year, style)) | ||
copyright_out.add(make_copyright_line(statement, year, prefix)) | ||
return copyright_out | ||
|
||
|
||
|
@@ -492,18 +493,19 @@ def contains_reuse_info(text: str) -> bool: | |
|
||
|
||
def make_copyright_line( | ||
statement: str, year: Optional[str] = None, copyright_style: str = "spdx" | ||
statement: str, year: Optional[str] = None, copyright_prefix: str = "spdx" | ||
) -> str: | ||
"""Given a statement, prefix it with ``SPDX-FileCopyrightText:`` if it is | ||
not already prefixed with some manner of copyright tag. | ||
""" | ||
if "\n" in statement: | ||
raise RuntimeError(f"Unexpected newline in '{statement}'") | ||
|
||
copyright_prefix = _COPYRIGHT_STYLES.get(copyright_style) | ||
if copyright_prefix is None: | ||
prefix = _COPYRIGHT_PREFIXES.get(copyright_prefix) | ||
if prefix is None: | ||
# TODO: Maybe translate this. Also maybe reduce DRY here. | ||
raise RuntimeError( | ||
"Unexpected copyright style: Need 'spdx', 'spdx-c', " | ||
"Unexpected copyright prefix: Need 'spdx', 'spdx-c', " | ||
"'spdx-symbol', 'string', 'string-c', " | ||
"'string-symbol', or 'symbol'" | ||
) | ||
|
@@ -513,8 +515,8 @@ def make_copyright_line( | |
if match is not None: | ||
return statement | ||
if year is not None: | ||
return f"{copyright_prefix} {year} {statement}" | ||
return f"{copyright_prefix} {statement}" | ||
return f"{prefix} {year} {statement}" | ||
return f"{prefix} {statement}" | ||
|
||
|
||
def _checksum(path: StrPath) -> str: | ||
|
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# SPDX-FileCopyrightText: 2021 Liam Beguin <[email protected]> | ||
# SPDX-FileCopyrightText: 2024 Rivos Inc. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
"""Tests for reuse._main: annotate merge-copyrights option""" | ||
|
||
|
||
from inspect import cleandoc | ||
|
||
from reuse._main import main | ||
|
@@ -102,7 +102,7 @@ def test_annotate_merge_copyrights_multi_prefix(fake_repository, stringio): | |
str(2015 + i), | ||
"--license", | ||
"GPL-3.0-or-later", | ||
"--copyright-style", | ||
"--copyright-prefix", | ||
"string-c", | ||
"--copyright", | ||
"Mary Sue", | ||
|
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# SPDX-FileCopyrightText: 2017 Free Software Foundation Europe e.V. <https://fsfe.org> | ||
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
# SPDX-FileCopyrightText: 2022 Nico Rikken <[email protected]> | ||
# SPDX-FileCopyrightText: 2022 Florian Snow <[email protected]> | ||
# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <[email protected]> | ||
# SPDX-FileCopyrightText: 2022 Florian Snow <[email protected]> | ||
# SPDX-FileCopyrightText: 2022 Nico Rikken <[email protected]> | ||
# SPDX-FileCopyrightText: 2022 Pietro Albini <[email protected]> | ||
# SPDX-FileCopyrightText: 2024 Rivos Inc. | ||
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
|
@@ -381,64 +382,64 @@ def test_make_copyright_line_year(): | |
) | ||
|
||
|
||
def test_make_copyright_line_style_spdx(): | ||
"""Given a simple statement and style, make it a copyright line.""" | ||
statement = _util.make_copyright_line("hello", copyright_style="spdx") | ||
def test_make_copyright_line_prefix_spdx(): | ||
"""Given a simple statement and prefix, make it a copyright line.""" | ||
statement = _util.make_copyright_line("hello", copyright_prefix="spdx") | ||
assert statement == "SPDX-FileCopyrightText: hello" | ||
|
||
|
||
def test_make_copyright_line_style_spdx_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_spdx_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="spdx" | ||
"hello", year=2019, copyright_prefix="spdx" | ||
) | ||
assert statement == "SPDX-FileCopyrightText: 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_spdx_c_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_spdx_c_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="spdx-c" | ||
"hello", year=2019, copyright_prefix="spdx-c" | ||
) | ||
assert statement == "SPDX-FileCopyrightText: (C) 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_spdx_symbol_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_spdx_symbol_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="spdx-symbol" | ||
"hello", year=2019, copyright_prefix="spdx-symbol" | ||
) | ||
assert statement == "SPDX-FileCopyrightText: © 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_string_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_string_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="string" | ||
"hello", year=2019, copyright_prefix="string" | ||
) | ||
assert statement == "Copyright 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_string_c_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_string_c_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="string-c" | ||
"hello", year=2019, copyright_prefix="string-c" | ||
) | ||
assert statement == "Copyright (C) 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_string_symbol_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_string_symbol_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="string-symbol" | ||
"hello", year=2019, copyright_prefix="string-symbol" | ||
) | ||
assert statement == "Copyright © 2019 hello" | ||
|
||
|
||
def test_make_copyright_line_style_symbol_year(): | ||
"""Given a simple statement, style and a year, make it a copyright line.""" | ||
def test_make_copyright_line_prefix_symbol_year(): | ||
"""Given a simple statement, prefix and a year, make it a copyright line.""" | ||
statement = _util.make_copyright_line( | ||
"hello", year=2019, copyright_style="symbol" | ||
"hello", year=2019, copyright_prefix="symbol" | ||
) | ||
assert statement == "© 2019 hello" | ||
|
||
|