Skip to main content

Layer Linter checks that your project follows a custom-defined layered architecture.

Project description

Layer Linter

https://img.shields.io/pypi/v/layer_linter.svg Python versions https://api.travis-ci.org/seddonym/layer_linter.svg?branch=master https://codecov.io/gh/seddonym/layer_linter/branch/master/graph/badge.svg Documentation Status Updates

Layer Linter checks that your project follows a custom-defined layered architecture, based on its internal dependencies (i.e. the imports between its modules).

Overview

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.

Quick start

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.

Create a layers.yml in the root of your project. For example:

My Layers Contract:
  packages:
    - 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.)

From your project root, run:

layer-lint myproject

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 on the what you can do in your layers.yml, see Core Concepts.

History

0.1.0 (2018-06-20)

  • First release on PyPI.

0.2.0 (2018-06-23)

  • Look for layers.yml in current working directory.

0.3.0 (2018-06-24)

  • Rename command to layer-lint.

  • Changed order of layers in layers.yml to be listed high level to low level.

0.4.0 (2018-07-22)

  • 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.

0.5.0 (2018-08-01)

  • 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.

0.6.0 (2018-08-07)

  • Added ability to whitelist paths.

0.6.1 (2018-08-07)

  • Add current working directory to path.

0.6.2 (2018-08-17)

  • Don’t analyse children of directories that aren’t Python packages.

  • Prevented installing incompatible version of Pydeps (1.6).

0.7.0 (2018-09-04)

  • Complete rewrite of static analysis used to build dependency graph.

  • Added quiet and verbose reporting.

  • Added type annotation and mypy.

  • Build earlier versions of Python using pybackwards.

  • Corrected docs to refer to layers.yml instead of layers.yaml.

0.7.1 (2018-09-04)

  • Fix packaging bug with 0.7.0.

0.7.2 (2018-09-05)

  • Fix bug with not checking all submodules of layer.

0.7.3 (2018-09-07)

  • Drop support for Python 3.4 and 3.5 and adjust packaging.

latest

  • Tweak command line error handling.

  • Improve README and Core Concepts documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

layer-linter-0.7.4.tar.gz (117.2 kB view hashes)

Uploaded Source

Built Distribution

layer_linter-0.7.4-py36,py37-none-any.whl (16.3 kB view hashes)

Uploaded Python 3.6,py37

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page