Skip to main content

An utility tool to check for inappropriate imports between modules in a Python project.

Project description

Modular Monolith Import Checker

Overview

The Modular Monolith Import Checker is a Python utility designed to enforce modular boundaries within your codebase. It ensures that modules in a modular monolith architecture do not import each other inappropriately, maintaining clear module boundaries and a clean architecture.

Features

  • Detect Forbidden Imports: Identifies cases where a module imports another module that it shouldn't.
  • Flexible Path Handling: Supports both absolute and relative paths for specifying base directories.
  • Dynamic Module List: Allows you to specify a list of modules to check.

Installation

To use the Modular Monolith Import Checker, you need Python 3 installed. Install the package using pip:

pip install module-import-checker

Usage

You can run the import checker from the command line or import it into your Python scripts.

Command-Line Interface

Run the import checker directly from the command line with various configurations:

  1. Modules at the Project Root:

    import_checker /path/to/project module1 module2 module3
    
    • /path/to/project is the base directory of your project.
    • module1, module2, module3, etc., are the names of the modules you want to check.
  2. Modules in the Current Directory:

    import_checker . module1 module2 module3
    
    • Use . if you are running the script from the project root directory.
  3. Modules Inside a Subdirectory:

    import_checker project_name module1 module2 module3
    
    • project_name is the name of the subdirectory containing your modules.

Example

To check imports in a project located in /home/user/myproject where modules are named auth, users, and payments, run:

import_checker /home/user/myproject auth users payments

You can create a bash script to run this command automatically:

#!/bin/bash
import_checker /home/user/myproject auth users payments

Command-Line Help

For detailed usage information, run:

import_checker --help

Example Output

Checking imports in Base Directory: /home/user/myproject
Checking module: /home/user/myproject/auth/
Import check failed with errors:
Forbidden import detected: 'users' imports 'auth' in /home/user/myproject/users/services.py

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request. Ensure that your code follows the existing style and includes tests for new features.

License

This project is licensed under the GNU General Public License - see the LICENSE file for details.

Contact

For any questions or issues, please contact abiolaadeshinaadedayo@gmail.com.

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

module_import_checker-0.0.12.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

module_import_checker-0.0.12-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file module_import_checker-0.0.12.tar.gz.

File metadata

File hashes

Hashes for module_import_checker-0.0.12.tar.gz
Algorithm Hash digest
SHA256 9d33b924f9634301c046e83b8833102ecc4677be38579a2cef0397d20a3237fb
MD5 37b00bc5c24360a7b6abdce50a3d2701
BLAKE2b-256 3349cd00734579b654bd4fba88dda3cc00fed776644931259961f0aa7d172ae7

See more details on using hashes here.

File details

Details for the file module_import_checker-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for module_import_checker-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1ec66a8042d9d7cb4722f339cdea0d58d3f6a769692df9ac1c7ee4089425f5
MD5 d5d81860cee65868ad1d2601127a1fe3
BLAKE2b-256 1b7844e73ccd5558b39c6ca13f438215b5c3e0952cae761d5ab6a864e10bb61e

See more details on using hashes here.

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