Skip to main content

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-hack
  • uv 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syspath_hack-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

syspath_hack-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file syspath_hack-0.1.0.tar.gz.

File metadata

  • Download URL: syspath_hack-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for syspath_hack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3107a8300037e23436c73cdaf6413b3b8f5f77986025c850a36bcb734e373d8
MD5 85bba54b5941205871c9d351ae69a86b
BLAKE2b-256 b73fa3bc52c0dcd21cabe89d29c5c69ea7bbd2a830c8a55924c0a685ec8f53a7

See more details on using hashes here.

File details

Details for the file syspath_hack-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for syspath_hack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09a894f3dc2c5db27f1259c90745a67af4fcf54ad7f7f6fad5154ec18ca5b4fb
MD5 2caa0727ad2b1bb9086454b427a49928
BLAKE2b-256 39f1dcbdbf7ddfd69160921d801534ee7ba0aa4531b64f95522c6642b4313649

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