Skip to content

Commit 952afe0

Browse files
author
Marc Henry de Frahan
committed
Set scratch directory and optional large install directory
1 parent 482e62b commit 952afe0

12 files changed

Lines changed: 73 additions & 23 deletions

.chezmoi.toml.tmpl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,43 @@
1717
{{ $ornl_hpc = true -}}
1818
{{- end -}}
1919

20+
{{/* Set scratch_root automatically based on system type */}}
21+
{{ $scratch_root := "${HOME}" -}}
22+
{{- if $nrel_hpc -}}
23+
{{ $scratch_root = "/scratch/${USER}" -}}
24+
{{- else if $ornl_hpc -}}
25+
{{ $scratch_root = "/lustre/orion/${USER}" -}}
26+
{{- end -}}
27+
28+
{{/* Prompt for large install directory (pyenv, virtualenvs) */}}
29+
{{- $use_large_install_dir := false -}}
30+
{{- $large_install_dir := "${HOME}" -}}
31+
{{- if hasKey . "use_large_install_dir" -}}
32+
{{- $use_large_install_dir = .use_large_install_dir -}}
33+
{{- else if stdinIsATTY -}}
34+
{{- $use_large_install_dir = promptBoolOnce . "use_large_install_dir" "Install large executables in non-default location" -}}
35+
{{- end -}}
36+
{{- if $use_large_install_dir -}}
37+
{{- $default_install_dir := printf "%s/install" $scratch_root -}}
38+
{{- if and (hasKey . "large_install_dir") .large_install_dir -}}
39+
{{- $large_install_dir = .large_install_dir -}}
40+
{{- else if stdinIsATTY -}}
41+
{{- $large_install_dir = promptStringOnce . "large_install_dir" (printf "Large install directory [%s]" $default_install_dir) -}}
42+
{{- if not $large_install_dir -}}
43+
{{- $large_install_dir = $default_install_dir -}}
44+
{{- end -}}
45+
{{- else -}}
46+
{{- $large_install_dir = $default_install_dir -}}
47+
{{- end -}}
48+
{{- end -}}
49+
2050
[data]
2151
use_zsh_root_dir = {{ $use_zsh_root_dir }}
2252
email = {{ $email | quote }}
2353
test_machine = {{ $test_machine }}
2454
spack_packages = false
2555
nrel_hpc = {{ $nrel_hpc }}
2656
nrel_cluster = {{ $nrel_cluster }}
27-
ornl_hpc = {{ $ornl_hpc }}
57+
ornl_hpc = {{ $ornl_hpc }}
58+
scratch_root = {{ $scratch_root | quote }}
59+
large_install_dir = {{ $large_install_dir | quote }}

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
git clone --depth 1 --branch "${{ github.head_ref || github.ref_name }}" https://github.com/marchdf/dotfiles.git "$HOME/.local/share/chezmoi"
3838
- name: Install
3939
run: |
40-
chezmoi init --source="$HOME/.local/share/chezmoi" --promptBool test_machine=t,"Use ZSH_ROOT_DIR for tmux shell"=f --promptString email=""
40+
chezmoi init --source="$HOME/.local/share/chezmoi" --promptBool test_machine=t,"Use ZSH_ROOT_DIR for tmux shell"=f,use_large_install_dir=f --promptString email=""
4141
chezmoi data
4242
chezmoi apply
4343
- name: Cold start zsh
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
source ~/.zshrc
6060
for TOOL in python pyenv uv poetry zoxide fzf bat; do
61-
if [[ ! -x "$(command -v ${TOOL})" ]]; then
61+
if [[ ! $(type ${TOOL} 2>/dev/null) ]]; then
6262
echo "${TOOL} not found!"
6363
exit 1
6464
else

bin/executable_png2eps.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ YRES=`echo $CHK | sed -ne '/pHYs/s/.*x\([0-9]*\) pixels\/meter.*/\1/p;'`
5050
# we ignore it (like pdfTeX does)
5151

5252
# set the command-line arguments for pnmtotiff which specify the resolution
53-
if [ "$RES" ] ; then
53+
if [[ "$RES" ]]; then
5454
echo "png2eps: Image with square pixels ($RES dpi)" 1>&2
5555
RES='-xres '$RES' -yres '$RES
5656
fi
57-
if [ -z "$RES" ] ; then
58-
if [ "$XRES" ] ; then
57+
if [[ -z "$RES" ]]; then
58+
if [[ "$XRES" ]]; then
5959
echo "png2eps: Image with non-square pixels" \
6060
"($XRES""x$YRES pixels/meter)" 1>&2
6161
# we still have to convert pixels/meter -> dpi

bin/executable_teatimer.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
# Make a tea timer display a notification
44
# Input the time, defaults to 3 minutes
55

6-
if [ -z "$1" ];
7-
then
6+
if [[ -z "$1" ]]; then
87
TIME="3m";
98
else
109
TIME=$1;
1110
fi
1211

