Skip to content

Commit

Permalink
Change syntax configuration file, rename from container (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Jan 8, 2020
1 parent 1f34adb commit 769e3df
Show file tree
Hide file tree
Showing 34 changed files with 603 additions and 477 deletions.
171 changes: 92 additions & 79 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This Python package, `webviz-config`, is the core plugin framework. For a real e

*Webviz* will create web applications with very :lock: strict security headers and CSP settings, giving an rating of **A+** on e.g. [Mozilla observatory](https://observatory.mozilla.org/). It also facilitates a :whale: Docker setup, where the Python code can be ran completely unpriviliged in a sandbox (both with respect to file system access and network communication).

Example configuration file and information about the standard containers can be seen in [the documentation](https://equinor.github.io/webviz-config/).
Example configuration file and information about the standard plugins can be seen in [the documentation](https://equinor.github.io/webviz-config/).

**The workflow can be summarized as this:**
1) The user provides a :book: configuration file following the [yaml](https://en.wikipedia.org/wiki/YAML) standard.
Expand Down Expand Up @@ -96,13 +96,13 @@ webviz certificate --auto-install
```
Certificate installation guidelines will be given when running the command.

### Creating new containers
### Creating new plugins

If you are interested in creating new containers which can be configured through
If you are interested in creating new plugins which can be configured through
the configuration file, take a look at the [contribution guide](./CONTRIBUTING.md).

To quickly get started, we recommend using the corresponding
[cookiecutter template](https://github.com/equinor/webviz-container-boilerplate).
[cookiecutter template](https://github.com/equinor/webviz-plugin-boilerplate).

### License

Expand Down
56 changes: 28 additions & 28 deletions docs/build_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Builds automatic documentation of the installed webviz config containers.
"""Builds automatic documentation of the installed webviz config plugins.
The documentation is designed to be used by the YAML configuration file end
user. Sphinx has not been used due to
Expand All @@ -9,10 +9,10 @@
is not needed.
Overall workflow is:
* Gets all installed containers.
* Finds all installed plugins.
* Automatically reads docstring and __init__ function signature (both
argument names and which arguments have default values).
* Output the extracted container information in html using jinja2.
* Output the extracted plugin information in html using jinja2.
"""

import shutil
Expand All @@ -22,7 +22,7 @@
from collections import defaultdict
import jinja2
from markdown import markdown
import webviz_config.containers
import webviz_config.plugins
from webviz_config._config_parser import SPECIAL_ARGS

SCRIPT_DIR = pathlib.Path(__file__).resolve().parent
Expand All @@ -48,58 +48,58 @@ def convert_docstring(doc):
return "" if doc is None else markdown(doc, extensions=["fenced_code"])


def get_container_documentation():
"""Get all installed containers, and document them by grabbing docstring
def get_plugin_documentation():
"""Get all installed plugins, and document them by grabbing docstring
and input arguments / function signature.
"""

containers = inspect.getmembers(webviz_config.containers, inspect.isclass)
plugins = inspect.getmembers(webviz_config.plugins, inspect.isclass)

container_doc = []
plugin_doc = []

for container in containers:
reference = container[1]
for plugin in plugins:
reference = plugin[1]

container_info = {}
plugin_info = {}

container_info["name"] = container[0]
container_info["doc"] = convert_docstring(reference.__doc__)
plugin_info["name"] = plugin[0]
plugin_info["doc"] = convert_docstring(reference.__doc__)

argspec = inspect.getfullargspec(reference.__init__)
container_info["args"] = [
plugin_info["args"] = [
arg for arg in argspec.args if arg not in SPECIAL_ARGS
]

container_info["values"] = defaultdict(lambda: "some value")
plugin_info["values"] = defaultdict(lambda: "some value")

if argspec.defaults is not None:
for arg, default in dict(
zip(reversed(argspec.args), reversed(argspec.defaults))
).items():
container_info["values"][
plugin_info["values"][
arg
] = f"{default} # Optional (default value shown here)."

module = inspect.getmodule(reference)
container_info["module"] = module.__name__
plugin_info["module"] = module.__name__

package = inspect.getmodule(module).__package__
container_info["package"] = package
container_info["package_doc"] = convert_docstring(
plugin_info["package"] = package
plugin_info["package_doc"] = convert_docstring(
import_module(package).__doc__
)

if not container_info["name"].startswith("Example"):
container_doc.append(container_info)
if not plugin_info["name"].startswith("Example"):
plugin_doc.append(plugin_info)

# Sort the containers by package:
# Sort the plugins by package:

package_ordered = defaultdict(lambda: {"containers": []})
package_ordered = defaultdict(lambda: {"plugins": []})

for container in sorted(container_doc, key=lambda x: (x["module"], x["name"])):
package = container["package"]
package_ordered[package]["containers"].append(container)
package_ordered[package]["doc"] = container["package_doc"]
for plugin in sorted(plugin_doc, key=lambda x: (x["module"], x["name"])):
package = plugin["package"]
package_ordered[package]["plugins"].append(plugin)
package_ordered[package]["doc"] = plugin["package_doc"]

return package_ordered

Expand All @@ -112,7 +112,7 @@ def get_basic_example():
if __name__ == "__main__":

template_data = {
"packages": get_container_documentation(),
"packages": get_plugin_documentation(),
"basic_example": get_basic_example(),
}

Expand Down
30 changes: 15 additions & 15 deletions docs/templates/index.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@

<body>

<div class='container'>
<div class="container">

<h1>Webviz configuration guide</h1>

<h2>Fundamental configuration</h2>

A configuration consists of some mandatory properties (title, username,
password) and one or more pages. Each page has a title, and potentially some
A configuration consists of some mandatory properties (e.g. app title)
and one or more pages. Each page has a title, and potentially some
content. The content can be one or more items.

Containers represent predefined content, which takes one or more arguments.
A list and description of all available different containers is listed below.
Plugins represent predefined content, which takes one or more arguments.
A list and description of all available different plugins is listed below.

Content which is not containers are interpreted as text paragraphs.
Content which is not plugins are interpreted as text paragraphs.

A basic example configuration is shown below.

<pre><code class='yaml'>{{ basic_example }}</code></pre>
<pre><code class="yaml">{{ basic_example }}</code></pre>

<h2>Container documentation</h2>
<h2>Plugin documentation</h2>

{%- for package in packages.values() %}

{{- package['doc'] -}}
{{- package["doc"] -}}

<div style='margin-left: 40px;'>
<div style="margin-left: 40px;">

{%- for container in package['containers'] %}
{%- for plugin in package["plugins"] %}

{{ container['doc'] }}
<pre><code class='yaml'> - container: {{ container['name'] }}
{%- for arg in container['args'] %}
{{ arg }}: {{ container['values'][arg] }}
{{ plugin["doc"] }}
<pre><code class="yaml"> - {{ plugin["name"] }}:
{%- for arg in plugin["args"] %}
{{ arg }}: {{ plugin["values"][arg] }}
{%- endfor %}
</code></pre>
<hr>
Expand Down
62 changes: 31 additions & 31 deletions examples/basic_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,60 @@ pages:

- title: Front page
content:
- container: BannerImage
image: ./example_banner.png
title: My banner image
- BannerImage:
image: ./example_banner.png
title: My banner image
- Webviz created from configuration file.
- Some other text, potentially with strange letters like Åre, Smørbukk Sør.

- title: Markdown example
content:
- container: Markdown
markdown_file: ./example-markdown.md
- Markdown:
markdown_file: ./example-markdown.md

- title: Table example
content:
- container: DataTable
csv_file: ./example_data.csv
- DataTable:
csv_file: ./example_data.csv

- title: PDF example
content:
- container: EmbedPdf
pdf_file: ./example.pdf
- EmbedPdf:
pdf_file: ./example.pdf

- title: Syntax highlighting example
content:
- container: SyntaxHighlighter
filename: ./basic_example.yaml
- SyntaxHighlighter:
filename: ./basic_example.yaml

- title: Tour example
content:
- container: ExampleTour
- ExampleTour:

- title: Plot a table
content:
- container: TablePlotter
csv_file: ./example_data.csv
filter_cols:
- TablePlotter:
csv_file: ./example_data.csv
filter_cols:
- Well
- Segment
- Average permeability (D)
contact_person:
name: Ola Nordmann
phone: +47 12345678
email: [email protected]
contact_person:
name: Ola Nordmann
phone: +47 12345678
email: [email protected]

- title: Plot a table (locked)
content:
- container: TablePlotter
csv_file: ./example_data.csv
lock: true
plot_options:
x: Well
y: Initial reservoir pressure (bar)
size: Average permeability (D)
facet_col: Segment
contact_person:
name: Kari Nordmann
phone: 12345678
email: [email protected]
- TablePlotter:
csv_file: ./example_data.csv
lock: true
plot_options:
x: Well
y: Initial reservoir pressure (bar)
size: Average permeability (D)
facet_col: Segment
contact_person:
name: Kari Nordmann
phone: 12345678
email: [email protected]
8 changes: 4 additions & 4 deletions examples/demo_portable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pages:

- title: Front page
content:
- container: ExamplePortable
some_number: 42
- container: ExampleAssets
picture_path: ./example_banner.png
- ExamplePortable:
some_number: 42
- ExampleAssets:
picture_path: ./example_banner.png
2 changes: 1 addition & 1 deletion examples/example-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### This is a subsubtitle

Hi from a Markdown container containing Norwegian letters (æ ø å), some
Hi from a Markdown text file containing Norwegian letters (æ ø å), some
**bold** letters, _italic_ letters. _You can also **combine** them._

#### An unordered list
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# webviz-core-components is part of the webviz-config project,
# just located in a separate repository for convenience,
# and is therefore pinned exactly here:
"webviz-core-components==0.0.14",
"webviz-core-components==0.0.15",
],
tests_require=TESTS_REQUIRES,
extras_require={"tests": TESTS_REQUIRES},
Expand Down
43 changes: 20 additions & 23 deletions tests/data/basic_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,45 @@
# The configuration files uses YAML (https://en.wikipedia.org/wiki/YAML).

title: Reek Webviz Demonstration
username: some_username
password: some_password


pages:

- title: Front page
content:
- container: BannerImage
image: ./example_banner.png
title: My banner image
- BannerImage:
image: ./example_banner.png
title: My banner image
- Webviz created from configuration file.
- Some other text, potentially with strange letters like Åre, Smørbukk Sør.

- title: Markdown example
content:
- container: Markdown
markdown_file: ./example-markdown.md
- Markdown:
markdown_file: ./example-markdown.md

- title: PDF example
content:
- container: EmbedPdf
pdf_file: ./example.pdf
- EmbedPdf:
pdf_file: ./example.pdf

- title: Syntax highlighting example
content:
- container: SyntaxHighlighter
filename: ./basic_example.yaml
dark_theme: true
- SyntaxHighlighter:
filename: ./basic_example.yaml
dark_theme: true

- title: Plot a table
content:
- container: TablePlotter
csv_file: ./example_data.csv
- TablePlotter:
csv_file: ./example_data.csv

- title: Plot a table (locked)
content:
- container: TablePlotter
csv_file: ./example_data.csv
lock: true
plot_options:
x: Well
y: Initial reservoir pressure (bar)
size: Average permeability (D)
facet_col: Segment
- TablePlotter:
csv_file: ./example_data.csv
lock: true
plot_options:
x: Well
y: Initial reservoir pressure (bar)
size: Average permeability (D)
facet_col: Segment
Loading

0 comments on commit 769e3df

Please sign in to comment.