Utilities for locating project roots and keeping sys.path tidy
Project description
syspath-hack
syspath-hack provides small helpers for keeping sys.path predictable in
scripts, notebooks, and tests. It resolves entries before adding them, avoids
duplicates, and can locate your project root with a marker file such as
pyproject.toml.
Installation
Install from PyPI with your preferred tool:
pip install syspath-hackuv add syspath-hack
Quick start
Add the project root to sys.path so local imports work during ad-hoc scripts
or notebooks:
from syspath_hack import add_project_root
add_project_root() # finds the nearest pyproject.toml above the cwd
Working with temporary paths
When you need to add a directory for a short time, pair add_to_syspath with
remove_from_syspath to leave sys.path tidy:
from pathlib import Path
from syspath_hack import add_to_syspath, remove_from_syspath
plugins_dir = Path(__file__).parent / "plugins"
add_to_syspath(plugins_dir)
try:
import plugin_loader # noqa: F401
finally:
remove_from_syspath(plugins_dir)
Custom project markers
You can search for a different marker file and handle failures explicitly:
from syspath_hack import ProjectRootNotFoundError, find_project_root
try:
repo_root = find_project_root("poetry.lock")
except ProjectRootNotFoundError as err:
raise SystemExit(f"Could not locate the repository: {err}") from err
else:
print(repo_root)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file syspath_hack-0.2.0.tar.gz.
File metadata
- Download URL: syspath_hack-0.2.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b23b7875b51e9dea7b3a4aae0b968412b04053b0b7f82458a4597a5044d182a7
|
|
| MD5 |
75601a4742f7631557496cc678e3e3ff
|
|
| BLAKE2b-256 |
058692c7181c80b359b2059a072dfd5f83fa30a8d250298acc37d6e65779d1b9
|
File details
Details for the file syspath_hack-0.2.0-py3-none-any.whl.
File metadata
- Download URL: syspath_hack-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ccd874fa054fbaa8943c5def4c1b81c595536cc78f32a0cc28d263eb56bd06
|
|
| MD5 |
3191106bb2ae124d09484f8c5c9dcae3
|
|
| BLAKE2b-256 |
bae414243d41bc1c7b5abc539732747df0bf888c8b00abdd91ab0e3902bc40b8
|