Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no strict dep5 parsing #805

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def _copyright(self) -> Optional[Copyright]:
copyright_path = self.root / ".reuse/dep5"
try:
with copyright_path.open(encoding="utf-8") as fp:
self._copyright_val = Copyright(fp)
self._copyright_val = Copyright(fp, strict=False)
except OSError:
_LOGGER.debug("no .reuse/dep5 file, or could not read it")
except DebianError:
Expand Down
4 changes: 2 additions & 2 deletions src/reuse/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Set, cast
from uuid import uuid4

from . import __REUSE_version__, __version__
from . import ReuseInfo, __REUSE_version__, __version__
from ._util import _LICENSING, StrPath, _checksum
from .project import Project, ReuseInfo
from .project import Project

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def dep5_copyright():
with (RESOURCES_DIRECTORY / "fake_repository/.reuse/dep5").open(
encoding="utf-8"
) as fp:
return Copyright(fp)
return Copyright(fp, strict=False)


@pytest.fixture()
Expand Down
87 changes: 87 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest

from reuse import SourceType
from reuse._util import _LICENSING
from reuse.project import Project
from reuse.report import FileReport, ProjectReport

Expand Down Expand Up @@ -267,6 +268,92 @@ def test_generate_file_report_to_dict_lint_source_information(fake_repository):
assert expression["value"] == "MIT OR 0BSD"


def test_strict_dep5_in_file_report(fake_repository):
"""All copyright information of a strictly formatted dep5 file should be
taken into account in the file report. 'Strictly formatted' here means no
syntax errors. Specifically, there shouldn't be any duplicate Copyright
tags/fields.
"""
# pylint: disable=line-too-long
(fake_repository / ".reuse/dep5").write_text(
dedent(
"""
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Some project
Upstream-Contact: Jane Doe
Source: https://example.com/

Files: doc/*
Copyright: 2017 Jane Doe
2018 John Doe
2019 Joey Doe
License: CC0-1.0
"""
)
)
project = Project(fake_repository)
report = FileReport.generate(
project,
"doc/index.rst",
)
assert len(report.reuse_infos) == 1
reuse_info = report.reuse_infos[0]
assert reuse_info.spdx_expressions == {_LICENSING.parse("CC0-1.0")}
assert reuse_info.copyright_lines == {
"2017 Jane Doe",
"2018 John Doe",
"2019 Joey Doe",
}
assert reuse_info.source_path == ".reuse/dep5"
assert reuse_info.source_type == SourceType.DEP5


def test_dep5_duplicate_copyright_in_file_report(fake_repository):
"""Duplicate 'Copyright:' fields (tags) in a DEP5 file is a syntax error.
Since python-debian 0.1.47, the parser raises an error on this class of
syntax error.

We suppress that error (by parsing the file 'non-strictly'), because this
error is undocumented breaking behaviour.

Towards that end, verify that no error is raised. As a side effect of
parsing non-strictly, only the first Copyright tag is parsed. This is
undesireable, but reflects pre-0.1.47 behaviour.

See also <https://github.com/fsfe/reuse-tool/issues/803>.

TODO: Expect at least a user-facing warning when this happens.
"""
# pylint: disable=line-too-long
(fake_repository / ".reuse/dep5").write_text(
dedent(
"""
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Some project
Upstream-Contact: Jane Doe
Source: https://example.com/

Files: doc/*
Copyright: 2017 Jane Doe
Copyright: 2018 John Doe
Copyright: 2019 Joey Doe
License: CC0-1.0
"""
)
)
project = Project(fake_repository)
report = FileReport.generate(
project,
"doc/index.rst",
)
assert len(report.reuse_infos) == 1
reuse_info = report.reuse_infos[0]
assert reuse_info.spdx_expressions == {_LICENSING.parse("CC0-1.0")}
assert reuse_info.copyright_lines == {"2017 Jane Doe"}
assert reuse_info.source_path == ".reuse/dep5"
assert reuse_info.source_type == SourceType.DEP5


def test_generate_project_report_simple(fake_repository, multiprocessing):
"""Simple generate test, just to see if it sort of works."""
project = Project(fake_repository)
Expand Down
Loading