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

No longer refuse to scan files with uncommentable file extensions #896

Merged
merged 3 commits into from
Jan 19, 2024
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ CLI command and its behaviour. There are no guarantees of stability for the

### Fixed

- `.qrc` and `.ui` now have the HTML comment style instead of being marked
uncommentable. (#896)
- This reverts behaviour introduced in v3.0.0: the contents of uncommentable
files are scanned for REUSE information again. The contents of binary files
are not. (#896)

### Security

## 3.0.0 - 2024-01-17
Expand Down
12 changes: 0 additions & 12 deletions src/reuse/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
cast,
)

from binaryornot.check import is_binary
from boolean.boolean import Expression, ParseError
from debian.copyright import Copyright
from debian.copyright import Error as DebianError
Expand Down Expand Up @@ -334,17 +333,6 @@ def _has_style(path: Path) -> bool:
return _get_comment_style(path) is not None


def _is_commentable(path: Path) -> bool:
"""Determines if *path* is commentable. Commentable files:

- have a CommentStyle that isn't UncommentableCommentStyle;
- are not binary.
"""
return not (
_is_uncommentable(path) or not _has_style(path) or is_binary(str(path))
)


def merge_copyright_lines(copyright_lines: Set[str]) -> Set[str]:
"""Parse all copyright lines and merge identical statements making years
into a range.
Expand Down
4 changes: 2 additions & 2 deletions src/reuse/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ class XQueryCommentStyle(CommentStyle):
".pyx": PythonCommentStyle,
".qbs": CCommentStyle,
".qml": CCommentStyle,
".qrc": UncommentableCommentStyle,
".qrc": HtmlCommentStyle,
".qss": CssCommentStyle,
".R": PythonCommentStyle,
".rake": PythonCommentStyle,
Expand Down Expand Up @@ -772,7 +772,7 @@ class XQueryCommentStyle(CommentStyle):
".tsx": CCommentStyle,
".ttl": PythonCommentStyle, # Turtle/RDF
".typ": CCommentStyle, # typst files
".ui": UncommentableCommentStyle,
".ui": HtmlCommentStyle,
".v": CCommentStyle, # V-Lang source code
".vala": CCommentStyle,
".vim": VimCommentStyle,
Expand Down
8 changes: 3 additions & 5 deletions src/reuse/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
_contains_snippet,
_copyright_from_dep5,
_determine_license_path,
_is_uncommentable,
_parse_dep5,
decoded_text_from_binary,
extract_reuse_info,
Expand Down Expand Up @@ -234,12 +233,11 @@ def reuse_info_of(self, path: StrPath) -> List[ReuseInfo]:
_("'{path}' covered by .reuse/dep5").format(path=path)
)

if _is_uncommentable(path) or is_binary(str(path)):
if is_binary(str(path)):
_LOGGER.info(
_(
"'{path}' was detected as a binary file or its extension is"
" marked as uncommentable; not searching its contents for"
" REUSE information."
"'{path}' was detected as a binary file; not searching its"
" contents for REUSE information."
).format(path=path)
)
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ def test_reuse_info_of_unlicensed_file(fake_repository):
assert not bool(project.reuse_info_of("foo.py"))


def test_reuse_info_of_uncommentable_file(empty_directory):
"""When a file is marked uncommentable, but does contain REUSE info, read it
anyway.
"""
(empty_directory / "foo.png").write_text("Copyright 2017 Jane Doe")
project = Project.from_directory(empty_directory)
result = project.reuse_info_of("foo.png")
assert len(result) == 1
assert result[0].copyright_lines


def test_reuse_info_of_only_copyright(fake_repository):
"""A file contains only a copyright line. Test whether it correctly picks
up on that.
Expand Down
Loading