Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seddonym/import-linter
Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://github.com/seddonym/import-linter
dependencies imports linter python
Last synced: 15 days ago
JSON representation
Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
- Host: GitHub
- URL: https://github.com/seddonym/import-linter
- Owner: seddonym
- License: bsd-2-clause
- Created: 2019-01-27T10:18:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-29T17:13:33.000Z (3 months ago)
- Last Synced: 2024-09-06T10:40:09.815Z (2 months ago)
- Topics: dependencies, imports, linter, python
- Language: Python
- Homepage: https://import-linter.readthedocs.io/
- Size: 520 KB
- Stars: 664
- Watchers: 10
- Forks: 45
- Open Issues: 47
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
=============
Import Linter
=============.. image:: https://img.shields.io/pypi/v/import-linter.svg
:target: https://pypi.org/project/import-linter.. image:: https://img.shields.io/pypi/pyversions/import-linter.svg
:alt: Python versions
:target: https://pypi.org/project/import-linter/.. image:: https://github.com/seddonym/import-linter/workflows/CI/badge.svg?branch=master
:target: https://github.com/seddonym/import-linter/actions?workflow=CI
:alt: CI StatusImport Linter allows you to define and enforce rules for the imports within and between Python packages.
* Free software: BSD license
* Documentation: https://import-linter.readthedocs.io.Overview
--------Import 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 imports between all the modules in one
or more Python packages, and compares this against a set of rules that you provide in a configuration file.The configuration file contains one or more 'contracts'. Each contract has a specific
type, which determines the sort of rules it will apply. For example, the ``forbidden``
contract type allows you to check that certain modules or packages are not imported by
parts of your project.Import Linter 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
Import Linter to your deployment pipeline, so that any code that does not follow
the architecture will fail tests.If there isn't a built in contract type that fits your desired architecture, you can define
a custom one.Quick start
-----------Install Import Linter::
pip install import-linter
Decide on the dependency flows you wish to check. In this example, we have
decided to make sure that ``myproject.foo`` has dependencies on neither
``myproject.bar`` nor ``myproject.baz``, so we will use the ``forbidden`` contract type.Create an ``.importlinter`` file in the root of your project to define your contract(s). In this case:
.. code-block:: ini
[importlinter]
root_package = myproject[importlinter:contract:1]
name=Foo doesn't import bar or baz
type=forbidden
source_modules=
myproject.foo
forbidden_modules=
myproject.bar
myproject.bazNow, from your project root, run::
lint-imports
If your code violates the contract, you will see an error message something like this:
.. code-block:: text
=============
Import Linter
=============---------
Contracts
---------Analyzed 23 files, 44 dependencies.
-----------------------------------Foo doesn't import bar or baz BROKEN
Contracts: 1 broken.
----------------
Broken contracts
----------------Foo doesn't import bar or baz
-----------------------------myproject.foo is not allowed to import myproject.bar:
- myproject.foo.blue -> myproject.utils.red (l.16)
myproject.utils.red -> myproject.utils.green (l.1)
myproject.utils.green -> myproject.bar.yellow (l.3)