From 235d26ae64c228bbf0b9c5a435e7bf36ac67c15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Malinowski?= <56644812+stan-dot@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:28:22 +0000 Subject: [PATCH] Add the python package and the config and make the contracts kept (#669) * added and all the contracts are kept * respond to feedback --- .github/workflows/_test.yml | 1 + .github/workflows/ci.yml | 2 +- .pre-commit-config.yaml | 8 ++++++ pyproject.toml | 51 +++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 37d997af1a..f652d4145f 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -49,6 +49,7 @@ jobs: with: python-version: ${{ inputs.python-version }} pip-install: ".[dev]" + - name: Run tests run: tox -e tests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d11c9c6dca..1f57059612 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: 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/.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..ef4834750c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ dev = [ "inflection", "ipython", "ipywidgets", + "import-linter", "matplotlib", "myst-parser", "numpydoc", @@ -164,3 +165,53 @@ 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.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", +] + + +[[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"]