Skip to content

Commit

Permalink
Merge pull request #778 from carmenbianca/remove-precedence
Browse files Browse the repository at this point in the history
Revert the mandatory order of precedence; display PendingDeprecationWarning
  • Loading branch information
linozen authored Jun 22, 2023
2 parents 899d200 + b37054d commit 6b81d04
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 63 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ CLI command and its behaviour. There are no guarantees of stability for the
- Added `--json` flag to `lint` command (#654).
- `reuse.ReuseInfo` now has `copy` and `union` methods. (#759)
- Added Ukrainian and Czech translations (#767)
- Added `--suppress-deprecation` to hide (verbose) deprecation warnings. (#778)

### Changed

Expand All @@ -86,12 +87,17 @@ CLI command and its behaviour. There are no guarantees of stability for the
version of reuse. (#724)
- Bumped SPDX license list to v3.21. (#763)
- Bumped REUSE Spec version to 3.1. (#768)
- Introduce an order of precedence. The copyright and licensing information from
different sources (e.g. `.license` or `.reuse/dep5` file) is no longer merged.
(#654)

### Deprecated

- Pending deprecation of aggregation of file sources. Presently, when copyright
and licensing information is defined both within e.g. the file itself and in
the DEP5 file, then the information is merged or aggregated for the purposes
of linting and BOM generation. In the future, this will no longer be the case
unless explicitly defined. The exact mechanism for this is not yet concrete,
but a `PendingDeprecationWarning` will be shown to the user to make them aware
of this. (#778)

### Removed

- Python 3.6 and 3.7 support has been dropped. (#673, #759)
Expand Down
9 changes: 9 additions & 0 deletions src/reuse/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import argparse
import logging
import sys
import warnings
from gettext import gettext as _
from typing import IO, Callable, List, Optional, Type, cast

Expand Down Expand Up @@ -68,6 +69,11 @@ def parser() -> argparse.ArgumentParser:
parser.add_argument(
"--debug", action="store_true", help=_("enable debug statements")
)
parser.add_argument(
"--suppress-deprecation",
action="store_true",
help=_("hide deprecation warnings"),
)
parser.add_argument(
"--include-submodules",
action="store_true",
Expand Down Expand Up @@ -271,6 +277,9 @@ def main(args: Optional[List[str]] = None, out: IO[str] = sys.stdout) -> int:
parsed_args = main_parser.parse_args(args)

setup_logging(level=logging.DEBUG if parsed_args.debug else logging.WARNING)
# Show all warnings raised by ourselves.
if not parsed_args.suppress_deprecation:
warnings.filterwarnings("default", module="reuse")

if parsed_args.version:
out.write(f"reuse {__version__}\n")
Expand Down
32 changes: 22 additions & 10 deletions src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import glob
import logging
import os
import warnings
from gettext import gettext as _
from pathlib import Path
from typing import Dict, Iterator, Optional, Union, cast
Expand Down Expand Up @@ -168,6 +169,7 @@ def reuse_info_of(self, path: StrPath) -> ReuseInfo:
# is captured in ReuseInfo
dep5_result = ReuseInfo()
file_result = ReuseInfo()
final_result = ReuseInfo()

# Search the .reuse/dep5 file for REUSE information.
if self._copyright:
Expand Down Expand Up @@ -217,26 +219,36 @@ def reuse_info_of(self, path: StrPath) -> ReuseInfo:
dep5_result.contains_copyright_or_licensing()
and file_result.contains_copyright_or_licensing()
):
_LOGGER.warning(
final_result = file_result.union(dep5_result)
warnings.warn(
_(
"Copyright and licensing information for '{original_path}'"
" have been found in '{path}' and the DEP5 file located at"
" '{dep5_path}'. The information in the DEP5 file has been"
" overridden. Please ensure that this is correct."
"Copyright and licensing information for"
" '{original_path}' has been found in both '{path}' and"
" in the DEP5 file located at '{dep5_path}'. The"
" information for these two sources has been"
" aggregated. In the future this behaviour will change,"
" and you will need to explicitly enable aggregation."
" See"
" <https://github.com/fsfe/reuse-tool/issues/779>. You"
" need do nothing yet. Run with"
" `--suppress-deprecation` to hide this warning."
).format(
original_path=original_path, path=path, dep5_path=dep5_path
)
),
PendingDeprecationWarning,
)
# Information is only found in a DEP5 file
elif (
dep5_result.contains_copyright_or_licensing()
and not file_result.contains_copyright_or_licensing()
):
return dep5_result.copy(source_path=source_path)
final_result = dep5_result.copy(source_path=source_path)
# There is a file header or a .license file
return file_result.copy(
source_path=source_path, source_type=source_type
)
else:
final_result = file_result.copy(
source_path=source_path, source_type=source_type
)
return final_result

def relative_from_root(self, path: StrPath) -> Path:
"""If the project root is /tmp/project, and *path* is
Expand Down
29 changes: 0 additions & 29 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,33 +191,4 @@ def test_lint_json_output(fake_repository):
)


def test_lint_json_output_precedence(fake_repository):
"""Test for lint with JSON output with focus on precedence."""
(fake_repository / "doc/differently_licensed_docs.rst").write_text(
"SPDX-License-Identifier: MIT"
)
project = Project(fake_repository)
report = ProjectReport.generate(project)

json_result = report.to_dict_lint()

assert json_result
# Test result
assert json_result["summary"]["compliant"] is False
# Test license path precedence
for test_file in json_result["files"]:
if test_file["path"].startswith(
str(fake_repository / "doc/differently_licensed_docs.rst")
):
assert test_file["licenses"][0]["value"] == "MIT"
assert test_file["licenses"][0]["source"] == str(
fake_repository / "doc/differently_licensed_docs.rst"
)
if test_file["path"].startswith(str(fake_repository / "doc/index.rst")):
assert test_file["licenses"][0]["value"] == "CC0-1.0"
assert test_file["licenses"][0]["source"] == str(
fake_repository / ".reuse/dep5"
)


# REUSE-IgnoreEnd
35 changes: 14 additions & 21 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import shutil
import warnings
from importlib import import_module
from inspect import cleandoc
from pathlib import Path
Expand Down Expand Up @@ -246,24 +247,10 @@ def test_reuse_info_of_only_copyright(fake_repository):
)


def test_reuse_info_of_only_copyright_also_covered_by_debian(fake_repository):
"""A file contains only a copyright line, but debian/copyright also has
information on this file. Use only the information from file header.
"""
(fake_repository / "doc/foo.py").write_text(
"SPDX-FileCopyrightText: in file"
)
project = Project(fake_repository)
reuse_info = project.reuse_info_of("doc/foo.py")

assert len(reuse_info.copyright_lines) == 1
assert "SPDX-FileCopyrightText: in file" in reuse_info.copyright_lines


def test_reuse_info_of_also_covered_by_dep5(fake_repository):
"""A file contains all REUSE information, but .reuse/dep5 also
provides information on this file. Use only the information
from the file header.
provides information on this file. Aggregate the information (for now), and
expect a PendingDeprecationWarning.
"""
(fake_repository / "doc/foo.py").write_text(
dedent(
Expand All @@ -273,11 +260,17 @@ def test_reuse_info_of_also_covered_by_dep5(fake_repository):
)
)
project = Project(fake_repository)
reuse_info = project.reuse_info_of("doc/foo.py")
assert LicenseSymbol("MIT") in reuse_info.spdx_expressions
assert LicenseSymbol("CC0-1.0") not in reuse_info.spdx_expressions
assert "SPDX-FileCopyrightText: in file" in reuse_info.copyright_lines
assert "2017 Jane Doe" not in reuse_info.copyright_lines
with warnings.catch_warnings(record=True) as caught_warnings:
reuse_info = project.reuse_info_of("doc/foo.py")
assert LicenseSymbol("MIT") in reuse_info.spdx_expressions
assert LicenseSymbol("CC0-1.0") in reuse_info.spdx_expressions
assert "SPDX-FileCopyrightText: in file" in reuse_info.copyright_lines
assert "2017 Jane Doe" in reuse_info.copyright_lines

assert len(caught_warnings) == 1
assert issubclass(
caught_warnings[0].category, PendingDeprecationWarning
)


def test_reuse_info_of_no_duplicates(empty_directory):
Expand Down

0 comments on commit 6b81d04

Please sign in to comment.