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 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 allows custom root file indicators, avoids recursive "/" is parent of "/" issue and can use the current file location to start walking the directory tree.

Usage

Installation:

pip install py-repo-root

Usage

Get project root

from pathlib import Path
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 pathlib import Path
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 pathlib import Path
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-1.1.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

py_repo_root-1.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-repo-root-1.1.1.tar.gz
  • Upload date:
  • Size: 2.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

Hashes for py-repo-root-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ddcf72a573e5b20dfdcf4b6a187869ddff93f3b1f8d0b8fa0217907cec4b6e5d
MD5 aea9f8b64b6424296b216f7eed39e80e
BLAKE2b-256 b101aef34d9fb7138a60f46774a7f3f4d6161cc148890ba5dd350b6d2357b2e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_repo_root-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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

Hashes for py_repo_root-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e87093be00fc7431ace50e695ec179241a051c4348ff51331ebcefb28f795f6
MD5 0314d49f8e60acf1c3185486a9d9af1e
BLAKE2b-256 81612fc19cace26efbcc5d5a95d96cd7e77604d099fb523d2e141851a1c7d9fc

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