Skip to main content

Python import checker

Project description

PyImportCheck

Pyimportcheck is a static code analyser for Python 3.

This project aims to provide quick detection of:

  • circular imports flow
  • missing exported symbols (special __all__ symbol)
  • bad package declaration (missing of __init__.py files)

Pyimportcheck analyses your code without actually running it. It checks for errors, enforces a coding standard, and can make suggestions about how the code could be refactored (see the screenshot above).

[!WARNING] This project was originaly designed for my personal use to quickly detect arbitrary "errors" (e.g exported symbols) in some "big" projects since the report from the python interpreter is not easy to interpret for some edge cases (like circular import)

Note that you probably want to use CodeQL with default python query that can perform the same job as my tool.

If you want to know what I plan to do with this project, you can check the Roadmap issue that evolves with time

Install

Install and update using pip or poetry:

pip install pyimportcheck
poetry add pyimportcheck

[!NOTE] Stable branches are named as <version> (e.g 0.1) (the master has been reserved for the next release), so, if you plan to build manually the project, do not forget to switch to the appropriate branch before !

How to use

You can use the --help flag to display information about what you can do with this tool. Most of the time, you simply need to indicate the path name to the package or file you want to check.

pyimportcheck /path/to/local/package

You can export any detected notification into a (rudumentary) JSON format with --json followed by the output path. You can also use --json-only to only perform the export without displaying anything:

pyimportcheck /path/to/local/file.py --json-only /path/to/json_output_file.json

Notes

[!TIP] I recommend you resolve each circular dependency in the order that they are displayed. This is because I do not detect if a circular import has already been detected (It will be the case in the future).

So, resolving one circular import can clear, at least, two errors (or more if you have a long loop)

[!CAUTION] This project only supports "absolute" imports from <package> ... import ... and import <package> .... Canonical imports (like from .<module> ... import ...) and special workarounds, like with typing.TYPE_CHEKING, are not supported (ignored for now).

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

pyimportcheck-0.1.6.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyimportcheck-0.1.6-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file pyimportcheck-0.1.6.tar.gz.

File metadata

  • Download URL: pyimportcheck-0.1.6.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for pyimportcheck-0.1.6.tar.gz
Algorithm Hash digest
SHA256 600d43bfee7e6508608aaf453fc8981a5f5784b282eab04da306cb5dd55b0523
MD5 a6c0396dae3b6838d4995d7b8ad60401
BLAKE2b-256 9c744c7515c68e584626f34d44633c38503d2bc8c60be157e0e93679f3ed43a4

See more details on using hashes here.

File details

Details for the file pyimportcheck-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pyimportcheck-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for pyimportcheck-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5b69024cd209363e0224ddc3145e8323b73c6480414753b8594f41431f161a1d
MD5 09cf540e0dd3b4243b612cc0a079672b
BLAKE2b-256 deb8d35db14acecf29a1604f6d7d590ea8400b42a26e856af03e7962c12c1a0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page