Skip to main content

Automatic path management for testing and development.

Project description

Build Status Coverage Status Documentation Status PyPI Version Python Versions License Ruff

What is autopypath?

autopypath is a library that simplifies the management of the Python module search path (sys.path) for testing and development environments.

It automatically detects your project root (via .git, pyproject.toml, etc.) and intelligently adds source directories to sys.path at runtime.

The Problem it Solves

In active development, builds are often broken. Standard test runners (like pytest or tox) often refuse to start if they cannot import the entire package, or if the package hasn’t been re-installed into the virtual environment after a structural change.

autopypath allows you to run individual tests or scripts in isolation, even if:

  • The project build is currently broken.

  • The package is not installed in the current environment.

  • Other parts of the test suite are failing due to ongoing refactoring.

It is not a replacement for virtual environments, but a resilience tool. It dynamically fixes “Module Not Found” errors on load, allowing you to debug a specific file without needing the entire project ecosystem to be in a perfect, deployable state.

Documentation

Installation

Installing from PyPI

pip install autopypath

Installing from Source

git clone https://github.com/JerilynFranz/python-autopypath.git
cd python-autopypath
pip install .

Development Installation

For development purposes, you can install autopypath in editable mode. To make this easier, a bootstrap.py script is provided.

git clone https://github.com/JerilynFranz/python-autopypath.git
cd python-autopypath
python3 bootstrap.py
source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`

This script will: 1. Set up the development environment (uv sync). 2. Install autopypath in editable mode. 3. Install Git hooks for pre-commit checks. 4. Install development tools like tox, sphinx, and ruff.

Usage

Simply import autopypath at the top of your test script. It will automatically detect the project root and adjust sys.path accordingly (by default adding src, lib, src/tests, and tests directories if they exist).

It does not add ‘.’ to sys.path by default to avoid conflicts with subdirectories that are NOT intended to be packages, but if you want to include the repo root directory, you can configure it via pyproject.toml or autopypath.toml.

Here is an example tests/my_test_script.py:

import autopypath  # <--- This line magics the sys.path
import pytest

# Now these imports work without installing the package
import mypackage.my_module

if __name__ == '__main__':
    pytest.main([__file__])

You can now run this file directly:

python tests/my_test_script.py

Configuration

autopypath automatically detects pyproject.toml. You can configure it by adding a [tool.autopypath] section.

Example `pyproject.toml`:

[tool.autopypath]
paths = ["lib", "src/tests", ".", "src"]

If you do not use pyproject.toml, you can create an autopypath.toml file either in your root directory or in subdirectories such as src or tests and it will be detected automatically. This can be useful for monorepos or multi-package repositories and allows customization of sys.path per sub-project or for detection of the project root in non-standard layouts.

Example `autopypath.toml`:

[tool.autopypath]
paths = ["src", "src/lib", "tests"]
repo_markers = {".git" = "dir"}

This file can be placed in the root of your project or in any directory that is a parent of your test scripts (but still inside the repo).

You can use it to customize which directories are added to sys.path, or to specify custom repository markers for detecting the project root as well as other settings affecting path resolution behavior.

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

autopypath-0.9.1.tar.gz (232.0 kB view details)

Uploaded Source

Built Distribution

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

autopypath-0.9.1-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file autopypath-0.9.1.tar.gz.

File metadata

  • Download URL: autopypath-0.9.1.tar.gz
  • Upload date:
  • Size: 232.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for autopypath-0.9.1.tar.gz
Algorithm Hash digest
SHA256 868907f7e151d4883fc491fc943ab383d80e8b78091994e58ce21f2360c5f37b
MD5 c5834ba32bd882b88fa9d2c3ed9d7494
BLAKE2b-256 c392737b4186f0abd14b42c26ad55f66b80c6b7e9b2b8cc2b51ff855ee6fb5ff

See more details on using hashes here.

File details

Details for the file autopypath-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: autopypath-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for autopypath-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e96a1a2c46e700f1787f860e2c0d464a92446b37c85e7a97e503d1a1fc67e5f8
MD5 61293989b4ebb0ca5e03404cfe3c62a3
BLAKE2b-256 c65f4c96285ae74a7fff353c458bf85c2cc61183c6d8633f932494960d691740

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