Skip to content

Commit

Permalink
Merge check_requirements.py into lint.py (rerun-io#5982)
Browse files Browse the repository at this point in the history
### What

* Fixes rerun-io#5893
  • Loading branch information
Wumpf authored Apr 16, 2024
1 parent 61af622 commit 88a94ee
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 57 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/contrib_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,8 @@ jobs:
- name: Check for too large files
run: pixi run check-large-files

- name: Check Python example requirements
shell: bash
run: |
pixi run ./scripts/ci/check_requirements.py
- name: Check Python example thumbnails
shell: bash
run: |
pixi run ./scripts/ci/thumbnails.py check
run: pixi run ./scripts/ci/thumbnails.py check

spell-check:
name: Spell Check
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/reusable_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ jobs:
- name: Check for too large files
run: pixi run check-large-files

- name: Check Python example requirements
run: pixi run ./scripts/ci/check_requirements.py

- name: Check Python example thumbnails
run: pixi run ./scripts/ci/thumbnails.py check

Expand Down
46 changes: 0 additions & 46 deletions scripts/ci/check_requirements.py

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import argparse
from glob import glob
import os
import re
import sys
Expand Down Expand Up @@ -959,6 +960,44 @@ def lint_crate_docs(should_ignore: Callable[[Any], bool]) -> int:
return error_count


def lint_example_requirements() -> int:
"""Check that `examples/python/requirements.txt` contains all requirements from the subdirectories and is correctly sorted."""

failed = False

with open("examples/python/requirements.txt") as f:
lines = f.read().strip().splitlines()
sorted_lines = lines.copy()
sorted_lines.sort()
requirements = set(lines)

missing = []
for path in glob("examples/python/*/requirements.txt"):
line = f"-r {os.path.relpath(path, 'examples/python')}"
if line not in requirements:
missing.append(line)

if len(missing) != 0:
print("\n`examples/python/requirements.txt` is missing the following requirements:")
for line in missing:
print(line)
failed = True

if lines != sorted_lines:
print("\n`examples/python/requirements.txt` is not correctly sorted.")
failed = True

if failed:
print("\nHere is what `examples/python/requirements.txt` should contain:")
expected = glob("examples/python/*/requirements.txt")
expected.sort()
for path in expected:
print(f"-r {os.path.relpath(path, 'examples/python')}")
return 1

return 0


def main() -> None:
# Make sure we are bug free before we run:
test_lint_line()
Expand Down Expand Up @@ -1062,6 +1101,8 @@ def main() -> None:
# Since no files have been specified, we also run the global lints.
num_errors += lint_crate_docs(should_ignore)

num_errors += lint_example_requirements()

if num_errors == 0:
print(f"{sys.argv[0]} finished without error")
sys.exit(0)
Expand Down

0 comments on commit 88a94ee

Please sign in to comment.