Skip to content
Open
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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ requests_).
- Christopher Bennett
- Ryan Boult
- Samuel Denton
- Vincent Gao
<!-- end-shortlog -->

(All contributors are identifiable with email addresses in the git version
Expand Down
1 change: 1 addition & 0 deletions changes.d/7351.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent `cylc lint` from raising tracebacks for empty files and `.cylc` directories.
10 changes: 9 additions & 1 deletion cylc/flow/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,11 @@ def check_cylc_file(
modify: bool = False,
):
"""Check A Cylc File for Cylc 7 Config"""
if file.is_dir():
LOG.error(f'{file_rel} is not a file.')
counter['E'] += 1
return

with open(file, 'r') as cylc_file:
# generator which reads and lints one line at a time
linter = lint(
Expand Down Expand Up @@ -1249,7 +1254,10 @@ def lint(
"""
# get the first line
line_no = 1
line = next(lines)
try:
line = next(lines)
except StopIteration:
return
# check if it is a jinja2 shebang
jinja_shebang = line.strip().lower() == JINJA2_SHEBANG

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/scripts/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
LINT_SECTION,
MANUAL_DEPRECATIONS,
check_lowercase_family_names,
check_cylc_file,
get_cylc_files,
get_pyproject_toml,
get_reference,
Expand Down Expand Up @@ -278,6 +279,15 @@ def test_check_cylc_file_line_no():
assert ':2:' in lint.messages[0]


def test_check_cylc_file_empty():
"""It does not raise a traceback for an empty file."""
lint = lint_text('', ['style'])

assert lint.counter == Counter()
assert lint.messages == []
assert lint.outlines == []


@pytest.mark.parametrize(
'line',
[
Expand Down Expand Up @@ -411,6 +421,18 @@ def test_get_cylc_files_get_all_rcs(tmp_path):
assert sorted(result) == sorted(expect)


def test_check_cylc_file_reports_directory(tmp_path, caplog):
"""It reports .cylc directories instead of raising a traceback."""
path = tmp_path / 'another.cylc'
path.mkdir()
counter = Counter()

check_cylc_file(path, Path('another.cylc'), {}, counter)

assert counter == Counter({'E': 1})
assert 'another.cylc is not a file.' in caplog.messages


def mock_parse_checks(*args, **kwargs):
return {
'U042': {
Expand Down