Python utility for cleaner handling of paths
Project description
Introduction
his package standardizes the handling of paths in a Python project by
allowing all paths to be relative to the project repo root.
The package also helps discover the project root automatically
based on the location of the file that invokes it and a user-specified
(or commonly used) project root indicator files such as requirements.txt
.
This package was heavily inspired by pyprojroot. Our version fixes some of the issues in the original.
Usage
Installation:
pip install py-repo-root
Usage
Get project root
from pyreporoot import project_root
project_root_dir = project_root(Path(__file__), root_files='requirements.txt')
Another common usage pattern may be to add the project_root to PYTHONPATH for the purposes of running some scripts.
import sys
from pyreporoot import project_root
sys,path.insert(0, str(project_root(Path(__file__), root_files='requirements.txt')))
Getting a relative path from the project root for a file:
from projectroot import project_root
path_to_file_from_project_root = project_root(Path(__file__), root_files='requirements.txt').joinpath('/path/to/file.txt')
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
File details
Details for the file py-repo-root-0.3.0.tar.gz
.
File metadata
- Download URL: py-repo-root-0.3.0.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2849b3a896e1cdac42d4a75cc17ac133da80dc5262385d6dad687e5914930822 |
|
MD5 | 4f4170968868a85950464e720d8e29fd |
|
BLAKE2b-256 | c8ff7cb952852c042b799f172af118e60033ed8b59a10127475d364e68cf6694 |
File details
Details for the file py_repo_root-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: py_repo_root-0.3.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9478b3670c6dafe36edc5abba446fbc76ea61b5ed7e8f02111dd9d91573d2e1 |
|
MD5 | 3c1fd2e59a387984b1b40e79c6b220a3 |
|
BLAKE2b-256 | 1115369b76d46d695f4eb5fc2f1f95d358816b22b07ac51426137b6b8712e3b4 |