Skip to main content

Find dirs which appear to be broken python packages, as a pre-commit hook.

Project description

Latest PyPI version Build Status

Find dirs which appear to be broken python packages, i.e. dirs which contain *.py files without the necessary

Suggested use is to run as a Pre-commit hook.


In your main code it’s unlikely to have orphan modules since they are not importable and likely a cause of visible errors.

However in your unit tests, particularly if you have a lot of tests, you may find orphans. They go undetected because while developing you maybe pass the full path to the orphan to your test runner, and it works. But when you run the full suite of tests the orphans won’t be found and so you have tests which aren’t running!

By running pyorphans as a pre-commit hook you can catch the orphans and fix them immediately.

CLI Usage

pip install pyorphans

This will install a console script pyorphans.

To run the checker, just pass it a list of the root packages in your project:

pyorphans tests myproject

It returns output like:



We can see here that tests/unit dir is missing an but contains

Also tests/integration/important_stuff and tests/integration/important_stuff/api dirs are both missing their files. Inside both directories is found a single ‘orphan’ file, tests/integration/important_stuff/api/

Say you get an output like:


Maybe scripts is not intended to be a package and is a perfectly good standalone script that runs from the command-line.

In this case create a .pyorphans_ignore file in the root of your project (the dir that pyorphans will be run from), containing:


Now myproject/scripts (and all its subdirs) will be excluded from the search for orphans.

Pre-commit Hook

We suggest using Pre-commit.

pip install pre-commit

Pyorphans is configured as a Pre-commit plugin. To apply it to your project, add a .pre-commit-config.yaml file to the root of your project like so:

  - repo:
    rev: "0.2.0"
    - id: pyorphans
        - myproject
        - tests

Now every time you commit, Pyorphans will run and ask you to fix any that it finds. Pyorphans runs fast so you’ll hardly notice it’s there!

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

pyorphans-0.2.2.tar.gz (4.2 kB view hashes)

Uploaded Source

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