-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.envrc
58 lines (50 loc) · 2.3 KB
/
.envrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# .envrc
#
# A complete example that:
# 1) Loads environment variables from a local .env (optional)
# 2) Discovers/creates the Poetry virtual environment
# 3) Activates that environment automatically via direnv
#
# Usage:
# - Create/modify .envrc in your project root
# - Run `direnv allow`
# - On next `cd` into this repo, your Poetry environment is auto-activated
###############################################################################
# 1) OPTIONAL: Load environment variables from a `.env` file
# - If you have a file named `.env` in this directory for secrets or
# general environment variables, the following line will load it.
# - (Requires the direnv stdlib function `dotenv` or do `source .env`)
###############################################################################
dotenv 2>/dev/null
# If you prefer a non-direnv approach, you can do: source .env
###############################################################################
# 2) Poetry environment discovery or creation
# - The snippet below tries to locate an existing Poetry venv via
# `poetry env info --path`.
# - If no venv is found, it runs `poetry install`.
# - Finally, if a venv is located, we run `layout python /path/to/venv/bin/python`.
###############################################################################
use_poetry() {
POETRY_ENV_PATH="$(poetry env info --path 2>/dev/null)"
if [[ -z "$POETRY_ENV_PATH" ]]; then
echo "No existing Poetry venv found. Installing dependencies..."
poetry install
POETRY_ENV_PATH="$(poetry env info --path 2>/dev/null)"
fi
if [[ -z "$POETRY_ENV_PATH" || ! -d "$POETRY_ENV_PATH" ]]; then
echo "Error: Could not locate or create a Poetry environment."
exit 1
fi
# Now actually activate the Python environment:
layout python "$POETRY_ENV_PATH/bin/python"
echo "Poetry env activated at: $POETRY_ENV_PATH"
}
use_poetry
###############################################################################
# 3) OPTIONAL: Additional environment variables or logic
# - Here you can set custom environment variables or run commands.
###############################################################################
# export ETHSCAN_API_KEY="ABCD1234"
# export MY_CUSTOM_FLAG="true"
echo "Quorum environment is now set up! Happy coding."