Giter Site home page Giter Site logo

pre-commit_check_load_module_py's Introduction

pre-commit check load module

This is a pre-commit hook that just loads python module.

Why ?

By configuring an interpreter (virtual env) and PYTHONPATH per folder, detect early offending imports such as using a package which is not included in virtual env, or importing a package which is not in PYTHONPATH.

How ?

This package is based on pre-commit framework.

Configure check load module

Create a configuration file .check_load_module in root repository folder.

[DEFAULT]
# optional logfile
logfile = /tmp/check_load_module.log

# add any number of section per folder to configure
[common]
# prefix of file path
prefix = common/
# python path for allowed imports in repository
PYTHONPATH = common
# interpreter path in virtual env
interpreter = ../../.venv/bin/python

[app]
prefix = app/
# separate folders with colon or semi-colon, it will be adapted depending on platform
PYTHONPATH = app:common
# if no interpreter specified, the default interpreter will be used
# for Windows/Linux compatibility, interpreter can have several values separated by a coma
# e.g. interpreter = .venv/bin/python, .venv/Scripts/python.exe

In this example, modules in app/ can import modules in common/ but the inverse is not possible.

Configure pre-commit to use this hook

Add this content in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/anhvut/pre-commit_check_load_module_py
    rev: 0.0.9
    hooks:
      - id: check-load-module-py
        name: Check module loads

Install hook:

pre-commit install-hooks

Update hook version

pre-commit autoupdate

Contribute to this hook

Virtual env

Use poetry to install virtual env:

poetry install

Run test

Use pytest with poetry:

poetry run pytest

pre-commit_check_load_module_py's People

Contributors

anhvut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.