import-linter


Nameimport-linter JSON
Version 2.0 PyPI version JSON
download
home_page
SummaryEnforces rules for the imports within and between Python packages.
upload_time2024-01-09 08:46:58
maintainer
docs_urlNone
author
requires_python>=3.8
licenseBSD 2-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            =============
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 Status

Import 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.baz

Now, 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)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "import-linter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "David Seddon <david@seddonym.me>",
    "download_url": "https://files.pythonhosted.org/packages/d4/3a/6b433eace42d2f92cb96667f326b11582004b74acd045bf10a277761eed4/import-linter-2.0.tar.gz",
    "platform": null,
    "description": "=============\nImport Linter\n=============\n\n.. image:: https://img.shields.io/pypi/v/import-linter.svg\n    :target: https://pypi.org/project/import-linter\n\n.. image:: https://img.shields.io/pypi/pyversions/import-linter.svg\n    :alt: Python versions\n    :target: https://pypi.org/project/import-linter/\n\n.. image:: https://github.com/seddonym/import-linter/workflows/CI/badge.svg?branch=master\n     :target: https://github.com/seddonym/import-linter/actions?workflow=CI\n     :alt: CI Status\n\nImport Linter allows you to define and enforce rules for the imports within and between Python packages.\n\n* Free software: BSD license\n* Documentation: https://import-linter.readthedocs.io.\n\nOverview\n--------\n\nImport Linter is a command line tool to check that you are following a self-imposed\narchitecture within your Python project. It does this by analysing the imports between all the modules in one\nor more Python packages, and compares this against a set of rules that you provide in a configuration file.\n\nThe configuration file contains one or more 'contracts'. Each contract has a specific\ntype, which determines the sort of rules it will apply. For example, the ``forbidden``\ncontract type allows you to check that certain modules or packages are not imported by\nparts of your project.\n\nImport Linter is particularly useful if you are working on a complex codebase within a team,\nwhen you want to enforce a particular architectural style. In this case you can add\nImport Linter to your deployment pipeline, so that any code that does not follow\nthe architecture will fail tests.\n\nIf there isn't a built in contract type that fits your desired architecture, you can define\na custom one.\n\nQuick start\n-----------\n\nInstall Import Linter::\n\n    pip install import-linter\n\nDecide on the dependency flows you wish to check. In this example, we have\ndecided to make sure that ``myproject.foo`` has dependencies on neither\n``myproject.bar`` nor ``myproject.baz``, so we will use the ``forbidden`` contract type.\n\nCreate an ``.importlinter`` file in the root of your project to define your contract(s). In this case:\n\n.. code-block:: ini\n\n    [importlinter]\n    root_package = myproject\n\n    [importlinter:contract:1]\n    name=Foo doesn't import bar or baz\n    type=forbidden\n    source_modules=\n        myproject.foo\n    forbidden_modules=\n        myproject.bar\n        myproject.baz\n\nNow, from your project root, run::\n\n    lint-imports\n\nIf your code violates the contract, you will see an error message something like this:\n\n.. code-block:: text\n\n    =============\n    Import Linter\n    =============\n\n    ---------\n    Contracts\n    ---------\n\n    Analyzed 23 files, 44 dependencies.\n    -----------------------------------\n\n    Foo doesn't import bar or baz BROKEN\n\n    Contracts: 1 broken.\n\n\n    ----------------\n    Broken contracts\n    ----------------\n\n    Foo doesn't import bar or baz\n    -----------------------------\n\n    myproject.foo is not allowed to import myproject.bar:\n\n    -   myproject.foo.blue -> myproject.utils.red (l.16)\n        myproject.utils.red -> myproject.utils.green (l.1)\n        myproject.utils.green -> myproject.bar.yellow (l.3)\n",
    "bugtrack_url": null,
    "license": "BSD 2-Clause License",
    "summary": "Enforces rules for the imports within and between Python packages.",
    "version": "2.0",
    "project_urls": {
        "Documentation": "https://import-linter.readthedocs.io/",
        "Source-code": "https://github.com/seddonym/import-linter/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "81825a23aefe774927b45d9964282496c5228d537bb5de1e54eedce832fa4901",
                "md5": "b0d0ca377fed086cdfd4f713466c06cf",
                "sha256": "200f9b46d20a055c1f6f514e4cd8074852261bc9c8733d028201a55be6058bb0"
            },
            "downloads": -1,
            "filename": "import_linter-2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b0d0ca377fed086cdfd4f713466c06cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 41018,
            "upload_time": "2024-01-09T08:46:56",
            "upload_time_iso_8601": "2024-01-09T08:46:56.881700Z",
            "url": "https://files.pythonhosted.org/packages/81/82/5a23aefe774927b45d9964282496c5228d537bb5de1e54eedce832fa4901/import_linter-2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d43a6b433eace42d2f92cb96667f326b11582004b74acd045bf10a277761eed4",
                "md5": "3c95e3379c8c223719c45527bdd22daa",
                "sha256": "b067cf0cdbf11c4f87524e32c2e3eaa62d46572e9e06511e6b453198b15b1c9a"
            },
            "downloads": -1,
            "filename": "import-linter-2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3c95e3379c8c223719c45527bdd22daa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 28678,
            "upload_time": "2024-01-09T08:46:58",
            "upload_time_iso_8601": "2024-01-09T08:46:58.204536Z",
            "url": "https://files.pythonhosted.org/packages/d4/3a/6b433eace42d2f92cb96667f326b11582004b74acd045bf10a277761eed4/import-linter-2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-09 08:46:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "seddonym",
    "github_project": "import-linter",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "import-linter"
}
        
Elapsed time: 0.52006s