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.11.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

module_import_checker-0.0.11-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for module_import_checker-0.0.11.tar.gz
Algorithm Hash digest
SHA256 eb2f69430e1478693f810dcaed66021d4f13d74be81e55a2e77877efd0c7cf26
MD5 28dcbcb4ac2578d58f2f1ba0956430ef
BLAKE2b-256 7e4744bd27ded971fedca630c511b3a89df55868675c7f70d90eeade14234a7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for module_import_checker-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 1f8c1f46b33015141327aee869c26418468abca3fa546feb684e8a5dcffc539c
MD5 5ed1ba463e0767137417782c7a1f0412
BLAKE2b-256 184c01ed3fcb636d91f0f218537804637da2bb2d1d2d60ec3100436cd5e1f868

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