1312
# Notification for Mac platform
14-
if [ "$(uname)" == "Darwin" ]; then
13+
if [[ "$(uname)" == "Darwin" ]]; then
1514

1615
# Wait the specified time (need to brew install coreutils)
1716
gsleep "$TIME";
@@ -38,7 +37,7 @@ if [ "$(uname)" == "Darwin" ]; then
3837

3938

4039
# Notification for GNU/Linux platform
41-
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
40+
elif [[ "$(uname -s)" == "Linux" ]]; then
4241

4342
# Wait the specified time
4443
sleep "$TIME";

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ENV PATH="/home/$USERNAME/.local/bin:${PATH}"
5050

5151
# Initialize chezmoi with dotfiles from GitHub
5252
RUN chezmoi init https://github.com/marchdf/dotfiles.git \
53-
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f \
53+
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f,use_large_install_dir=f \
5454
--promptString email="marchdf@docker-container.com" \
5555
&& chezmoi apply
5656

docker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ docker compose run --rm ubuntu-test
2323

2424
# Inside container - first time setup:
2525
chezmoi init --source /dotfiles-source \
26-
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f \
27-
--promptString email="test@docker.com"
26+
--promptBool test_machine=f,"Use ZSH_ROOT_DIR for tmux shell"=f,use_large_install_dir=f \
27+
--promptString email="marchdf@docker-container.com"
2828
chezmoi apply
2929

3030
# Iterating on changes (edit files on host, then in container):

dot_local/share/zinit/plugins/hpc/hpc.plugin.zsh.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Plugins[PERSONAL_DIR]="${0:h}"
2222
# Custom for NREL HPC machines
2323

2424
# Set scratch
25-
if [ -d "/scratch/${USER}" ]; then
26-
export SCRATCH="/scratch/${USER}"
25+
if [ -d "{{ .scratch_root }}" ]; then
26+
export SCRATCH="{{ .scratch_root }}"
2727
fi
2828

2929
# Set the modules

dot_zshrc.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export COMBUSTION_DIR="${HOME}/combustion"
8181
export MASA_HOME="${COMBUSTION_DIR}/install/MASA"
8282

8383
# pyenv
84-
export PYENV_ROOT="${HOME}/.local/${ARCH}/pyenv"
84+
export PYENV_ROOT="{{ .large_install_dir }}/.local/${ARCH}/pyenv"
8585
if [ -d "${PYENV_ROOT}" ]; then
8686
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
8787
eval "$(pyenv init -)"
@@ -109,7 +109,7 @@ if [[ -x "$(command -v claude)" ]]; then
109109
export CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS=50000
110110
fi
111111

112-
export WORKON_HOME="${HOME}/.local/${ARCH}/virtualenvs"
112+
export WORKON_HOME="{{ .large_install_dir }}/.local/${ARCH}/virtualenvs"
113113

114114
{{- if eq .chezmoi.os "darwin" }}
115115

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ set -e
55
PYTHON_VERSION="3.12.9"
66

77
ARCH=$(uname -m)
8-
export PYENV_ROOT="${HOME}/.local/${ARCH}/pyenv"
9-
export WORKON_HOME="${HOME}/.local/${ARCH}/virtualenvs"
8+
9+
# Ensure large install directory is writable
10+
if [[ ! -d "{{ .large_install_dir }}/.local/${ARCH}" ]]; then
11+
if ! mkdir -p "{{ .large_install_dir }}/.local/${ARCH}" 2>/dev/null; then
12+
echo "ERROR: Cannot create {{ .large_install_dir }}/.local/${ARCH}"
13+
echo "Check that the install directory is accessible"
14+
exit 1
15+
fi
16+
fi
17+
18+
export PYENV_ROOT="{{ .large_install_dir }}/.local/${ARCH}/pyenv"
19+
export WORKON_HOME="{{ .large_install_dir }}/.local/${ARCH}/virtualenvs"
1020

1121
# Install pyenv if not present
1222
if [[ ! -x "$(command -v pyenv)" ]] && [[ ! -d "${PYENV_ROOT}" ]]; then
@@ -15,7 +25,7 @@ if [[ ! -x "$(command -v pyenv)" ]] && [[ ! -d "${PYENV_ROOT}" ]]; then
1525
fi
1626

1727
# Initialize pyenv
18-
if [ -d "${PYENV_ROOT}" ]; then
28+
if [[ -d "${PYENV_ROOT}" ]]; then
1929
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
2030
eval "$(pyenv init -)"
2131
fi

run_before_install-packages-cli.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARCH=$(uname -m)
44
ARCH_BIN="${HOME}/.local/${ARCH}/bin"
55
mkdir -p "${ARCH_BIN}"
66

7-
if [ ! -d "${HOME}/.oh-my-zsh" ]; then
7+
if [[ ! -d "${HOME}/.oh-my-zsh" ]]; then
88
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc
99
fi
1010

0 commit comments

Comments
 (0)