From e08148f36a0b3d9d14160fa78e84d55e95017033 Mon Sep 17 00:00:00 2001 From: "Tom C (DLS)" <101418278+coretl@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:18:39 +0000 Subject: [PATCH] Improve import linting (#704) It now considers the runtime stack and the testing stack as separate --- .gitignore | 4 +++- pyproject.toml | 50 ++++++++++++++++---------------------------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index ef6d127ea9..8d2b6b388a 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,8 @@ docs/savefig # generated version number ophyd_async/_version.py - # ruff cache .ruff_cache/ + +# import linter cache +.import_linter_cache/ diff --git a/pyproject.toml b/pyproject.toml index 9246ec9ba7..f07aef8504 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,6 +159,9 @@ lint.select = [ "SLF", # self - https://docs.astral.sh/ruff/settings/#lintflake8-self "PLC2701", # private import - https://docs.astral.sh/ruff/rules/import-private-name/ ] +lint.ignore = [ + "B901", # Return in a generator is needed for plans +] lint.preview = true # so that preview mode PLC2701 is enabled [tool.ruff.lint.per-file-ignores] @@ -172,47 +175,26 @@ lint.preview = true # so that preview mode PLC2701 is enabled root_package = "ophyd_async" [[tool.importlinter.contracts]] -name = "Core is independent" -type = "independence" -modules = "ophyd_async.core" +name = "All runtime modules are in layers" +type = "layers" +containers = ["ophyd_async"] +layers = ["plan_stubs", "fastcs", "epics | tango | sim", "core"] +exhaustive = true +exhaustive_ignores = ["testing", "_version", "__main__"] [[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", -] +name = "Testing modules" +type = "layers" +containers = ["ophyd_async"] +layers = ["testing", "core"] [[tool.importlinter.contracts]] -name = "tango depends only on core" +name = "Testing modules are not used at runtime" type = "forbidden" -source_modules = "ophyd_async.tango" +source_modules = "ophyd_async.testing" 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.epics", "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"]