-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.sh
More file actions
53 lines (44 loc) · 1.22 KB
/
environment.sh
File metadata and controls
53 lines (44 loc) · 1.22 KB
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
# environment.sh - Configure build environment
# Environment
export PROJECT_ROOT=$PWD
export PROJECT_NAME=$(basename $PROJECT_ROOT)
# Python versions
export VERSION=${VERSION:-0.1.0}
export PY_VERSION=$(echo $VERSION | sed 's/-/\.dev0+/')
# Jupyter
export JUPYTER_CONFIG_DIR=${PROJECT_ROOT}/.build/jupyter
export JUPYTER_DATA_DIR=${JUPYTER_CONFIG_DIR}
export JUPYTER_PLATFORM_DIRS=1
# Set mtimes to timestamp of latest commit if project has git repo
if [[ -d .git ]]; then
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
else
unset SOURCE_DATE_EPOCH
fi
# Export variables to temporary .env
tmp_project_env=$(mktemp)
project_variables=(
PROJECT_ROOT
PROJECT_NAME
VERSION
PY_VERSION
JUPYTER_CONFIG_DIR
JUPYTER_DATA_DIR
JUPYTER_PLATFORM_DIRS
SOURCE_DATE_EPOCH
)
for v in "${project_variables[@]}"; do
if [ -n "${BASH_VERSION:-}" ]; then
# For bash
echo "$v=${!v}" >> $tmp_project_env
elif [ -n "${ZSH_VERSION:-}" ]; then
# For zsh
echo "$v=${(P)v}" >> $tmp_project_env
fi
done
# Only update .env if they're different.
# Note: Prevents parallel make processes from stepping on each other.
if [[ ! -f .env ]] || ! cmp -s .env $tmp_project_env; then
echo "Updating .env"
mv $tmp_project_env .env
fi