From 9a4491bcd3bb8742a95a75cd103d4b0094a34dfd Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Wed, 4 Oct 2023 01:02:47 +0200 Subject: [PATCH] add importability test --- .github/workflows/test.yml | 21 +++++++++++++++++++++ tests/test_importable.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/test_importable.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2e25ce4..cde3353e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,27 @@ on: - "pyproject.toml" jobs: + importable: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -el {0} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup environment + uses: ./.github/actions/setup-env + with: + optional-dependencies: "false" + + - name: Check if all public packages are importable + run: python tests/test_importable.py + + unit: runs-on: ubuntu-latest defaults: diff --git a/tests/test_importable.py b/tests/test_importable.py new file mode 100644 index 00000000..d3e41f88 --- /dev/null +++ b/tests/test_importable.py @@ -0,0 +1,32 @@ +import importlib +from pathlib import Path + +HERE = Path(__file__).parent +PROJECT_ROOT = HERE.parent +PACKAGE_ROOT = PROJECT_ROOT / "ragna" + + +def main(): + for path in PACKAGE_ROOT.rglob("*.py"): + if path.name == "__init__.py": + path = path.parent + else: + path = path.with_suffix("") + + if path.name.startswith("_"): + continue + + name = path.relative_to(PROJECT_ROOT).as_posix().replace("/", ".") + + try: + importlib.import_module(name) + except Exception as exc: + raise ImportError( + f"Trying to import '{name}' raise the error above" + ) from exc + else: + print(name) + + +if __name__ == "__main__": + main()