Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aeisenbarth committed Jun 28, 2024
0 parents commit e590a60
Show file tree
Hide file tree
Showing 27 changed files with 3,210 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
dist/
eggs/
sdist/
wheels/
*.egg-info/
MANIFEST

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
coverage.xml
*.cover
*.py,cover
.pytest_cache/

# Sphinx documentation
docs/_build/

# Jupyter Notebook
.ipynb_checkpoints

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

jupyter_execute
1 change: 1 addition & 0 deletions .pdm-python
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/andreas/software/miniconda3/envs/myst-nb-json/bin/python
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-json
files: \.(json)$
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python/black
rev: 22.3.0
hooks:
- id: black-jupyter
args: ["--config=pyproject.toml"]
pass_filenames: true
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--settings-path=pyproject.toml"]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14
hooks:
- id: mdformat
additional_dependencies:
- mdformat-beautysh
- mdformat-black
- mdformat-frontmatter
- mdformat-toc
- mdformat-gfm
args: ["--number", "--wrap", "keep"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
args: ["--install-types", "--non-interactive"]
additional_dependencies: ["bokeh>=3.3.4", "sphinx>=7.2.6"]
exclude: >
(?x)^(
tests/.*\.py
)$
- repo: https://github.com/pdm-project/pdm
rev: 2.15.4
hooks:
- id: pdm-lock-check
- repo: https://github.com/hadialqattan/pycln
rev: v1.3.2
hooks:
- id: pycln
args: ["--config=pyproject.toml"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
hooks:
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD License

Copyright (c) 2024, Andreas Eisenbarth
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exclude docs
recursive-exclude docs *
exclude tests
recursive-exclude tests *.js *.css
include myst_nb_json/resources/*.js
include myst_nb_json/resources/*.css

exclude .pre-commit-config.yaml
exclude .readthedocs.yaml

include LICENSE
include README.md
include AUTHORS.md
include CONTRIBUTING.md
include src/myst_nb_json/py.typed
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# MyST-NB JSON

A MIME-type plugin for rendering JSON output from Jupyter notebooks to HTML

______________________________________________________________________

Outputs from Jupyter notebook code cells usually contain representations in one or multiple MIME
types (image, text, ...). IPython provides multiple built-in output types, but not all of them
have a representation for HTML, and fall back to a stringified version of the Python object.

This is the case for the `application/json` type:

It is nicely rendered in Jupyter because Jupyter includes a
[JSON renderer](https://github.com/jupyterlab/jupyterlab/tree/7909745d075aceb0cf1099ad53a3174e92b575ae/packages/json-extension),
but MyST-NB can only use IPython's built-ins which display as `<IPython.core.display.JSON object>`.

## Jupyter Lab

![Screenshot of json_dict in Jupyter](./docs/images/example1-jupyter.png)

## MyST-NB without plugin

![Screenshot of json_dict in HTML by MyST-NB](./docs/images/example1-myst-nb.png)

## MyST-NB with myst-nb-json plugin

![Screenshot of json_dict in HTML with myst-nb-json](./docs/images/example1-myst-nb-json.png)
60 changes: 60 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from datetime import datetime
from importlib import metadata

# Custom constants (no Sphinx configuration)

REPOSITORY_URL = "https://github.com/aeisenbarth/myst-nb-json"

# -- Project information ---------------------------------------------------------------------------

project = "MyST-NB JSON"
author = "Andreas Eisenbarth"

copyright = f"{datetime.now():%Y}, Andreas Eisenbarth"

release = version = metadata.version("myst-nb-json")

# -- General configuration -------------------------------------------------------------------------

extensions = ["myst_nb"]

# List of glob-style patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
# Myst-nb creates a folder "jupyter_execute" and copies notebooks there, which causes recursive
# inclusion, so exclude it. See https://github.com/executablebooks/MyST-NB/issues/129
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "jupyter_execute"]

# -- Options for HTML output -----------------------------------------------------------------------

html_theme = "sphinx_book_theme"

html_theme_options = dict(
use_repository_button=True,
use_download_button=False,
repository_provider="gitlab",
repository_url=REPOSITORY_URL,
repository_branch="main",
navigation_with_keys=False, # https://github.com/pydata/pydata-sphinx-theme/issues/1492
collapse_navbar=False,
show_navbar_depth=1,
)

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["static"]

# Define custom CSS rules
html_css_files = ["custom.css"]

# If true, “Created using Sphinx” is shown in the HTML footer. Default is True.
html_show_sphinx = False

# -- myst_parser / myst_nb -------------------------------------------------------------------------
26 changes: 26 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Development

1. Clone the repository:

```shell
git clone https://github.com/aeisenbarth/myst-nb-json.git
```

2. Install dependencies:

```shell
pip install pdm
pdm install
```

3. Run tests:

```shell
pdm test
```

4. Build documentation:

```shell
pdm docs
```
Loading

0 comments on commit e590a60

Please sign in to comment.