Skip to main content

Python utility for cleaner handling of paths

Project description

Introduction

This package standardizes the handling of paths in a Python project by allowing all paths to be relative to the project repo root. The package discovers the project root based on the location of a special (empty) .py-repo-root file. The project root indicator can be overriden with a custom one, if desired.

This package was heavily inspired by pyprojroot. This package allows custom root file indicators, avoids recursive "/" is parent of "/" issue and can use the current file location to start walking the directory tree.

Setup

Installation:

pip install py-repo-root

Usage

Get project root, using the default list of project root indicators

from pyreporoot import project_root

project_root_dir = project_root(__file__)

Specify a custom project root indicator (not included in the list above)

project_root_dir = project_root(__file__, root_files='.my-root-indicator')

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, project_root(__file__))

Getting a relative path from the project root for a file:

from pathlib import Path
from projectroot import project_root

project_root_dir = project_root(__file__)
path_rel_to_project_root = Path(project_root_dir).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-2.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

py_repo_root-2.0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file py-repo-root-2.0.1.tar.gz.

File metadata

  • Download URL: py-repo-root-2.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for py-repo-root-2.0.1.tar.gz
Algorithm Hash digest
SHA256 1216a5ddea54e1fea25a5e108fe7056ff09356e294813008d8e89db6d558f418
MD5 57abe71c06ad77a26d8370b8ac9da2f2
BLAKE2b-256 edce1e74b7517ea17aa00cffe62b139dbc904494fd56a4f5e4b8cfbde11847a7

See more details on using hashes here.

File details

Details for the file py_repo_root-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_repo_root-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for py_repo_root-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebdb8f5dc6b45bb890d493c9f14c63d79c029b31cb97ada989fcfcef3acc06fe
MD5 47bf624a7049df25150e0cefba4941d5
BLAKE2b-256 ee08813653d0ee306dc564ac4ba0f0fab6171f8769e0aedaf63c6da64e21a67e

See more details on using hashes here.

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