Skip to main content

Auto-detect project root and provide convenient path accessors for data, models, conf, and logs directories

Project description

path_cfg_manager

A lightweight Python package that auto-detects your project root directory and provides convenience functions for accessing common subdirectories (data/, models/, conf/, logs/).

How It Works

On import, path_cfg_manager determines the project root by:

  1. Checking the ENTRY-FILEPATH environment variable, or
  2. Locating the /src/ segment in sys.argv[0] and using the parent as the project root.

It then automatically adds <project_root>/src to sys.path.

ENTRY-FILEPATH is parsed with the same logic as sys.argv[0], so it should point to a file path under <project_root>/src/.

Installation

pip install path_cfg_manager

Or install from source:

pip install .

Usage

from path_cfg_manager import relative_data_path, relative_conf_path, local_config

# Get absolute path to a file in the data/ directory
csv_path = relative_data_path('input', 'data.csv')

# Get absolute path to a file in the conf/ directory
cfg_path = relative_conf_path('settings.yaml')

# Load and cache a JSON config from conf/
config = local_config('config.json')

API Reference

Path Functions

All path functions accept *args path components and return an absolute path.

Function Base directory
relative_project_path(*args) Project root
relative_data_path(*args) <project>/data/
relative_models_path(*args) <project>/models/
relative_conf_path(*args) <project>/conf/
relative_logs_path(*args) <project>/logs/

local_config(config_name='config.json') -> dict

Loads a JSON file from the conf/ directory and caches it. Subsequent calls with the same filename return the cached result.

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

path_cfg_manager-0.0.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file path_cfg_manager-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for path_cfg_manager-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bf2d0633e26d3caab46af2b12ead35125f59eda394ce3f829b19255a2a8c8d9c
MD5 90dc91deaf894cc4b1984ae41f01afac
BLAKE2b-256 195dff027767c7f823ebf9b820a710aab8f41fb0b8337f17d849b8288b9d73fd

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