Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update marimo subcommand #274

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ bin_PROGRAMS =
bin_SCRIPTS =
dist_doc_DATA =

docs_targets = docs/Utilities

check-target:
@test $(prefix) = $(shell $(top_srcdir)/build-aux/version.sh --install) || ( echo "ERROR [Makefile]: prefix '$(prefix)' and target '($(shell $(top_srcdir)/build-aux/version.sh --install))' mismatch; ./configure is outdated. Build using '--clean' option to fix this." > /dev/stderr ; false )

Expand Down Expand Up @@ -331,7 +329,5 @@ documents/gridlabd.pdf: documents/gridlabd.glm
(cd documents ; $(DESTDIR)$(bindir)/gridlabd gridlabd.glm | echo "WARNING: unable to update documents/gridlabd.pdf")
test -f documents/gridlabd.md && pandoc -V geometry:landscape documents/gridlabd.md -o documents/gridlabd.pdf

docs: $(docs_targets) # documents/gridlabd.pdf

docs_toc:
utilities/regen_toc >'docs/User manual/0 - Cover/1 - Contents.md'
20 changes: 11 additions & 9 deletions docs/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

DOCS =
DOCS += docs/Utilities/Framework.md
DOCS += docs/Utilities/Network.md
DOCS += docs/Utilities/Edit.md
DOCS += docs/Utilities/Mapping.md
DOCS += docs/Utilities/Unitcalc.md
docs: docs/Utilities

DOCS_UTILITIES =
DOCS_UTILITIES += docs/Utilities/Framework.md
DOCS_UTILITIES += docs/Utilities/Network.md
DOCS_UTILITIES += docs/Utilities/Edit.md
DOCS_UTILITIES += docs/Utilities/Mapping.md
DOCS_UTILITIES += docs/Utilities/Unitcalc.md

docs/Utilities: $(DOCS_UTILITIES)
echo "Updating $@..."

%.md: FORCE
echo "Updating $@"
$(DESTDIR)$(bindir)/gridlabd python docs/makemd.py $(basename $(notdir $(shell echo "$@" | tr 'A-Z' 'a-z'))) $(dir $@)

docs/Utilities: $(DOCS)

FORCE:
87 changes: 69 additions & 18 deletions subcommands/gridlabd-marimo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
##
## Syntax: gridlabd marimo [OPTIONS ...] [COMMAND] [NOTEBOOK]
##
## Options:
Expand All @@ -9,6 +10,8 @@
##
## * `--pid`: get the process id for the notebook (if any)
##
## * `-R|--repo`: change marimo repository (default `arras-energy/marimo`)
##
## * `--upgrade`: upgrade marimo to latest version
##
## * `--url`: get the URL for the notebook (if any)
Expand All @@ -17,6 +20,8 @@
##
## * `--wait`: wait for marimo server to exit
##
## * `-W|--workdir`: change work directory (default `gridlabd-marimo`)
##
## Commands:
##
## * `edit NOTEBOOK`: open the notebook in the marimo editor
Expand All @@ -25,6 +30,8 @@
##
## * `list`: list open marimo notebooks
##
## * `status`: list details of active notebooks
##
## * `stop NOTEBOOK`: stops the marimo notebook
##
## Run a gridlabd marimo notebook.
Expand Down Expand Up @@ -53,15 +60,26 @@

LIB=$GLD_ETC/marimo
LOG=$LIB/marimo.log
URL=https://raw.githubusercontent.com/arras-energy/marimo/refs/heads/main/source
WAIT=no
WORKDIR=gridlabd-marimo

E_OK=0
E_SYNTAX=1
E_FAIL=2
E_NOTFOUND=3
E_MISSING=4

