Skip to content
/ envidia Public
forked from luocfprime/envidia

Project level environment variable management utility.

License

Notifications You must be signed in to change notification settings

lbllyl/envidia

 
 

Repository files navigation

Envidia

Unit Tests Python Versions PyPI

Envidia is a command-line interface (CLI) tool for loading project-level environment variables and simplifying the setting of long environment variables with aliases.

Table of Contents

Install

To install Envidia, use pip:

pip install envidia

Features

1. Loading .env from a directory

Envidia allows you to load environment variables from a directory, replacing long and verbose declarations with simple commands.

load-demo

2. Set Environment Variables via Alias

Setting environment variables manually can be cumbersome. Envidia provides a convenient way to set them via alias.

❌: export CUDA_VISIBLE_DEVICES="0"

✅: source <(e --cuda 0) or simply es --cuda 0 if you have eval $(envidia install) in your .bashrc or .zshrc.

Put the following line in your .bashrc or .zshrc:

eval "$(envidia install --alias es)"

Specify which option is related to which environment variable in env.d/bootstrap.py:

from envidia import register_option

register_option("cuda", "CUDA_VISIBLE_DEVICES", default="0")

Use es to set environment variables specified in env.d. ( es is short for "env set").

alias-demo

3. Integration with Cookiecutter

Pack your project environment variables as a cookiecutter template to reuse them across different projects.

cookiecutter-demo

4. Pre-load and Post-load Hooks

Use hooks to verify path variables or add extra variables into the environment.

# env.d/bootstrap.py
from pathlib import Path

from envidia import Loader, register_option

register_option("cuda", "CUDA_VISIBLE_DEVICES", default="0")
register_option("foo", "FOO_PATH", default=".")


def pre_load(loader: Loader):
    # add extra variable into the environment
    # if hf_transfer is installed, set HF_TRANSFER=1
    if is_package_installed("hf_transfer"):
        loader.env_registry["HF_TRANSFER"] = "1"
    else:
        loader.env_registry["HF_TRANSFER"] = "0"


def post_load(loader: Loader):
    # validate a path must exist
    if not Path(loader.env_registry.get("FOO_PATH", "")).exists():
        raise RuntimeError("FOO_PATH must exist")

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Project level environment variable management utility.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 93.2%
  • Makefile 6.7%
  • Shell 0.1%