chore: SAVEPOINT

This commit is contained in:
2026-04-20 16:32:27 -04:00
parent 4728c0b62a
commit 6d977f5e35
12 changed files with 707 additions and 17 deletions
+86 -11
View File
@@ -5,8 +5,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_PYTHON="$SCRIPT_DIR/.venv/bin/python3"
if [ -f "$SCRIPT_DIR/.env" ]; then
# shellcheck source=/dev/null
source "$SCRIPT_DIR/.env"
# shellcheck source=/dev/null
source "$SCRIPT_DIR/.env"
fi
init_paper() {
@@ -14,6 +14,10 @@ init_paper() {
local name
name="$(printf '%s' "$raw" | tr '[:upper:]' '[:lower:]' | tr -d '\\' | tr '[:space:]' '_')"
local dest="$SCRIPT_DIR/$name"
if [ -d "$dest" ]; then
echo "Error: '$dest' already exists" >&2
exit 1
fi
mkdir -p "$dest"
cp "$SCRIPT_DIR/ams-latex-template/doc/amsart-template.tex" "$dest/paper.tex"
sed -i '' "s|\\\\title{}|\\\\title{$raw}|" "$dest/paper.tex"
@@ -23,20 +27,20 @@ init_paper() {
}
setup() {
local python_path="${1:?Usage: setup <python_path> <sage_site_packages> <system_name>}"
local sage_site_packages="${2:?Usage: setup <python_path> <sage_site_packages> <system_name>}"
local system_name="${3:?Usage: setup <python_path> <sage_site_packages> <system_name>}"
local sage_python_path="${1:-${SAGE_PYTHON_PATH:?Usage: setup <sage_python_path> <sage_site_packages> <system_name>}}"
local sage_site_packages="${2:-${SAGE_SITE_PACKAGES:?Usage: setup <sage_python_path> <sage_site_packages> <system_name>}}"
local system_name="${3:-$(hostname -s)}"
printf 'SAGE_PYTHON_PATH=%s\nSAGE_SITE_PACKAGES=%s\n' "$python_path" "$sage_site_packages" \
> "$SCRIPT_DIR/.env.$system_name"
printf 'SAGE_PYTHON_PATH=%s\nSAGE_SITE_PACKAGES=%s\n' "$sage_python_path" "$sage_site_packages" \
>"$SCRIPT_DIR/.env.$system_name"
ln -sf ".env.$system_name" "$SCRIPT_DIR/.env"
source "$SCRIPT_DIR/.env"
mkdir -p "$SCRIPT_DIR/.vscode"
"$python_path" - <<EOF
"$sage_python_path" - <<EOF
import json
settings = {
"python.defaultInterpreterPath": "$python_path",
"python.defaultInterpreterPath": "$sage_python_path",
"python.analysis.extraPaths": ["$sage_site_packages"],
"python.analysis.diagnosticSeverityOverrides": {
"reportUnknownMemberType": "warning",
@@ -51,10 +55,16 @@ with open("$SCRIPT_DIR/.vscode/settings.json", "w") as f:
f.write("\n")
EOF
"$python_path" -m venv "$SCRIPT_DIR/.venv"
make -C "$SCRIPT_DIR/plantri"
"$sage_python_path" -m venv "$SCRIPT_DIR/.venv"
"$VENV_PYTHON" -m pip install -r "$SCRIPT_DIR/requirements.txt"
}
run_sage() {
PATH="$PATH:$SCRIPT_DIR/plantri" sage "$@"
}
lint() {
"$VENV_PYTHON" -m pyright lib/ --pythonpath "$SAGE_PYTHON_PATH"
"$VENV_PYTHON" -m pylint lib/ \
@@ -62,6 +72,63 @@ lint() {
--disable=fixme
}
completion() {
local shell="${1:-zsh}"
case "$shell" in
zsh)
cat <<'EOF'
_run_sh() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'1: :->subcmd' \
'*: :->args'
case $state in
subcmd)
local subcmds=(
'init_paper:Initialize a new paper directory from the AMS template'
'setup:Configure Python/Sage environment and install dependencies'
'sage:Run sage with plantri available on PATH'
'lint:Run pyright and pylint on lib/'
'completion:Output shell completion code'
)
_describe 'subcommand' subcmds
;;
args)
case $words[2] in
init_paper)
_message 'paper title (spaces become underscores)'
;;
setup)
case $((CURRENT - 2)) in
1) _files ;;
2) _files -/ ;;
3) _message 'system name (e.g. macbook, workstation)' ;;
esac
;;
sage)
_files
;;
completion)
_values 'shell' 'zsh'
;;
esac
;;
esac
}
compdef _run_sh run.sh
EOF
;;
*)
echo "Unsupported shell: $shell. Supported: zsh" >&2
exit 1
;;
esac
}
case "${1:-}" in
init_paper)
shift
@@ -71,11 +138,19 @@ setup)
shift
setup "$@"
;;
sage)
shift
run_sage "$@"
;;
lint)
lint
;;
completion)
shift
completion "$@"
;;
*)
echo "Usage: $0 {init_paper|setup|lint} [args]" >&2
echo "Usage: $0 {init_paper|setup|sage|lint|completion} [args]" >&2
exit 1
;;
esac