function repo()
{
if [ $# -eq 0 ]; then
error "missing repo name" E_MISSING
fi
URL=https://raw.githubusercontent.com/$1/refs/heads/main/source
API=https://api.github.com/repos/$1/contents/source
GIT=https://github.com/$1
}
repo arras-energy/marimo

function error()
{
# error MESSAGE [EXITCODE]
Expand Down Expand Up @@ -90,13 +108,13 @@ function index()
if [ "$(gridlabd.bin --version=branch)" == "master" ]; then
curl -sL -H 'Cache-Control: no-cache' $URL/.index 2>>$LOG
else
curl -sL -H 'Cache-Control: no-cache' https://api.github.com/repos/arras-energy/marimo/contents/source 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n"
curl -sL -H 'Cache-Control: no-cache' $API 2>>$LOG | grep '"name": ".*\.py",' | cut -f2 -d: | cut -f1 -d. | tr -cd "A-Za-z0-9_\\n"
fi
}

function getlist()
{
basename -s .py $(ps -ax | grep bin/marimo | grep -v grep | sed -r 's/ +/ /g' | cut -f7 -d' ') 2>>$LOG
basename -s .py $(ps -ax | grep bin/marimo | grep -v grep | sed -r 's/ +/ /g' | rev | cut -f1 -d'/' | rev ) 2>>$LOG
}

function getpid()
Expand All @@ -105,13 +123,6 @@ function getpid()
ps ax | grep bin/marimo | grep $EXE | cut -f1 -d' ' 2>>$LOG
}

function getinfo()
{
for PID in $*; do
lsof -i -P -a -p $PID | tail -n +1 2>>$LOG
done
}

function geturl()
{
PID=$(getpid $1)
Expand Down Expand Up @@ -175,20 +186,30 @@ function edit()
elif [ "$(gridlabd.bin --version=branch)" == "master" ]; then
error "you must use a development version of gridlabd" E_FAIL
fi
if [ -d gridlabd-marimo ]; then
( cd gridlabd-marimo ; git pull )
if [ -d "$WORKDIR" ]; then
ORIGIN=$(cd "$WORKDIR"; git remote get-url origin)
if [ "$URL" != "$ORIGIN" ]; then
warning "repository '$GIT' does not match '$WORKDIR' origin '$ORIGIN', unable to pull"
elif [ ! -d "$WORKDIR/.git" ]; then
warning "'$WORKDIR' is not a git repository (you cannot commit changes), unable to pull"
else
( cd "$WORKDIR" ; git pull )
fi
else
git clone https://github.com/arras-energy/marimo gridlabd-marimo
git clone $GIT "$WORKDIR" || error "clone failed" E_FAIL
fi
if [ ! -d gridlabd-marimo/source ]; then
if [ ! -d "$WORKDIR/source" ]; then
error "clone failed" E_FAIL
else
if [ ! -f gridlabd-marimo/source/$1.py ]; then
echo "Creating gridlabd-marimo/source/$1.py"
if [ ! -f "$WORKDIR/source/$1.py" ]; then
echo "Creating '$WORKDIR/source/$1.py'"
fi
( cd gridlabd-marimo/source ; marimo edit $1.py )
echo "Opening marimo notebook..." >/dev/stderr
( cd "$WORKDIR/source" ; marimo edit "$1.py" )
fi
if [ -d "$WORKDIR/.git" ]; then
warning "don't forget to add/commit/push changes to '$WORKDIR' when done editing"
fi
warning "don't forget to add/commit/push when done editing"
}

function open()
Expand All @@ -203,6 +224,21 @@ function open()

}

function status()
{
LIST=$(getlist)
if [ ! -z "$LIST" ]; then
FORMAT="%-16.16s %-6.6s %-32.32s\n"
printf "$FORMAT" Name PID URL
printf "$FORMAT" ---------------- ------ --------------------------------
for APP in $LIST; do
APPPID=$(getpid $APP)
APPURL=$(geturl $APP)
printf "$FORMAT" $APP $APPPID $APPURL
done
fi
}

mkdir -p $LIB/.etag
echo "*** COMMAND = '$0 $*' ***" >>$LOG

Expand All @@ -228,6 +264,10 @@ while [ $# -gt 0 ]; do
getpid $2
shift 1
;;
-R|--repo)
repo $2
shift 1
;;
--upgrade)
python3 -m pip install --upgrade marimo
shift 1
Expand All @@ -242,10 +282,21 @@ while [ $# -gt 0 ]; do
--wait)
WAIT=yes
;;
-W|--workdir)
if [ $# -eq 1 ]; then
error "missing folder name" E_MISSING
fi
WORKDIR=$2
shift
;;
index) # list of available apps
index
exit $E_OK
;;
status)
status
exit $E_OK
;;
list) # list of active apps
getlist
exit $E_OK
Expand Down
Loading