Skip to content

Commit

Permalink
Replace idaesx gui command with simpler idaesx serve (#104)
Browse files Browse the repository at this point in the history
* Import module instead of single function

* Remove GUI functionality

* Replace idaesx gui subcommand with serve

* Remove leftover GUI-related code
  • Loading branch information
lbianchi-lbl authored Apr 23, 2024
1 parent 300c6c5 commit ff71e7c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 398 deletions.
4 changes: 2 additions & 2 deletions README-developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ Create a new virtual environment and install the package from test.pypi into it:
pip install --extra-index-url https://test.pypi.org/simple/ idaes-examples
```

If the installation succeeds, you should be able to browse the notebooks using the built-in GUI:
If the installation succeeds, you should be able to serve the notebooks:
```shell
idaesx gui
idaesx serve
```

If it all looks good, you can repeat the **Upload** step with the real [PyPI](pypi.org)
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ to install and run the notebooks in an isolated environment.

Use the command
```
idaesx gui
idaesx serve
```
to get a simple graphical UI that lets you
browse and open notebooks (with Jupyter) for local execution and experimentation.
The GUI will show the description of each notebook and allow selection of tutorial or exercise versions of the notebook, if these exist.
to start a Jupyter server to browser and open the notebooks for local execution and experimentation.

Alternately, you may use Jupyter notebook's file browser in the installed notebooks directory,
using the `idaesx where` command to find that directory:
`jupyter notebook $(idaesx where)`.

Only the source notebooks (ending in '_src.ipynb') are included in the repository.
The `idaesx gui` command will generate the other versions, or you can run preprocessing manually with: `idaesx pre -d "$(idaesx where)\.."`.

The `idaesx serve` command will generate the other versions, or you can run preprocessing manually with: `idaesx pre -d "$(idaesx where)\.."`.

## Build documentation

Expand Down
337 changes: 0 additions & 337 deletions idaes_examples/browse.py

Large diffs are not rendered by default.

60 changes: 22 additions & 38 deletions idaes_examples/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
import re
import shutil
from subprocess import check_call
import subprocess
import sys
import time
import traceback
Expand Down Expand Up @@ -37,8 +37,6 @@
from idaes_examples.util import _log as util_log

# third-party
from jupyter_cache import get_cache
import nbformat as nbf


# -------------
Expand Down Expand Up @@ -371,7 +369,7 @@ def black(srcdir=None):
src_path = find_notebook_root(Path(srcdir)) / NB_ROOT
commandline = ["black", "--include", ".*_src\\.ipynb", str(src_path)]
add_vb_flags(_log, commandline)
check_call(commandline)
subprocess.check_call(commandline)


# --------------------
Expand Down Expand Up @@ -406,7 +404,7 @@ def jupyterbook(srcdir=None, quiet=0, dev=False):
else:
add_vb_flags(_log, commandline)
# run build
check_call(commandline)
subprocess.check_call(commandline)
finally:
os.chdir(cwd)
_copy_built_files(path)
Expand Down Expand Up @@ -487,7 +485,7 @@ def update_value(value, k1, k2):
if sphinx:
Commands.subheading(f"Updating Sphinx config file")
commandline = ["jupyter-book", "config", "sphinx", str(config_file.parent)]
check_call(commandline)
subprocess.check_call(commandline)

if show:

Expand Down Expand Up @@ -770,22 +768,27 @@ def black(cls, args):
return cls._run("format notebook code", black, srcdir=args.dir)

@classmethod
def gui(cls, args):
def serve(cls, args):
from idaes_examples import browse

cls.heading(f"Load notebooks into GUI")
nb_dir = browse.find_notebook_dir().parent
nb_dir = browse.find_notebook_dir()
cls._run(f"pre-process notebooks", preprocess, srcdir=nb_dir)
browse.set_log_level(_log.getEffectiveLevel())
nb = browse.Notebooks()
if args.console:
for val in nb._sorted_values:
pth = Path(val.path).relative_to(Path.cwd())
print(f"{val.type}{' '*(10 - len(val.type))} {val.title} -> {pth}")
status = 0
else:
status = browse.gui(nb, use_lab=args.lab, stop_notebooks_on_quit=args.stop)
return status

def _run_jupyter_server():
try:
ret = subprocess.run(
[
"jupyter",
"notebook",
str(nb_dir),
"-y", # answer 'yes' to skip confirmation prompts
],
)
except KeyboardInterrupt:
return

return cls._run(f"starting Jupyter server in {nb_dir}", _run_jupyter_server)

@classmethod
def where(cls, args):
Expand Down Expand Up @@ -857,7 +860,7 @@ def main():
("hdr", "View or edit headers"),
("clean", "Clean generated files"),
("black", "Format code in notebooks with Black"),
("gui", "Graphical notebook browser"),
("serve", "Start local Jupyter server to browse and run notebooks"),
("skipped", "List notebooks tagged to skip some pre-processing"),
("where", "Print example notebook directory path"),
("new", "Terminal-based UI for starting a new notebook"),
Expand Down Expand Up @@ -922,25 +925,6 @@ def main():
subp["conf"].add_argument(
"--sphinx", action="store_true", help="Run JB command to update Sphinx conf.py"
)
subp["gui"].add_argument("--console", "-c", action="store_true", dest="console")
subp["gui"].add_argument(
"--stderr",
"-e",
action="store_true",
default=False,
dest="log_console",
help=(
"Print logs to the console "
"(stderr) instead of redirecting "
"them to a file in ~/.idaes/logs"
),
)
subp["gui"].add_argument(
"--lab", help="Use Jupyter Lab instead of Jupyter Notebook", action="store_true"
)
subp["gui"].add_argument(
"--stop", help="Stop notebooks on GUI quit", action="store_true"
)
subp["hdr"].add_argument("--path", help="Path to notebook for `--edit`")
subp["hdr"].add_argument(
"--edit", help="Edit mode (default is print)", action="store_true"
Expand Down
8 changes: 1 addition & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ dependencies = [
keywords = ["IDAES", "energy systems", "chemical engineering", "process modeling"]

[project.optional-dependencies]
gui = [
# For the small embedded GUI
"PySimpleGUI~=4.60.4",
"tkhtmlview==0.1.1.post5",
"Markdown~=3.4.1",
]
omlt = [
# For Keras/OMLT
"omlt",
Expand Down Expand Up @@ -87,7 +81,7 @@ docs = [
]
# For developers
dev = [
"idaes-examples[gui,testing,docs]",
"idaes-examples[testing,docs]",
# For jupyter notebook testing
"black[jupyter] ~= 22.8.0",
# For adding copyright headers (see addheader.yml and the readme)
Expand Down
11 changes: 3 additions & 8 deletions tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,10 @@ To make sure the notebook code is formatted according to IDAES convention, you c
idaesx black
```

### Browse the notebooks
### Use the notebooks

There is a simple embedded GUI for browsing the notebooks.
While, of course, you can navigate to the notebooks with Jupyter's file browser, the GUI has the
advantage of giving notebook descriptions as you browse.
Use the following command to start a Jupyter server for browsing and running the notebooks locally:

```
idaesx gui
idaesx serve
```

Note #1: Due to the limitations of the Tk toolkit, the font is pretty ugly. Sorry.
Note #2: The first markdown cell with a header is used for the description.

0 comments on commit ff71e7c

Please sign in to comment.