Skip to content

Commit

Permalink
Merge pull request #8 from usnistgov/docs
Browse files Browse the repository at this point in the history
Zenodo Upload and Mkdocs
  • Loading branch information
wd15 authored Mar 6, 2024
2 parents 719f5a7 + 2e03350 commit 8839bfb
Show file tree
Hide file tree
Showing 27 changed files with 81,524 additions and 915 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
python=3.10
poetry
- run: poetry install
- run: py.test --nbval-lax --cov-fail-under=100
- env:
ZENODO_SANDBOX_API_TOKEN: ${{ secrets.ZENODO_SANDBOX_API_TOKEN }}
run: py.test --nbval-lax --cov-fail-under=100
- run: |
mkdir -p tmp
cd tmp
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Docs
on:
push:
branches:
- main
jobs:
deploy-docs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable
name: pfhub
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
extraPullNames: nix-community
- run: echo "UID=${UID}" >> $GITHUB_ENV
- uses: actions/cache/restore@v3
with:
path: /run/user/${{ env.UID }}/http_cache.sqlite
key: ${{ runner.os}}-http_cache.sqlite
- run: nix develop --command bash -c "mkdocs gh-deploy --clean --verbose --remote-branch nist-pages"
- uses: actions/cache/save@v3
if: always()
with:
path: /run/user/${{ env.UID }}/http_cache.sqlite
key: ${{ runner.os }}-http_cache.sqlite
4 changes: 3 additions & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
with:
path: /run/user/${{ env.UID }}/http_cache.sqlite
key: ${{ runner.os}}-http_cache.sqlite
- run: nix develop --command bash -c "py.test --nbval-lax --cov-fail-under=100"
- env:
ZENODO_SANDBOX_API_TOKEN: ${{ secrets.ZENODO_SANDBOX_API_TOKEN }}
run: nix develop --command bash -c "py.test --nbval-lax --cov-fail-under=100"
- run: nix develop --command bash -c "black --check pfhub"
- run: nix develop --command bash -c "pylint pfhub"
- run: nix develop --command bash -c "flake8 pfhub"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.~*
.coverage
dist
site
tmp
52 changes: 52 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,55 @@ To publish, use
[flakes]: https://nixos.wiki/wiki/Flakes
[conventional]: https://www.conventionalcommits.org
[pypi-test]: https://stackoverflow.com/questions/68882603/using-python-poetry-to-publish-to-test-pypi-org

### Deploying the docs

Use

$ mkdocs gh-deploy --remote-branch nist-pages --remote-name upstream

when in the nix development environment. This will build the docs and
push to the `nist-pages` branch in the upstream repository.



### Setting up Zenodo

