Skip to content

Commit

Permalink
Merge pull request #886 from carmenbianca/copying-license-fix
Browse files Browse the repository at this point in the history
Ignore COPYING and LICENSE as exact matches or with extensions
  • Loading branch information
carmenbianca committed Apr 27, 2024
2 parents 4d10e67 + 0ed4d11 commit a55d195
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit a55d195

Please sign in to comment.