From 62deb1da6bdaa703031c3153e22365ee485c4932 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 22 Nov 2024 12:26:49 +0000 Subject: [PATCH] added and all the contracts are kept --- .github/workflows/_test.yml | 4 ++++ .github/workflows/ci.yml | 2 +- .pre-commit-config.yaml | 8 ++++++++ pyproject.toml | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 37d997af1a..32bc843bed 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -49,6 +49,10 @@ jobs: with: python-version: ${{ inputs.python-version }} pip-install: ".[dev]" + + - name: Run import linter + run: lint-imports + - name: Run tests run: tox -e tests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d11c9c6dca..ff5e92d344 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: uses: ./.github/workflows/_tox.yml with: tox: pre-commit,type-checking - + test: needs: check if: needs.check.outputs.branch-pr == '' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60fc23f9a7..72e6dd577d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,3 +22,11 @@ repos: entry: ruff format --force-exclude types: [python] require_serial: true + + - id: import-contracts + name: Ensure import directionality + pass_filenames: false + language: system + entry: lint-imports + types: [python] + require_serial: false diff --git a/pyproject.toml b/pyproject.toml index 41975b0ae7..3f7f642b7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ dev = [ "inflection", "ipython", "ipywidgets", + "import-linter", "matplotlib", "myst-parser", "numpydoc", @@ -164,3 +165,41 @@ lint.preview = true # so that preview mode PLC2701 is enabled # See https://github.com/DiamondLightSource/python-copier-template/issues/154 # Remove this line to forbid private member access in tests "tests/**/*" = ["SLF001"] + + +[tool.importlinter] +root_package = "ophyd_async" + +[[tool.importlinter.contracts]] +name = "Core is independent" +type = "independence" +modules = "ophyd_async.core" + +[[tool.importlinter.contracts]] +name = "Epics depends only on core" +type = "forbidden" +source_modules = "ophyd_async.epics" +forbidden_modules = [ + "ophyd_async.fastcs", + "ophyd_async.plan_stubs", + "ophyd_async.sim", + "ophyd_async.tango", +] + +[[tool.importlinter.contracts]] +name = "tango depends only on core" +type = "forbidden" +source_modules = "ophyd_async.tango" +forbidden_modules = [ + "ophyd_async.fastcs", + "ophyd_async.plan_stubs", + "ophyd_async.sim", + "ophyd_async.epics", +] + + +[[tool.importlinter.contracts]] +name = "Fastcs depends only on core, epics, tango" +type = "forbidden" +source_modules = "ophyd_async.fastcs" +forbidden_modules = ["ophyd_async.plan_stubs", "ophyd_async.sim"]