Layer Linter checks that your project follows a custom-defined layered architecture.
Layer Linter has been deprecated in favour of Import Linter.
Import Linter does everything Layer Linter does, but with more features and a slightly different API. If you’re already using Layer Linter, migrating to Import Linter is simple: there is a guide here.
Layer Linter checks that your project follows a custom-defined layered architecture, based on its internal dependencies (i.e. the imports between its modules).
- Free software: BSD license
- Documentation: https://layer-linter.readthedocs.io.
Layer Linter is a command line tool to check that you are following a self-imposed architecture within your Python project. It does this by analysing the internal imports between all the modules in your code base, and compares this against a set of simple rules that you provide in a layers.yml file.
For example, you can use it to check that no modules inside myproject.foo import from any modules inside myproject.bar, even indirectly.
This is particularly useful if you are working on a complex codebase within a team, when you want to enforce a particular architectural style. In this case you can add Layer Linter to your deployment pipeline, so that any code that does not follow the architecture will fail tests.
Install Layer Linter:
pip install layer-linter
Decide on the dependency flows you wish to check. In this example, we have organised our project into three subpackages, myproject.high, myproject.medium and myproject.low. These subpackages are known as layers. Note: layers must have the same parent package (i.e. all be in the same directory). This parent is known as a container.
Create a layers.yml in the root of your project. For example:
My Layers Contract: containers: - myproject layers: - high - medium - low
(This contract tells Layer Linter that the order of the layers runs from low at the bottom to high at the top. Layers higher up can import ones lower down, but not the other way around.)
Note that the container is an absolute name of a Python package, while the layers are relative to the container.
Now, from your project root, run:
If your code violates the contract, you will see an error message something like this:
============ Layer Linter ============ --------- Contracts --------- Analyzed 23 files, 44 dependencies. ----------------------------------- My layer contract BROKEN Contracts: 0 kept, 1 broken. ---------------- Broken contracts ---------------- My layer contract ----------------- 1. myproject.low.x imports myproject.high.y: myproject.low.x <- myproject.utils <- myproject.high.y
For more details, see Usage.
- First release on PyPI.
- Look for layers.yml in current working directory.
- Renamed command to layer-lint.
- Changed order of layers in layers.yml to be listed high level to low level.
- Made dependency analysis more efficient and robust.
- Improved report formatting.
- Removed illegal dependencies that were implied by other, more succinct illegal dependencies.
- Added --debug command line argument.
- Added count of analysed files and dependencies to report.
- Fixed issues from running command in a different directory to the package.
- Increased speed of analysis.
- Changed --config_directory command line argument to --config-directory.
- Added ability to whitelist paths.
- Added current working directory to path.
- Don’t analyse children of directories that aren’t Python packages.
- Prevented installing incompatible version of Pydeps (1.6).
- Completed rewrite of static analysis used to build dependency graph.
- Added quiet and verbose reporting.
- Added type annotation and mypy.
- Built earlier versions of Python using pybackwards.
- Corrected docs to refer to layers.yml instead of layers.yaml.
- Fixed packaging bug with 0.7.0.
- Fixed bug with not checking all submodules of layer.
- Dropped support for Python 3.4 and 3.5 and adjust packaging.
- Tweaked command line error handling.
- Improved README and Core Concepts documentation.
- Replace --config-directory parameter with --config parameter, which takes a file name instead.
- Moved to beta version.
- Improved documentation.
- Better handling of invalid package names passed to command line.
- Renamed ‘packages’ to ‘containers’ in contracts.
- Improved handling of invalid containers.
- Error if a layer is missing.
- Fixed RST rendering on PyPI.
- Support defining optional layers.
- Updated dependencies, especially switching to a version of PyYAML to address https://nvd.nist.gov/vuln/detail/CVE-2017-18342.
- Fix parsing of relative imports within __init__.py files.
- Add support for Click 7.x.
- Fix bug with Windows file paths.
- Deprecate Layer Linter in favour of Import Linter.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size layer_linter-0.12.3-py36,py37-none-any.whl (19.8 kB)||File type Wheel||Python version py36,py37||Upload date||Hashes View|
|Filename, size layer-linter-0.12.3.tar.gz (121.1 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for layer_linter-0.12.3-py36,py37-none-any.whl