Skip to content
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
1 change: 1 addition & 0 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def fill_defaults(config): # noqa: C901
cfg = config["license_rst"]
cfg.setdefault("add_to_files", False)
cfg.setdefault("text", license_text(config["license"], config["project_name"]))
cfg.setdefault("exclude", None)


def license_text(license, project_name):
Expand Down
6 changes: 5 additions & 1 deletion nengo_bones/scripts/check_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def main(root_dir, conf_file, verbose):
]

if "license_rst" in config and config["license_rst"]["add_to_files"]:
_, missing = check_notice.check_notice(path, config["license_rst"]["text"])
_, missing = check_notice.check_notice(
path,
config["license_rst"]["text"],
exclude=config["license_rst"]["exclude"],
)
passed.append(missing == 0)

click.echo("*" * 50)
Expand Down
11 changes: 10 additions & 1 deletion nengo_bones/scripts/check_notice.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Checks that license text is added to all .py files."""

import re

import click

from nengo_bones.templates import add_notice


def check_notice(root, text, fix=False, verbose=False):
def check_notice(root, text, fix=False, verbose=False, exclude=None):
"""
Check for license notices in all .py files.

Expand All @@ -19,6 +21,8 @@ def check_notice(root, text, fix=False, verbose=False):
Add the notice to any file that is missing one.
verbose : bool
Print the name of all files checked.
exclude : list of str
Regex patterns for files to exclude from checking.

Returns
-------
Expand All @@ -33,6 +37,11 @@ def check_notice(root, text, fix=False, verbose=False):
checked = 0
missing = 0
for path in root.rglob("*.py"):
if exclude is not None and any(
re.search(p, str(path)) is not None for p in exclude
):
continue

checked += 1
current_text = path.read_text()

Expand Down
19 changes: 19 additions & 0 deletions nengo_bones/tests/test_check_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,22 @@ def test_license_check(tmp_path):
result = _run_check_bones(tmp_path)
assert_exit(result, 1)
assert "Missing" in result.output

_write_nengo_yml(
tmp_path,
nengo_yml="""
project_name: Dumdum
pkg_name: dummy
repo_name: dummy_org/dummy

license_rst:
add_to_files: true
exclude:
- file.py
""",
)
(tmp_path / "file.py").touch()

result = _run_check_bones(tmp_path)
assert_exit(result, 0)
assert "Missing" not in result.output
1 change: 0 additions & 1 deletion nengo_bones/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def make_has_line(lines, strip=False, regex=False):
idx = 0

def has_line(target, strip=strip, regex=regex, print_on_fail=True):
nonlocal lines
nonlocal idx

while idx < len(lines):
Expand Down
Loading