From 62deb1da6bdaa703031c3153e22365ee485c4932 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 22 Nov 2024 12:26:49 +0000 Subject: [PATCH 1/2] 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"] From 7f0e910bb817507e6eed6725d2e02b2245488366 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 22 Nov 2024 17:03:03 +0000 Subject: [PATCH 2/2] respond to feedback --- .github/workflows/_test.yml | 3 --- .github/workflows/ci.yml | 4 ++-- pyproject.toml | 12 ++++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 32bc843bed..f652d4145f 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -50,9 +50,6 @@ jobs: 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 ff5e92d344..1f57059612 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,14 +14,14 @@ jobs: uses: ./.github/workflows/_tox.yml with: tox: pre-commit,type-checking - + test: needs: check if: needs.check.outputs.branch-pr == '' strategy: matrix: runs-on: ["ubuntu-latest", "windows-latest"] # can add macos-latest - python-version: ["3.10","3.11"] # 3.12 should be added when p4p is updated + python-version: ["3.10", "3.11"] # 3.12 should be added when p4p is updated include: # Include one that runs in the dev environment - runs-on: "ubuntu-latest" diff --git a/pyproject.toml b/pyproject.toml index 3f7f642b7f..ef4834750c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -191,10 +191,22 @@ name = "tango depends only on core" type = "forbidden" source_modules = "ophyd_async.tango" forbidden_modules = [ + "ophyd_async.epics", "ophyd_async.fastcs", "ophyd_async.plan_stubs", "ophyd_async.sim", +] + + +[[tool.importlinter.contracts]] +name = "sim depends only on core" +type = "forbidden" +source_modules = "ophyd_async.sim" +forbidden_modules = [ "ophyd_async.epics", + "ophyd_async.fastcs", + "ophyd_async.plan_stubs", + "ophyd_async.tango", ]