Skip to content

Commit

Permalink
change --copyright-style to --copyright-prefix fsfe#973
Browse files Browse the repository at this point in the history
  • Loading branch information
kbroch-rivosinc authored and carmenbianca committed Jul 1, 2024
1 parent 33c331b commit f2ad23f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CLI command and its behaviour. There are no guarantees of stability for the
- Perl test (`.t`) (#997)
- BATS test (`.bats`) (#997)
- Support alternate spelling `--skip-unrecognized` (#974)
- Change `--copyright-style` to `--copyright-prefix` (still supporting former) (#973)

### Changed

Expand Down
6 changes: 3 additions & 3 deletions docs/man/reuse-annotate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ information which the tool will add to the file(s).
.. option:: -c, --copyright COPYRIGHT

A copyright holder. This does not contain the year or the copyright prefix.
See :option:`--year` and :option:`--copyright-style` for the year and prefix.
See :option:`--year` and :option:`--copyright-prefix` for the year and prefix.
This option can be repeated.

.. option:: -l, --license LICENSE
Expand All @@ -77,10 +77,10 @@ Other options
files. This is useful when a file extension is not recognised, or when a file
extension is associated with a comment style that you disagree with.

.. option:: --copyright-style STYLE
.. option:: --copyright-prefix PREFIX

The prefix to use in the copyright statement. If not defined, ``spdx`` is used
as prefix. The available copyright styles are:
as prefix. The available copyright prefixes are:

.. code-block::
Expand Down
18 changes: 12 additions & 6 deletions src/reuse/_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from . import ReuseInfo
from ._util import (
_COPYRIGHT_STYLES,
_COPYRIGHT_PREFIXES,
PathType,
StrPath,
_determine_license_path,
Expand Down Expand Up @@ -305,13 +305,13 @@ def get_reuse_info(args: Namespace, year: Optional[str]) -> ReuseInfo:
--contributor.
"""
expressions = set(args.license) if args.license is not None else set()
copyright_style = (
args.copyright_style if args.copyright_style is not None else "spdx"
copyright_prefix = (
args.copyright_prefix if args.copyright_prefix is not None else "spdx"
)
copyright_lines = (
{
make_copyright_line(
item, year=year, copyright_style=copyright_style
item, year=year, copyright_prefix=copyright_prefix
)
for item in args.copyright
}
Expand Down Expand Up @@ -410,11 +410,17 @@ def add_arguments(parser: ArgumentParser) -> None:
choices=list(NAME_STYLE_MAP),
help=_("comment style to use, optional"),
)
parser.add_argument(
"--copyright-prefix",
action="store",
choices=list(_COPYRIGHT_PREFIXES.keys()),
help=_("copyright prefix to use, optional"),
)
parser.add_argument(
"--copyright-style",
action="store",
choices=list(_COPYRIGHT_STYLES.keys()),
help=_("copyright style to use, optional"),
dest="copyright_prefix",
help=SUPPRESS,
)
parser.add_argument(
"--template",
Expand Down
11 changes: 6 additions & 5 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX-FileCopyrightText: 2022 Pietro Albini <pietro.albini@ferrous-systems.com>
# SPDX-FileCopyrightText: 2023 DB Systel GmbH
# SPDX-FileCopyrightText: 2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
# SPDX-FileCopyrightText: 2024 Rivos Inc.
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
Expand Down Expand Up @@ -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: ©",
Expand Down Expand Up @@ -324,7 +325,7 @@ def merge_copyright_lines(copyright_lines: Set[str]) -> Set[str]:
][0]
)
style = "spdx"
for key, value in _COPYRIGHT_STYLES.items():
for key, value in _COPYRIGHT_PREFIXES.items():
if prefix == value:
style = key
break
Expand Down Expand Up @@ -492,18 +493,18 @@ 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)
copyright_prefix = _COPYRIGHT_PREFIXES.get(copyright_prefix)
if copyright_prefix is None:
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'"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main_annotate_merge.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2021 Liam Beguin <liambeguin@gmail.com>
# 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
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 12 additions & 11 deletions tests/test_util.py
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 <nico.rikken@fsfe.org>
# SPDX-FileCopyrightText: 2022 Florian Snow <florian@familysnow.net>
# SPDX-FileCopyrightText: 2022 Carmen Bianca Bakker <carmenbianca@fsfe.org>
# SPDX-FileCopyrightText: 2022 Florian Snow <florian@familysnow.net>
# SPDX-FileCopyrightText: 2022 Nico Rikken <nico.rikken@fsfe.org>
# SPDX-FileCopyrightText: 2022 Pietro Albini <pietro.albini@ferrous-systems.com>
# SPDX-FileCopyrightText: 2024 Rivos Inc.
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -383,62 +384,62 @@ 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")
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."""
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."""
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."""
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."""
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."""
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."""
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."""
statement = _util.make_copyright_line(
"hello", year=2019, copyright_style="symbol"
"hello", year=2019, copyright_prefix="symbol"
)
assert statement == "© 2019 hello"

Expand Down

0 comments on commit f2ad23f

Please sign in to comment.