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

Ignore COPYING and LICENSE as exact matches or with extensions #886

Merged
merged 1 commit into from
Apr 27, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ CLI command and its behaviour. There are no guarantees of stability for the
### Changed

- `.s` files now use the Python comment style as per GNU Assembler (gas). (#928)
- Previously, any file that begins with `COPYING` or `LICENSE` was ignored. This
has been changed. Now, files like `COPYING_README` are no longer ignored, but
`COPYING` and `COPYING.txt` are still ignored (in other words: exact matches,
or `COPYING` + a file extension). Idem ditto for `LICENSE`. (#886)

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions src/reuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
]

_IGNORE_FILE_PATTERNS = [
re.compile(r"^LICENSE"),
re.compile(r"^COPYING"),
re.compile(r"^LICENSE(\..*)?$"),
re.compile(r"^COPYING(\..*)?$"),
# ".git" as file happens in submodules
re.compile(r"^\.git$"),
re.compile(r"^\.gitkeep$"),
Expand Down
26 changes: 25 additions & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,36 @@ def test_all_files_ignore_git(empty_directory):
def test_all_files_ignore_hg(empty_directory):
"""When the hg directory is present, ignore it."""
(empty_directory / ".hg").mkdir()
(empty_directory / ".hg/config").touch()
(empty_directory / ".hg/config").write_text("foo")

project = Project.from_directory(empty_directory)
assert not list(project.all_files())


def test_all_files_ignore_license_copying(empty_directory):
"""When there are files names LICENSE, LICENSE.ext, COPYING, or COPYING.ext,
ignore them.
"""
(empty_directory / "LICENSE").write_text("foo")
(empty_directory / "LICENSE.txt").write_text("foo")
(empty_directory / "COPYING").write_text("foo")
(empty_directory / "COPYING.txt").write_text("foo")

project = Project.from_directory(empty_directory)
assert not list(project.all_files())


def test_all_files_not_ignore_license_copying_no_ext(empty_directory):
"""Do not ignore files that start with LICENSE or COPYING and are followed
by some non-extension text.
"""
(empty_directory / "LICENSE_README.md").write_text("foo")
(empty_directory / "COPYING2").write_text("foo")

project = Project.from_directory(empty_directory)
assert len(list(project.all_files())) == 2


@posix
def test_all_files_symlinks(empty_directory):
"""All symlinks must be ignored."""
Expand Down
Loading