Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: logicalclocks/hopsworks-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 70757394759640428a0ee219fc2ae9f0a5a2bd0c
Choose a base ref
..
head repository: logicalclocks/hopsworks-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 78d1cd219e53ccb1a9921bce2395d31ba44e05c7
Choose a head ref
Showing with 39 additions and 30 deletions.
  1. +1 −1 .github/workflows/python.yml
  2. +38 −29 python/aliases.py
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ jobs:
run: ruff format $ALL_CHANGED_FILES

- name: check aliases
run: python ./python/aliases.py check
run: python python/aliases.py check

unit_tests:
name: Unit Tests
67 changes: 38 additions & 29 deletions python/aliases.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,16 @@
# Everything that is not a top-level file, a part of sources, or a part of ignored is considered to be autmoatically managed.


def traverse(path, f):
if not path.exists():
return
if path.is_file():
f(path)
return
for child in path.iterdir():
traverse(child, f)


def collect_imports(root):
imports = []

@@ -46,12 +56,8 @@ def imports_add(file):
imports.append(pkg + "." + file.name[:-3])

for source in SOURCES:
if (root / source).is_file():
imports_add(root / source)
continue
for dirpath, _, filenames in (root / source).walk():
for filename in filenames:
imports_add(dirpath / filename)
traverse(root / source, imports_add)

return imports


@@ -83,35 +89,38 @@ def fix(root):
filepath.touch()
filepath.write_text(content)
ignored = [root / path for path in SOURCES + IGNORED]
for dirpath, _, filenames in root.walk():
if dirpath == root:
continue
for filename in filenames:
filepath = dirpath / filename
if any(filepath.is_relative_to(p) for p in ignored):
continue
if filepath not in managed:
filepath.unlink()

def remove_if_excess(path):
if path.parent == root:
return
if any(path.is_relative_to(p) for p in ignored):
return
if path not in managed:
path.unlink()

traverse(root, remove_if_excess)


def check(root):
global ok
ok = True
managed = collect_managed(root)
ignored = [root / path for path in SOURCES + IGNORED]
for dirpath, _, filenames in root.walk():
if dirpath == root:
continue
for filename in filenames:
filepath = dirpath / filename
if any(filepath.is_relative_to(p) for p in ignored):
continue
if filepath not in managed:
print(f"Error: {filepath} shouldn't exist.")
ok = False
continue
if filepath.read_text() != managed[filepath]:
print(f"Error: {filepath} has wrong content.")
ok = False

def check_file(path):
global ok
if path.parent == root or any(path.is_relative_to(p) for p in ignored):
return
if path not in managed:
print(f"Error: {path} shouldn't exist.")
ok = False
return
if path.read_text() != managed[path]:
print(f"Error: {path} has wrong content.")
ok = False

traverse(root, check_file)

if ok:
print("The aliases are correct!")
else: