Skip to content

Commit

Permalink
Develop (#28)
Browse files Browse the repository at this point in the history
* Feature/print friendly pages (#21)

* Correct print formatting

* Update docs and version number

* Update docs

* Update roadmap

* Update release notes

* Update release notes formatting

* Feature/output to pdf (#25)

* Move Jinja template to resources directory

* Add weasyprint dependency

* Implement and test PDF creation

* Update docs

* Fix image scaling

* Extract image resizing to external function

* Revert back to current API for scaling

* Omit display, getters, setters from coverage

* Update lock file

* Feature/inline content dependencies (#26)

* Refactor content dependency handling

* Allow inline dependencies

* Add user options for offline mode

* Feature/render plots as svg (#27)

* Add svg export for plots

* Update docs

* Update iris example
  • Loading branch information
domvwt authored May 3, 2021
1 parent c75fecf commit 52ea7ac
Show file tree
Hide file tree
Showing 26 changed files with 28,656 additions and 370 deletions.
12 changes: 12 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ exclude_lines =
pragma: no cover
raise NotImplementedError
if __name__ == .__main__.:
def __repr__
def _repr_html_
def __str__
def display
return self._
def set_
def _render_title
def _parent_class
def _child_class
if TYPE_CHECKING
if kwargs.get("pdf_mode"):
if output_format == "svg":
ignore_errors = True
omit =
tests/*
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,44 @@ esparto
[![codecov](https://codecov.io/gh/domvwt/esparto/branch/main/graph/badge.svg?token=35J8NZCUYC)](https://codecov.io/gh/domvwt/esparto)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=domvwt_esparto&metric=alert_status)](https://sonarcloud.io/dashboard?id=domvwt_esparto)

Esparto is a super minimal frontend web framework written in Python. Its primary use is for generating shareable single page documents
Esparto is a simple HTML and PDF document generator for Python. Its primary use is for generating shareable single page reports
with content from popular analytics and data science libraries.

Full documentation and examples at [domvwt.github.io/esparto/](https://domvwt.github.io/esparto/).
Full documentation and examples are available at [domvwt.github.io/esparto/](https://domvwt.github.io/esparto/).

## Overview
The library features a streamlined API that defines pages in terms of
sections, rows, and columns; and an intelligent wrapping system that automatically
converts Python objects into content.

We use the grid system and components from [Bootstrap](https://getbootstrap.com/) to ensure
documents adapt to the viewing device and appear immediately familiar and accessible.
No knowledge of Bootstrap or web development is required to use the library, however, as these
details are conveniently abstracted.

At publishing time, the completed document is passed to [Jinja2](https://palletsprojects.com/p/jinja/)
and fed into an HTML template with all style details and dependencies captured inline.

Esparto supports content rendering within Jupyter Notebooks, allowing users to interactively
and iteratively build documents without disrupting their workflow.

PDF conversion is provided by [Weasyprint](https://weasyprint.org/).

### Features
* Lightweight API
* No CSS or HTML required
* Device responsive display
* Self contained / inline dependencies
* Jupyter Notebook support
* Printer friendly formatting
* PDF output
* MIT License

### Supported Content
* Markdown text
* Markdown
* Images
* Matplotlib figures
* Pandas DataFrames
* Bokeh objects
* Plotly figures
* Plots from:
* Matplotlib
* Bokeh
* Plotly
24 changes: 21 additions & 3 deletions docs/01-getting-started/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
Quickstart
==========

The esparto library can be installed with pip:
The esparto library can be installed with pip. Only the minimal package requirements will be installed by default:

```bash
pip install esparto
```

<br>

For PDF output we will also require [weasyprint]("https://weasyprint.org/"), although
this is optional:

```bash
pip install weasyprint
```


<br>

Documents start with a Page object, to which user content can be added iteratively.
Expand All @@ -23,7 +33,7 @@ Your *content* goes **here!**
"""

my_page += content_md
my_page.save("esparto-quick.html")
my_page.save_html("esparto-quick.html")
```
<br>

Expand All @@ -47,7 +57,7 @@ Your *content* goes **here!**
my_page += content_md
my_page += "image.jpg"

html = my_page.save("esparto-quick-image.html")
my_page.save_html("esparto-quick-image.html")
```
<br>

Expand All @@ -57,6 +67,14 @@ Esparto determines that the string points to a valid image and loads the file:

<br>

And for PDF output:

```python
my_page.save_pdf("esparto-quick-image.pdf")
```

<br>

Please see the [examples page](../02-user-guide/examples.md) for more.

<br>
2 changes: 1 addition & 1 deletion docs/03-api-reference/content.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# esparto._content

!!! info
Content classes should be accessed from the module top level.
Content classes can be accessed from the module top level:

``` python
import esparto as es
Expand Down
2 changes: 1 addition & 1 deletion docs/03-api-reference/layout.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# esparto._layout

!!! info
Layout classes should be accessed from the module top level.
Layout classes can be accessed from the module top level:

``` python
import esparto as es
Expand Down
16 changes: 9 additions & 7 deletions docs/03-api-reference/publish.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# esparto._publish

!!! info
Publishing methods should be accessed via Layout classes.
Publishing methods should usually be accessed via Layout classes:

``` python
import esparto as es

# Create a new Page
page = es.Page(title="My New Page")

# Render to Jupyter Notebook cell:
page.display()

# Publish the document to an HTML file:
page.save()
page.save_html("my-page.html")

# Or as a PDF:
page.save_pdf("my-page.pdf")

```

## ::: esparto._publish.publish
### ::: esparto._publish.publish_html

### ::: esparto._publish.publish_pdf

## ::: esparto._publish.nb_display
### ::: esparto._publish.nb_display

<br>
9 changes: 4 additions & 5 deletions docs/04-about/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ Ready to contribute? Here's how to set up esparto for local development.
5. When you're done making changes, check that your changes pass flake8
and the tests, including testing other Python versions with tox:

$ flake8 esparto tests
$ python setup.py test or pytest
$ tox
$ make format lint mypy test
$ make test-all

To get flake8 and tox, just pip install them into your virtualenv.

Expand All @@ -100,8 +99,8 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated.
Put your new functionality into a function with a docstring, and add
the feature to the list in README.rst.
3. The pull request should work for Python 2.7, 3.5, 3.6, 3.7 and 3.8,
and for PyPy. Check
3. The pull request should work for Python 3.6, 3.7, 3.8, and 3.9.
Check
<https://travis-ci.org/domvwt/esparto/pull_requests> and make sure
that the tests pass for all supported Python versions.

Expand Down
9 changes: 9 additions & 0 deletions docs/04-about/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Release Notes
=============

0.2.3 (2021-05-03)
------------------

- Make documents 'print friendly'.
- Output to PDF with weasyprint.
- Export matplotlib plots as SVG by default.
- Use `esparto.options` for configuring behaviour.


0.2.2 (2021-04-24)
------------------

Expand Down
8 changes: 3 additions & 5 deletions docs/04-about/roadmap.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## New Features
* Provide content support for
* Plotly
* Bokeh
* Altair
Potential features:

* Alternative themes
* Additional Bootstrap components
* User supplied Jinja templates
* Custom CSS
27,698 changes: 27,636 additions & 62 deletions docs/examples/iris-report.ipynb

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Welcome
Esparto is a super minimal frontend web framework written in Python. Its primary use is for generating shareable single page documents
Esparto is a simple HTML and PDF document generator for Python. Its primary use is for generating shareable single page reports
with content from popular analytics and data science libraries.

## Overview
The library provides a streamlined API that lets users define their page in terms of
The library features a streamlined API that defines pages in terms of
sections, rows, and columns; and an intelligent wrapping system that automatically
converts Python objects into content.

Expand All @@ -18,20 +18,25 @@ and fed into an HTML template with all style details and dependencies captured i
Esparto supports content rendering within Jupyter Notebooks, allowing users to interactively
and iteratively build documents without disrupting their workflow.

## Features
PDF conversion is provided by [Weasyprint](https://weasyprint.org/).

### Features
* Lightweight API
* Jupyter Notebook support
* No CSS or HTML required
* Device responsive display
* Self contained / inline dependencies
* Jupyter Notebook support
* Printer friendly formatting
* PDF output
* MIT License

## Supported Content
* Markdown text
### Supported Content
* Markdown
* Images
* Matplotlib figures
* Pandas DataFrames
* Bokeh objects
* Plotly figures
* Plots from:
* Matplotlib
* Bokeh
* Plotly

<br>
11 changes: 8 additions & 3 deletions esparto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"""Top-level package for esparto."""

from importlib.util import find_spec as _find_spec
from typing import Set
from pathlib import Path as _Path
from typing import Set as _Set

__author__ = """Dominic Thorn"""
__email__ = "[email protected]"
__version__ = "0.2.2"
__version__ = "0.2.3"

_MODULE_PATH: _Path = _Path(__file__).parent.absolute()


_OPTIONAL_DEPENDENCIES: set = {
Expand All @@ -16,9 +19,10 @@
"pandas",
"bokeh",
"plotly",
"weasyprint",
}

_INSTALLED_MODULES: Set[str] = {
_INSTALLED_MODULES: _Set[str] = {
x.name for x in [_find_spec(dep) for dep in _OPTIONAL_DEPENDENCIES] if x
}

Expand All @@ -31,3 +35,4 @@
Markdown,
)
from esparto._layout import Column, Page, Row, Section
from esparto._options import options
4 changes: 2 additions & 2 deletions esparto/_adaptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def content_adaptor_df(content: DataFrame) -> DataFramePd:
from matplotlib.figure import Figure # type: ignore

@content_adaptor.register(Figure)
def content_adaptor_fig(content: Figure) -> FigureMpl:
def content_adaptor_mpl(content: Figure) -> FigureMpl:
"""Convert Matplotlib Figure to FigureMpl content."""
return FigureMpl(content)

Expand All @@ -66,7 +66,7 @@ def content_adaptor_fig(content: Figure) -> FigureMpl:
from bokeh.layouts import LayoutDOM as BokehObject # type: ignore

@content_adaptor.register(BokehObject)
def content_adaptor_bokeh_layout(content: BokehObject) -> FigureBokeh:
def content_adaptor_bokeh(content: BokehObject) -> FigureBokeh:
"""Convert Bokeh Layout to FigureBokeh content."""
return FigureBokeh(content)

Expand Down
Loading

0 comments on commit 52ea7ac

Please sign in to comment.