Skip to content

Commit 9eb8cdb

Browse files
authored
Improve readability and design of auto-built documentation (equinor#241)
1 parent 7367d13 commit 9eb8cdb

32 files changed

+824
-358
lines changed

.github/workflows/webviz-config.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
with:
3737
python-version: ${{ matrix.python-version }}
3838

39+
- name: 📦 Install npm dependencies
40+
run: |
41+
npm ci --ignore-scripts
42+
npm run postinstall
43+
3944
- name: 📦 Install webviz-config with dependencies
4045
run: |
4146
pip install 'pandas==${{ matrix.pandas-version }}'
@@ -65,24 +70,23 @@ jobs:
6570
webviz certificate
6671
webviz preferences --theme default
6772
pytest ./tests --headless --forked
68-
pushd ./docs
69-
python build_docs.py
70-
popd
73+
webviz docs --portable ./docs_build --skip-open
7174
7275
- name: 🚢 Build and deploy Python package
7376
if: github.event_name == 'release' && matrix.python-version == '3.6' && matrix.pandas-version == '1.*'
7477
env:
7578
TWINE_USERNAME: __token__
7679
TWINE_PASSWORD: ${{ secrets.pypi_webviz_token }}
7780
run: |
81+
export SETUPTOOLS_SCM_PRETEND_VERSION=${GITHUB_REF//refs\/tags\//}
7882
python -m pip install --upgrade setuptools wheel twine
7983
python setup.py sdist bdist_wheel
8084
twine upload dist/*
8185
8286
- name: 📚 Update GitHub pages
8387
if: github.event_name != 'schedule' && github.ref == 'refs/heads/master' && matrix.python-version == '3.6' && matrix.pandas-version == '1.*'
8488
run: |
85-
cp -R ./docs/_build ../_build
89+
cp -R ./docs_build ../docs_build
8690
8791
git config --local user.email "webviz-github-action"
8892
git config --local user.name "webviz-github-action"
@@ -91,7 +95,7 @@ jobs:
9195
git clean -f -f -d -x
9296
git rm -r *
9397
94-
cp -R ../_build/* .
98+
cp -R ../docs_build/* .
9599
96100
git add .
97101

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ venv
1111
.DS_Store
1212
dist
1313
build
14+
webviz_config/_docs/static/fonts
15+
webviz_config/_docs/static/INTRODUCTION.md
16+
webviz_config/_docs/static/*.js
17+
webviz_config/_docs/static/*.css
18+
!webviz_config/_docs/static/webviz-doc.js
19+
!webviz_config/_docs/static/webviz-doc.css

CONTRIBUTING.md

+48-8
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,55 @@ black --check webviz_config tests
509509

510510
## Build documentation
511511

512-
End-user documentation (i.e. YAML configuration file) be created
513-
after installation by
512+
`webviz-config` can automatically build documentation for all installed plugins. E.g.
513+
the end user can get an overview of all installed plugins, and their arguments, by
514+
running
515+
```bash
516+
webviz docs
517+
```
518+
in the terminal. Behind the scenes, `webviz-config` will then create a
519+
[`docsify`](https://github.com/docsifyjs/docsify) setup and open it `localhost`.
514520

521+
The setup can also be deployed to e.g. GitHub Pages directly. To store the documentation
522+
output run
515523
```bash
516-
pip install .[tests] # if not already done
517-
cd ./docs
518-
python ./build_docs.py
524+
webviz docs --portable ./built_docs --skip-open
525+
```
526+
The `--skip-open` argument is useful in a CI/CD setting, to prevent `webviz-config`
527+
from automatically trying to open the created documentation in the browser.
528+
529+
### Improve plugin documentation
530+
531+
Auto-built `webviz` documentation will:
532+
- Find all installed plugins.
533+
- Group them according to top package name.
534+
- Show a `YAML` snippet with the plugin argument options.
535+
- Arguments with default values will be presented with the default value, and be marked as optional.
536+
- If an argument has a type annotation, that will be included in the documentation.
537+
538+
In addition, if the plugin class has a docstring, the content in the docstring will
539+
be used as a short introduction to the plugin. If the docstring has several parts,
540+
when split by a line containing only `---`, they will be used as follows:
541+
1. First part is the introduction to the plugin.
542+
2. Second part is a more detailed explanation of the plugin arguments.
543+
3. Third part is information regarding plugin data input. E.g assumptions,
544+
prerequisites and/or required/assumed data format.
545+
546+
Since `docsify` is used behind the scenes, you can create information boxes, warning boxes
547+
and use GitHub emojis :bowtie: in the plugin docstring.
548+
See [`docsify` documentation](https://docsify.js.org/#/) for details.
549+
550+
[KaTeX](https://katex.org/) is also used behind the scenes, meaning that you can add
551+
math (TeX syntax) to your docstrings and get it rendered in the auto-built
552+
documentation. Remember that `\` is an escape character in Python, i.e. either
553+
escape it (`\\`) or use raw strings:
554+
```python
555+
class HistoryMatch(WebvizPluginABC):
556+
r"""This is a docstring with some inline math $\alpha$ and some block math:
557+
558+
$$\alpha = \frac{\beta}{\gamma}$$
559+
"""
519560
```
520561

521-
Officially updated built end-user documentation (i.e. information to the
522-
person setting up the configuration file) is
523-
[hosted here on github](https://equinor.github.io/webviz-config/).
562+
Example of auto-built documentation for `webviz-config` can be seen
563+
[here on github](https://equinor.github.io/webviz-config/).

INTRODUCTION.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Webviz introduction
2+
3+
### Fundamental configuration
4+
5+
A configuration consists of some mandatory properties, e.g. app title,
6+
and one or more pages. A page has a title and some content.
7+
Each page can contain as many plugins as you want.
8+
9+
Plugins represent predefined content, which can take one or more arguments.
10+
Lists and descriptions of installed plugins can be found on the other subpages.
11+
12+
Content which is not plugins is interpreted as text paragraphs.
13+
14+
A simple example configuration:
15+
```yaml
16+
# This is a webviz configuration file example.
17+
# The configuration files use the YAML standard (https://en.wikipedia.org/wiki/YAML).
18+
19+
title: Reek Webviz Demonstration
20+
21+
pages:
22+
23+
- title: Front page
24+
content:
25+
- BannerImage:
26+
image: ./example_banner.png
27+
title: My banner image
28+
- Webviz created from a configuration file.
29+
30+
- title: Markdown example
31+
content:
32+
- Markdown:
33+
markdown_file: ./example-markdown.md
34+
```
35+
36+
### Command line usage
37+
38+
#### Get documentation
39+
40+
You can always run `webviz --help` to see available command line options.
41+
To see command line options on a subcommand, run e.g. `webviz build --help`.
42+
43+
:books: To open the `webviz` documentation on all installed plugins, run `webviz docs`.
44+
45+
#### Portable vs. non-portable
46+
47+
Assuming you have a configuration file `your_config.yml`,
48+
there are two main usages of `webviz`:
49+
50+
```bash
51+
webviz build your_config.yml
52+
```
53+
and
54+
```bash
55+
webviz build your_config.yml --portable ./some_output_folder
56+
python ./some_output_folder/webviz_app.py
57+
```
58+
59+
**Portable**
60+
61+
The portable way is useful when one or more plugins included in the configuration need to do
62+
some time-consuming data aggregation on their own, before presenting it to the user.
63+
The time-consuming part will then be done in the `build` step, and you can run your
64+
created application as many time as you want afterwards, with as little waiting
65+
time as possible.
66+
67+
The `--portable` way also has the benefit of creating a :whale: Docker setup for your
68+
application - ready to be deployed to e.g. a cloud provider.
69+
70+
**Non-portable**
71+
72+
Non-portable is the easiest way if none of the plugins
73+
have time-consuming data aggregration to do.
74+
75+
A feature in Dash, used by `webviz` is [hot reload](https://community.plot.ly/t/announcing-hot-reload/14177).
76+
When the Dash Python code file is saved, the content seen in the web browser is
77+
automatically reloaded (no need for localhost server restart). This feature is passed on to
78+
the Webviz configuration utility, meaning that if you run
79+
```bash
80+
webviz build ./examples/basic_example.yaml
81+
```
82+
and then modify `./examples/basic_example.yaml` while the Webviz application is
83+
still running, a hot reload will occur.
84+
85+
#### Localhost certificate
86+
87+
For quick local analysis, `webviz-config` uses `https` and runs on `localhost`.
88+
In order to create your personal :lock: `https` certificate (only valid for `localhost`), run
89+
```bash
90+
webviz certificate --auto-install
91+
```
92+
Certificate installation guidelines will be given when running the command.
93+
94+
#### User preferences
95+
96+
You can set preferred :rainbow: theme and/or :earth_africa: browser, such that `webviz` remembers it for later
97+
runs. E.g.
98+
99+
```bash
100+
webviz preferences --theme equinor --browser firefox
101+
```

README.md

+9-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img height="150" src="https://github.com/equinor/webviz-config/raw/master/docs/assets/webviz-logo.svg?sanitize=true">
2+
<img height="150" src="https://github.com/equinor/webviz-config/raw/master/webviz_config/_docs/static/webviz-logo.svg?sanitize=true">
33
</p>
44

55
<h2 align="center">Democratizing Python web applications</h2>
@@ -42,21 +42,21 @@ Example configuration file and information about the standard plugins can be see
4242

4343
### Installation
4444

45-
The simplest way of installing `webviz-config` is to run
45+
The recommended and simplest way of installing `webviz-config` is to run
4646
```bash
4747
pip install webviz-config
4848
```
4949

50-
If you want to download the latest source code and install it manually you
50+
If you want to develop `webviz-config` and install the latest source code manually you
51+
can do something along the lines of:
5152
can run
5253
```bash
5354
git clone [email protected]:equinor/webviz-config.git
5455
cd ./webviz-config
55-
pip install .
56+
npm ci --ignore-scripts && npm run postinstall
57+
pip install -e .
5658
```
5759

58-
### Usage
59-
6060
After installation, there is a console script named `webviz` available. You can test the installation by using the provided test
6161
configuration file,
6262
```bash
@@ -74,28 +74,11 @@ The optional arguments can be seen when running
7474
```bash
7575
webviz --help
7676
```
77-
For example will
78-
```bash
79-
webviz build ./examples/basic_example.yaml --portable ./my_portable_app
80-
```
81-
create a portable instance (with corresponding Dockerfile) and store it in the provided folder.
8277

83-
A feature in Dash is [hot reload](https://community.plot.ly/t/announcing-hot-reload/14177).
84-
When the Dash Python code file is saved, the content seen in the web browser is
85-
automatically reloaded (no need for localhost server restart). This feature is passed on to
86-
the Webviz configuration utility, meaning that if the user runs
87-
```bash
88-
webviz build ./examples/basic_example.yaml
89-
```
90-
and then modifies `./examples/basic_example.yaml` while the Webviz application is
91-
still running, a hot reload will occur.
78+
### Usage
9279

93-
For quick local analysis, `webviz-config` uses `https` and runs on `localhost`.
94-
In order to create your personal `https` certificate (only valid for `localhost`), run
95-
```bash
96-
webviz certificate --auto-install
97-
```
98-
Certificate installation guidelines will be given when running the command.
80+
See [the introduction](./INTRODUCTION.md) page for information on how you
81+
create a `webviz` configuration file and use it.
9982

10083
### Creating new plugins
10184

docs/.gitignore

-2
This file was deleted.

docs/assets/webviz_doc.css

-50
This file was deleted.

0 commit comments

Comments
 (0)