diff --git a/README.md b/README.md index 6a90e16..702d78d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # quietlaunch +[![tests](https://github.com/loggger101/quietlaunch/actions/workflows/tests.yml/badge.svg)](https://github.com/loggger101/quietlaunch/actions/workflows/tests.yml) + Start a Streamlit app with **no console window**, and give it something to close. `streamlit run app.py` in a terminal makes the terminal the app: close it and the @@ -16,8 +18,9 @@ console with a small control window that - stops the server **and its children** when it is closed; - installs Streamlit on first use if the interpreter does not have it. -Standard library only. Windows is the reason it exists; Linux and macOS work too -(tkinter required for the window; without it there is a message-box fallback). +Python 3.9 or later, standard library only. Windows is the reason it exists; +Linux and macOS work too, and CI runs all three (tkinter required for the +window; without it there is a message-box fallback). Extracted from [economicspace](https://github.com/loggger101/economicspace)'s dashboard launcher, whose history this repository carries. @@ -59,20 +62,21 @@ sys.exit(quietlaunch.launch(quietlaunch.LaunchConfig( ))) ``` -`python -m quietlaunch --help` lists every option; each is a `LaunchConfig` +`python -m quietlaunch --help` lists every option; each sets a `LaunchConfig` field: -| field | default | what | -|---|---|---| -| `app` | (required) | the Streamlit script | -| `title`, `heading`, `subtitle` | `Streamlit`, title, `Dashboard` | window text | -| `boot_hint` | empty | shown while the server boots | -| `workdir` | the app's folder | the server's working directory | -| `state_dir` | `/.launcher` | logs and the running-server marker; gitignore it | -| `port_first`, `port_tries` | `8501`, `12` | ports tried, upwards | -| `boot_timeout_s` | `300` | how long a boot may take | -| `auto_install`, `requirements` | `True`, none | first-run `pip install` of Streamlit, or of a requirements file | -| `streamlit_args` | none | extra `streamlit run` arguments | +| field | flag | default | what | +|---|---|---|---| +| `app` | positional | (required) | the Streamlit script | +| `title`, `heading`, `subtitle` | `--title`, `--heading`, `--subtitle` | `Streamlit`, title, `Dashboard` | window text | +| `boot_hint` | `--hint` | empty | shown while the server boots | +| `workdir` | `--workdir` | the app's folder | the server's working directory | +| `state_dir` | `--state-dir` | `/.launcher` | logs and the running-server marker; gitignore it | +| `port_first`, `port_tries` | `--port`, `--port-tries` | `8501`, `12` | ports tried, upwards | +| `boot_timeout_s` | `--boot-timeout` | `300` | how long a boot may take | +| `auto_install` | `--no-install` | `True` | first-run `pip install` when Streamlit is missing | +| `requirements` | `--requirements` | none | install from this file (relative to `workdir`) instead of `streamlit>=1.30`; a missing file falls back to that spec | +| `streamlit_args` | after `--` | none | extra `streamlit run` arguments | What it leaves in `state_dir`: `dashboard-.log` (the server's output), `install.log` (the first-run install), and `running-.json` (the port, pid @@ -123,7 +127,13 @@ python -m pytest The tests run the real boot sequence against a fake server (`tests/fake_streamlit.py`) and stand-in Tk widgets, so they need no display and -no Streamlit, and finish in seconds. +no Streamlit, and finish in seconds. `tests/test_rules.py` also holds the +package to its own rules: standard library only, ASCII only, a docstring on +every definition. + +A release bumps `quietlaunch.__version__` (the one place the version is +written; `pyproject.toml` reads it), adds a [CHANGELOG](CHANGELOG.md) entry, +and tags `vX.Y.Z`. Consumers pin the tag. ## Licence diff --git a/quietlaunch/launcher.py b/quietlaunch/launcher.py index 229eb95..164610a 100644 --- a/quietlaunch/launcher.py +++ b/quietlaunch/launcher.py @@ -242,11 +242,10 @@ def _port_answers(port, timeout=0.4): """True if something is LISTENING on this localhost port. The other half of `_port_is_free`, and the two are deliberately separate - questions asked in that order. `_port_is_free` does a bare `bind` and must - NOT set SO_REUSEADDR: on Windows that flag is inverted, meaning "bind even - though someone else holds it" rather than Unix's "reuse a TIME_WAIT port", - so setting it made a free-port probe answer True for the very port - Streamlit was serving on at that moment. + questions, this one asked FIRST. A bind cannot be trusted to detect a live + server on Windows: a server listening on 0.0.0.0 does not stop a plain bind + on 127.0.0.1, so only a connect says whether anybody is there. See + `_port_is_free` for why that probe must not set SO_REUSEADDR either. """ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.settimeout(timeout) @@ -663,7 +662,7 @@ def apply(): def _done_booting(self, ok, message, detail=""): """End the boot sequence: stop the progress bar and report pass or fail. - Enables "Open in browser" only on success. Called exactly once per boot, + Enables "Open dashboard" only on success. Called exactly once per boot, including from `_boot`'s except arm, because a launcher that dies silently is indistinguishable from one still working. """ @@ -693,7 +692,7 @@ def quit(self): closing the window mid-spawn otherwise found `proc` still None, killed nothing, and left a server that nothing on screen could stop. And the pending `after` is CANCELLED rather than merely left unscheduled: - clearing `stopping` stops the pump rescheduling, but the one already in + setting `stopping` stops the pump rescheduling, but the one already in flight still fires, into a destroyed interpreter. """ with self.lock: