Skip to main content

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


Download files

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

Source Distribution

py-repo-root-0.4.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

py_repo_root-0.4.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page