Before use, you will probably want to read Core concepts.
Defining your contracts¶
Your layers contracts are defined in a YAML file named
may exist anywhere, but a good place is in your project root.
The file contains one or more contracts, in the following format:
Contract name: containers: - mypackage.container ... layers: - layerone - layertwo ... whitelisted_paths: - mypackage.container.layertwo.module <- mypackage.container.layerone.module ...
- Contract name: A string to describe your contract.
- Containers: Absolute names of any Python package that contains the layers as immediate children. One or more containers are allowed in this list.
- Layers: Names of the Python module relative to each container listed in
containers. Modules lower down the list must not import modules higher up. (Remember, a Python module can either be a
.pyfile or a directory with an
- Whitelisted paths (optional): If you wish certain import paths not to break in the contract, you can optionally whitelist them. The modules should be listed as absolute names, with the importing module first, and the imported module second.
For some examples, see Core concepts.
You may specify certain layers as optional, by enclosing the name in parentheses.
By default, Layer Linter will error if it cannot find the module for a particular layer. Take the following contract:
My contract: containers: - mypackage.foo - mypackage.bar layers: - one - two
If the module
mypackage.foo.two is missing, the contract will be broken. If you want
the contract to pass despite this, you can enclose the layer name in parentheses:
My contract: containers: - mypackage.foo - mypackage.bar layers: - one - (two)
two is now optional, which means the contract will pass even though
Running the linter¶
Layer Linter provides a single command:
Running this will check that your project adheres to the contracts in your
package_name: The name of the top-level Python package to validate (required).
--config: The YAML file describing your layer contract(s). If not supplied, Layer Linter will look for a file called
layers.ymlin the current directory.
--quiet: Do not output anything if the contracts are all adhered to.
-v): Output a more verbose report.
--debug: Output debug messages when running the linter. No parameters required.
Using a different filename or location instead of
layer-lint myproject --config path/to/alternative.yml