Skip to content

Independence

Independence

Type name: independence

Independence contracts check that a set of modules do not depend on each other.

They do this by checking that there are no imports in any direction between the modules, even indirectly.

Example:

[importlinter:contract:my-independence-contract]
name = My independence contract
type = independence
modules =
    mypackage.foo
    mypackage.bar
    mypackage.baz
ignore_imports =
    mypackage.bar.green -> mypackage.utils
    mypackage.baz.blue -> mypackage.foo.purple
[[tool.importlinter.contracts]]
name = "My independence contract"
type = "independence"
modules = [
    "mypackage.foo",
    "mypackage.bar",
    "mypackage.baz",
]
ignore_imports = [
    "mypackage.bar.green -> mypackage.utils",
    "mypackage.baz.blue -> mypackage.foo.purple",
]

Configuration options

  • modules: A list of modules/subpackages that should be independent of each other. Supports wildcards.
  • ignore_imports: See shared options.
  • unmatched_ignore_imports_alerting: See shared options.