autopypath
Table of Contents
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.
It does not read .env files to derive PYTHONPATH because the semantics cannot be consistently interpreted across different operating systems.
For example, consider PYTHONPATH=src:test;lib:
On POSIX, PYTHONPATH is separated by : → ["src", "test;lib"]
On Windows, PYTHONPATH is separated by ; → ["src:test", "lib"]
And the intent may have been ["src", "test", "lib"]
All of those interpretations are “reasonable”, so autopypath avoids guessing what was meant and instead uses pyproject.toml or autopypath.toml for configuration.
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 mitigates path-related ModuleNotFoundError errors, allowing you to debug a specific file without needing the entire project ecosystem to be in a perfect, deployable state.
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:
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:
import autopypath # <--- This line adjusts 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).
Metadata
Release files for autopypath 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autopypath-1.0.1.tar.gz | 234.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autopypath-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 284.4 kB
Release files / autopypath-1.0.1.tar.gz
| Download URL | autopypath-1.0.1.tar.gz |
|---|---|
| Size | 234.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0456c286cd9e7a837e5685effe80878bef7b9b46b37e08668c7d207af22d968b
|
|
BLAKE2b-256 checksum How to use checksums |
6d3df6e2a55f5aba39fcd32195a2fd2b517ed038621e81d6a63a121af668eeaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / autopypath-1.0.1-py3-none-any.whl
| Download URL | autopypath-1.0.1-py3-none-any.whl |
|---|---|
| Size | 49.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97552dd59a2587e793b6645c20ae42b6207e1ac714f94745b226b7a42fab180e
|
|
BLAKE2b-256 checksum How to use checksums |
a051059a09bb98584907036e332a1330c9ac077cb70d7ddf6333536e1f4079ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|