Skip to content

Commit

Permalink
Merge pull request #896 from carmenbianca/fix-uncommentable
Browse files Browse the repository at this point in the history
No longer refuse to scan files with uncommentable file extensions
  • Loading branch information
carmenbianca authored Jan 19, 2024
2 parents 120be91 + 27e70a1 commit 50a7474
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
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

0 comments on commit 50a7474

Please sign in to comment.