Skip to content

Commit

Permalink
check if requirements are sorted
Browse files Browse the repository at this point in the history
also intentionally submit incorrect `requirements.txt` so that CI fails
  • Loading branch information
jprochazk committed May 9, 2023
1 parent 1d9cb5a commit f2e0240
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 1 addition & 2 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
-r minimal/requirements.txt
-r mp_pose/requirements.txt
-r multiprocessing/requirements.txt
-r multithreading/requirements.txt
-r notebook/requirements.txt
-r nyud/requirements.txt
-r objectron/requirements.txt
-r opencv_canny/requirements.txt
-r plots/requirements.txt
-r raw_mesh/requirements.txt
-r ros/requirements.txt
-r raw_mesh/requirements.txt
-r segment_anything/requirements.txt
-r stable_diffusion/requirements.txt
-r text_logging/requirements.txt
Expand Down
27 changes: 22 additions & 5 deletions scripts/check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@


def main() -> None:
print("checking `examples/python/requirements.txt`")
failed = False

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

missing = []
for path in glob("examples/python/*/requirements.txt"):
Expand All @@ -16,12 +21,24 @@ def main() -> None:
missing.append(line)

if len(missing) != 0:
print("`examples/python/requirements.txt` is missing the following requirements:")
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')}")
exit(1)

print("`examples/python/requirements.txt` is not missing any requirements")
else:
print("All clear.")


if __name__ == "__main__":
Expand Down

0 comments on commit f2e0240

Please sign in to comment.