It's best to start testing uploads using Zenodo Sandbox before using
the main Zenodo repository. See [the zenodo-client
documentation](https://pypi.org/project/zenodo-client/) for more
details, but the following steps should work:

- Create an account with Zenodo sandbox at
[https://sandbox.zenodo.org/signup/](https://sandbox.zenodo.org/signup/).

- Generate a Zenodo token from
[https://sandbox.zenodo.org/account/settings/applications/](https://sandbox.zenodo.org/account/settings/applications/)
under "Applications" > "Personal Access Tokens". Select
"deposits:actions", "deposits:write" and "user:email" when
generating the token.

- Copy the token and set the `ZENODO_SANDBOX_API_TOKEN` environment
variable using the token or add the token to `~/.config/zenodo.ini`
so that it looks like

```
[zenodo]
sandbox_api_token = XXX
```

- Test using the PFHub CLI to upload data to Zenodo Sandbox. Use
`pfhub upload pfhub.yaml --sandbox` to do this. Sample data is
available here
[here](https://github.com/usnistgov/pfhub-cli/tree/main/pfhub/test_data).


**NOTE**: logging into Zenodo's sandbox can be difficult with ORCID
and is probably easier with a GitHub ID.

To use the main Zenodo repository (not sandbox), follow the same
instructions as above, but use the main Zenodo site. Set the
`ZENODO_API_TOKEN` or add the `api_token = XXX` to
`~/.config/zenodo.ini`.

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PFHub CLI

## Overview

A Python module for both rendering and submitting [PFHub] phase-field
benchmark results using Jupyter, Pandas and Plotly.

Expand Down Expand Up @@ -27,7 +29,7 @@ for just the command line tool or
$ nix develop github:usnistgov/pfhub-cli

to generate an environment with Python and Jupyter available. See
[the Nix section of the development guide](./DEVELOPMENT.md#flakes) to
[the Nix section of the development guide](./DEVELOPMENT.md#nix-shell-prompt) to
get more help starting out with Nix.

## Usage
Expand All @@ -37,7 +39,10 @@ get more help starting out with Nix.
To test that the PFHub CLI is installed correctly use

$ pfhub test

A single test will fail if `ZENODO_SANDBOX_API_TOKEN` is not set, see
the [development guide](./DEVELOPMENT.md#setting-up-zenodo).

### Submit a benchmark result

Under construction.
Expand Down
2 changes: 2 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--8<-- "DEVELOPMENT.md"

1 change: 1 addition & 0 deletions docs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "LICENSE.md"
17 changes: 17 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# API


::: pfhub.main
options:
members:
- efficiency_plot
- levelset_plot
show_root_heading: true
show_source: true

::: pfhub.scripts.cli
options:
members:
- download_zenodo
show_root_heading: true
show_source: true
4 changes: 4 additions & 0 deletions docs/css/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.highlight.language-python {
color: #3E4349;
font-size: 16px;
}
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--8<-- "README.md"

79,733 changes: 79,733 additions & 0 deletions docs/notebooks/test.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
url-normalize = [ "poetry-core" ];
cfgraph = [ "setuptools" ];
pytest-logging = [ "setuptools" ];
mkdocs-windmill = [ "setuptools" ];
paginate = [ "setuptools" ];
};

p2n-overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend (self: super:
Expand Down
67 changes: 67 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
site_name: PFHub CLI
site_url: https://example.com/
repo_url: https://github.com/usnistgov/pfhub-cli

theme:
name: material
palette:

# Palette toggle for dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode

- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode

nav:
- Home: index.md
# - Tutorial: tutorial.md
- "How-to Guide":
- "Test Notebook include": notebooks/test
# - "Upload Data to Zenodo": upload-zenodo.md
# - "Submit a Benchmark Result": test
# - "Generate Data": generate.md
# - "Generate a pfhub.yaml": pfhub-yaml.md
# - Background: background.md
- API: api.md
- Development: DEVELOPMENT.md

markdown_extensions:
- pymdownx.snippets:
check_paths: true
- toc:
permalink: ""

plugins:
- mkdocs-jupyter:
execute: true
allow_errors: false
include_requirejs: true
ignore: [".ipynb_checkpoints/*.ipynb"]
- mkdocstrings:
handlers:
python:
options:
docstring_style: google
docstring_section_style: list
# heading_level: 1
inherited_members: true
merge_init_into_class: true
separate_signature: true
show_root_heading: true
show_root_full_path: false
show_signature_annotations: true
show_symbol_type_heading: true
show_symbol_type_toc: true
signature_crossrefs: true
summary: true
parameter_headings: true

extra_css:
- extra.css
12 changes: 1 addition & 11 deletions pfhub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,7 @@ def test(*args): # pragma: no cover
import pytest # pylint: disable=import-outside-toplevel

path = os.path.join(os.path.split(__file__)[0])
pytest.main(
args=[
path,
"--doctest-modules",
"-r s",
"--cov=pfhub/",
"--no-cov-on-fail",
"--cov-fail-under=100",
]
+ list(args)
)
pytest.main(args=[path, "--doctest-modules", "-r s", "--no-cov"] + list(args))


__version__ = _version.get_versions()["version"]
4 changes: 2 additions & 2 deletions pfhub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def get_file_strings(meta_yaml):
meta_yaml: wizdot version of meta.yaml
Returns:
a dictionary of files and contents for wring to disk including
a dictionary of files and contents for writing to disk including
the pfhub.yaml and necessary data files
>>> yaml_file = str(getfixture('yaml_data_file'))
Expand Down Expand Up @@ -406,7 +406,7 @@ def render_pfhub_schema(data, time_data, memory_data, timeseries):
{
"problem": data.benchmark.id,
"benchmark_version": data.benchmark.version,
"summary": data.metadata.summary,
"summary": data.metadata.summary.encode("unicode_escape"),
"contributors": [
{
"id": "github:" + data.metadata.author.github_id,
Expand Down
2 changes: 1 addition & 1 deletion pfhub/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def compact(items):


def read_vega_data(keys, data):
"""Read vega data given keys to exract
"""Read vega data given keys to extract
Read a vega data block given the keys (or columns) to extract
Expand Down
6 changes: 5 additions & 1 deletion pfhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,16 @@ def line_plot(
def levelset_plot(
data, layout=None, columns=("x", "y", "z"), mask_func=lambda x: slice(len(x))
):
"""Generate a Plotly level set plot
r"""Generate a Plotly level set plot
Args:
data: extracted data as a data frame
layout: dictionary with "x", "y" and "title" keys to customize the plot
mask_func: function to apply to remove values (helps to reduce memory usage)
Example:
```
>>> x, y = np.mgrid[-1:1:10j, -1:1:10j]
>>> x = x.flatten()
>>> y = y.flatten()
Expand All @@ -416,6 +419,7 @@ def levelset_plot(
'yaxis': {'range': [-1, 1], 'scaleanchor': 'x', 'scaleratio': 1}}
})
```
"""
if layout is None:
layout = {}
Expand Down
2 changes: 1 addition & 1 deletion pfhub/schema/pfhub_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ slots:
time_in_s:
description: >-
Amount of time required to execute the simulation.
range: integer
range: float
required: true
slot_uri: https://schema.org/Number
unit:
Expand Down
16 changes: 9 additions & 7 deletions pfhub/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ..convert import download_meta as download_meta_
from ..func import compact
from ..new_to_old import to_old
from ..upload import upload_to_zenodo


EPILOG = "See the documentation at \
Expand Down Expand Up @@ -234,15 +235,16 @@ def test(): # pragma: no cover


@cli.command(epilog=EPILOG)
@click.option(
"--path",
"-p",
help="Upload a set of files to Zenodo",
type=click.Path(exists=True, readable=True, file_okay=False),
default="./",
@click.argument(
"file_path",
type=click.Path(exists=True, dir_okay=False, readable=True),
default="./pfhub.yaml",
)
def upload(path): # pylint: disable=unused-argument
@click.option("--sandbox/--no-sandbox", default=True)
def upload(file_path, sandbox): # pylint: disable=unused-argument
"""Upload PFHub data to Zenodo"""
url = upload_to_zenodo(file_path, sandbox)
click.secho(message=f"Uploaded to {url}", fg="green")


@cli.command(epilog=EPILOG)
Expand Down
Loading

0 comments on commit 8839bfb

Please sign in to comment.