File size: 1,118 Bytes
3e62986 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | from pathlib import Path
import re
import sys
PROJECT_ROOT = Path(__file__).resolve().parents[1]
LOCAL_ROOTS = (
PROJECT_ROOT / "flax_model",
PROJECT_ROOT / "model",
PROJECT_ROOT / "scripts",
)
def _python_files(root: Path):
return [
path
for path in root.rglob("*.py")
if "__pycache__" not in path.parts
]
def _check_no_onescience_model_imports():
pattern = re.compile(
r"onescience\.(flax_models|models)\.",
re.MULTILINE,
)
offenders = []
for root in LOCAL_ROOTS:
for path in _python_files(root):
text = path.read_text(encoding="utf-8", errors="ignore")
if pattern.search(text):
offenders.append(str(path.relative_to(PROJECT_ROOT)))
return offenders
def main():
offenders = _check_no_onescience_model_imports()
if offenders:
print("Forbidden onescience model imports:")
for offender in offenders:
print(f" {offender}")
return 1
print("Import boundary checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())
|