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

Adding --json to lint #654

Merged
merged 60 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
cb94206
Rework `lint`
linozen Jan 11, 2023
3ae8af7
Add --json` argument
linozen Jan 24, 2023
2e6805e
Slim down data dictionary creation
linozen Jan 24, 2023
5a03e9e
Rework plaintext formatter
linozen Jan 24, 2023
21d0026
Move JSON formatter and re-add `lint` function
linozen Jan 24, 2023
0b473f0
Remove old output generation functions
linozen Jan 24, 2023
74fd00e
Adapt tests
linozen Jan 24, 2023
fb32ead
Add new tests
linozen Jan 24, 2023
ff3d3c3
Satisfy pylint
linozen Jan 24, 2023
cfcac8e
Satisfy isort
linozen Jan 24, 2023
d749d51
Make showing of license (not path) work on Windows
linozen Jan 24, 2023
5dcd872
Satisfy pylint (again)
linozen Jan 24, 2023
e03fb3e
Add changelog entry
linozen Jan 24, 2023
89dbd8b
Fix typo
linozen Jan 24, 2023
034a9af
Move `collect_data_from_report` to `ProjectReport.to_dict`
linozen Feb 15, 2023
6bb2a47
(convenience) Add `--format` to easily switch between plain and JSON …
linozen Feb 15, 2023
6bc172a
Get `__REUSE_version__` from report object
linozen Feb 15, 2023
2a2e44f
Add newline at the end of the output
linozen Feb 15, 2023
5c25198
Update tests according to code changes
linozen Feb 15, 2023
f697c73
Fix minor issues in `report.py`
linozen Apr 5, 2023
f20429f
Fix plaintext output
linozen Apr 5, 2023
1b2bd90
Add custom JSON serializer
linozen Apr 5, 2023
d98d162
Adapt `SpdxInfo` namedtuple to contain source path
linozen Apr 5, 2023
9c106f1
Remove useless line
linozen Apr 5, 2023
9beac70
Actually return license/copyright source path
linozen Apr 5, 2023
c43c91f
Determine license source correctly
linozen Apr 5, 2023
6fc5ec1
Allow returning empty arrays
linozen Apr 5, 2023
3ad1fe3
Satisfy black
linozen Apr 6, 2023
2fcc8eb
Ensure consistency of the JSON output
linozen Apr 6, 2023
d50d15e
Ensure consistency of the plaintext output
linozen Apr 6, 2023
fbf6e53
Move logic to FileReport.to_dict and rename method to to_dict_lint
carmenbianca Apr 10, 2023
bd59465
Create ProjectReport.is_compliant
carmenbianca Apr 10, 2023
8f3b5d0
Rename json_version to lint_version
carmenbianca Apr 10, 2023
8feed9e
Remove superfluous function
carmenbianca Apr 10, 2023
7423f62
Make tests run by importing an existing function
carmenbianca May 11, 2023
f648356
Repair boolean check of SpdxInfo; object not iterable
carmenbianca May 21, 2023
c75a3e3
Correctly use format_plain
carmenbianca May 21, 2023
5bc2c58
fixup! Rename json_version to lint_version
carmenbianca May 21, 2023
54a8a66
fixup! fixup! Rename json_version to lint_version
carmenbianca May 21, 2023
d3208db
Don't pass string where (optional) set is expected
carmenbianca May 21, 2023
8a40fb6
fixup! Don't pass string where (optional) set is expected
carmenbianca May 21, 2023
a769306
fixup! fixup! Don't pass string where (optional) set is expected
carmenbianca May 21, 2023
cc5a383
Create SpdxInfo.contains_copyright_or_licensing
carmenbianca May 21, 2023
23fa4cc
Make lint version a global constant
carmenbianca May 21, 2023
8fa808a
Add tool version to json output
carmenbianca May 21, 2023
c94b5a0
Refactoring precedence for license path
linozen May 25, 2023
7493ed1
Add two `--json` specific test to `tests/test_lint.py`
linozen May 25, 2023
bb3217a
Adapting two tests to new precedence behaviour
linozen May 25, 2023
f2f1ef0
Adding a warning when information is overriden
linozen May 25, 2023
cd820e1
Import `Path` instead of `PosixPath`
linozen May 25, 2023
6c51545
Use `StringIO` object instead of normal string object
linozen May 25, 2023
d1c2146
Make sure that some keys are on top of sorted output
linozen May 25, 2023
c8baa6e
Make `summary_contents` a dictionary
linozen May 25, 2023
983b0c4
Simplify `lint --quiet`
linozen May 26, 2023
d7af2e2
Move dictionary sorting and test it
linozen May 26, 2023
33456cb
Rename `SpdxInfo` to `ReuseInfo`
linozen May 26, 2023
962521f
Rename `ReuseInfo.license_path` to `ReuseInfo.source_path`
linozen May 26, 2023
852b3fb
Also encode `source_type` in `ReuseInfo`
linozen May 26, 2023
322dd8a
Rename `spdx_info_of` to `reuse_info_of`
linozen May 26, 2023
7346234
Add SourceType enum and use it for source_type in ReuseInfo
linozen Jun 1, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CLI command and its behaviour. There are no guarantees of stability for the
SPDX license expression remains the same:
`Apache-2.0 AND CC0-1.0 AND CC-BY-SA-4.0 AND GPL-3.0-or-later`. (#733)
- Added `--contributor` option to `annotate`. (#669)
- Added `--json` flag to `lint` command (#654).

### Changed

Expand Down
7 changes: 6 additions & 1 deletion src/reuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os
import re
from dataclasses import dataclass, field
from typing import NamedTuple, Set
from typing import NamedTuple, Optional, Set

try:
from importlib.metadata import PackageNotFoundError, version
Expand Down Expand Up @@ -95,6 +95,11 @@ class SpdxInfo:
spdx_expressions: Set[Expression] = field(default_factory=set)
copyright_lines: Set[str] = field(default_factory=set)
contributor_lines: Set[str] = field(default_factory=set)
license_path: Optional[str] = None

def contains_copyright_or_licensing(self) -> bool:
"""Either *spdx_expressions* or *copyright_lines* is non-empty."""
return bool(self.spdx_expressions or self.copyright_lines)

def __bool__(self):
return any(self.__dict__.values())
Expand Down
5 changes: 3 additions & 2 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ def _copyright_from_dep5(path: PathLike, dep5_copyright: Copyright) -> SpdxInfo:
result = dep5_copyright.find_files_paragraph(Path(path).as_posix())

if result is None:
return SpdxInfo(set(), set())
return SpdxInfo(set(), set(), license_path=str(path))

return SpdxInfo(
set(map(_LICENSING.parse, [result.license.synopsis])),
set(map(str.strip, result.copyright.splitlines())),
license_path=str(path),
)


Expand Down Expand Up @@ -316,7 +317,7 @@ def extract_spdx_info(text: str) -> SpdxInfo:
copyright_matches.add(match.groupdict()["copyright"].strip())
break

return SpdxInfo(expressions, copyright_matches)
return SpdxInfo(expressions, copyright_matches, "")


def find_license_identifiers(text: str) -> Iterator[str]:
Expand Down
3 changes: 2 additions & 1 deletion src/reuse/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def create_header(
spdx_info.spdx_expressions.union(existing_spdx.spdx_expressions),
spdx_copyrights,
spdx_info.contributor_lines.union(existing_spdx.contributor_lines),
"",
)

new_header += _create_new_header(
Expand Down Expand Up @@ -784,7 +785,7 @@ def run(args, project: Project, out=sys.stdout) -> int:
set(args.contributor) if args.contributor is not None else set()
)

spdx_info = SpdxInfo(expressions, copyright_lines, contributors)
spdx_info = SpdxInfo(expressions, copyright_lines, contributors, "")

result = 0
for path in paths:
Expand Down
Loading