Skip to content

Commit

Permalink
Develop (#17)
Browse files Browse the repository at this point in the history
* Add Bootstrap dependencies for relevant content classes.
* Inherit FigureBokeh height from Bokeh object.
* Fix issues with in-notebook content rendering.
  • Loading branch information
domvwt authored Apr 24, 2021
1 parent baf057a commit f79ff26
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 129 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Scratch files for testing
scratch.ipynb
scratch.py
*scratch*.ipynb
*scratch*.py
image.jpg
esparto-doc.html
esparto-quick.html
docs/examples/*.html

# IDE files
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install:
- poetry install $INSTALL_DEPS -E test

script:
- python -m tests.check_package_version
- black --check .
- flake8
- mypy esparto tests
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ mypy: ## check type hints

test: ## run tests quickly with the default Python
pytest
python -m tests.check_package_version

test-all: ## run tests on every Python version with tox
tox --skip-missing-interpreters
Expand Down
Binary file added devdocs/classes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/02-user-guide/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The [pandas-bokeh](https://github.com/PatrikHlobil/Pandas-Bokeh) library offers
with few lines of code.

With the [Plotly backend for Pandas](https://plotly.com/python/pandas-backend/)
we can access the Plotly Express API directly from the '.plot()' method of any DataFrame or Series.
we can access the Plotly Express API directly from the `.plot()` method of any DataFrame or Series.

This notebook shows basic examples from each library:

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

0.2.1 (2021-04-24)
------------------

- Add Bootstrap dependencies for relevant content classes.
- Inherit FigureBokeh height from Bokeh object.
- Fix issues with in-notebook content rendering.


0.2.0 (2021-04-23)
------------------

- Add support for Bokeh and Plotly.


0.1.2 (2021-04-09)
------------------

Expand All @@ -17,3 +31,5 @@ Release Notes
------------------

- First public release.

<br>
96 changes: 59 additions & 37 deletions docs/examples/interactive-plots.ipynb

Large diffs are not rendered by default.

211 changes: 146 additions & 65 deletions docs/examples/iris-report.ipynb

Large diffs are not rendered by default.

Binary file added docs/examples/iris-virginica.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion esparto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__author__ = """Dominic Thorn"""
__email__ = "[email protected]"
__version__ = "0.2.0"
__version__ = "0.2.1"


_OPTIONAL_DEPENDENCIES: set = {
Expand Down
21 changes: 13 additions & 8 deletions esparto/_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def __init__(self, text):
raise TypeError(r"text must be str")

self.content = str(text)
self._dependencies = set()
self._dependencies = {"bootstrap"}

def to_html(self) -> str:
html = md.markdown(self.content)
html = f"{html}\n"
html = f"<div class='container-fluid px-1'>\n{html}\n</div>"
html = f"<div class='container px-1'>\n{html}\n</div>"
return html


Expand Down Expand Up @@ -212,6 +212,7 @@ def __init__(
self.alt_text = alt_text
self.caption = caption
self.scale = scale
self._dependencies = {"bootstrap"}

def rescale(self, scale) -> "Image":
"""Rescale the image prior to rendering.
Expand Down Expand Up @@ -293,6 +294,7 @@ def __init__(
self.content = df
self.index = index
self.col_space = col_space
self._dependencies = {"bootstrap"}

def to_html(self) -> str:
classes = "table table-sm table-striped table-hover table-bordered"
Expand Down Expand Up @@ -332,8 +334,8 @@ class FigureBokeh(Content):
Args:
figure (bokeh.layouts.LayoutDOM): A Bokeh object.
width (int): Width in pixels. (default = 'auto')
height (int): Height in pixels. (default = 'auto')
width (int): Width in pixels. (default = from figure or 'auto')
height (int): Height in pixels. (default = from figure or 'auto')
"""

Expand Down Expand Up @@ -401,8 +403,11 @@ def __init__(
if not issubclass(type(figure), BokehObject):
raise TypeError(r"figure must be a Bokeh object")

self.width = width or "auto"
self.height = height or "auto"
fig_width = figure.properties_with_values().get("width")
fig_height = figure.properties_with_values().get("height")

self.width = width or fig_width or "auto"
self.height = height or fig_height or "auto"

# Required as deep copy is not defined for Bokeh figures
# Also need to catch some erroneous args that get passed to the function
Expand All @@ -425,7 +430,7 @@ class FigurePlotly(Content):
Args:
figure (plotly.graph_objs._figure.Figure): A Plotly figure.
width (int): Width in pixels. (default = 'auto')
height (int): Height in pixels. (default = 500')
height (int): Height in pixels. (default = 500)
"""

Expand Down Expand Up @@ -488,8 +493,8 @@ def __init__(self, figure: "PlotlyFigure", width: int = None, height: int = None
self.width = width or figure.layout["width"] or "auto"
self.height = height or figure.layout["height"] or 500

self._dependencies = {"plotly"}
self.content = figure
self._dependencies = {"plotly"}

def to_html(self) -> str:
html = plotly_to_html(self.content, include_plotlyjs=False, full_html=False)
Expand Down
11 changes: 7 additions & 4 deletions esparto/_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,22 @@ def nb_display(

head_deps = "\n".join(_get_head_deps(required_deps))
tail_deps = "\n".join(_get_tail_deps(required_deps))
content_html = f"<div class='container-fluid' style='width: 100%; height: 100%;'>\n{item.to_html()}\n</div>"
content_html = f"<div class='container' style='width: 100%; height: 100%;'>\n{item.to_html()}\n</div>"

render_html = (
f"<!doctype html>\n<html>\n<head>{head_deps}</head>\n"
f"<body>\n{content_html}\n{tail_deps}\n</body>\n</html>\n"
)

print()
display(HTML(render_html), metadata=dict(isolated=True))
# This allows time to download plotly.js from the CDN - otherwise cell renders empty
# TODO: Make this asynchronous
if "plotly" in required_deps:
time.sleep(1)
display(
HTML(f"<head>\n{head_deps}\n</head>\n"), metadata=dict(isolated=True)
)
time.sleep(2)

display(HTML(render_html, metadata=dict(isolated=True)))
print()

# Prevent output scrolling
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "esparto"
version = "0.2.0"
version = "0.2.1"
description = "Minimal frontend web framework written in Python."
authors = ["Dominic Thorn <[email protected]>"]
license = "MIT"
Expand Down
21 changes: 12 additions & 9 deletions tests/check_package_version.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import sys
from pathlib import Path

import esparto
import esparto as es


def check_package_version():
if sys.version >= "3.8.0":
from importlib.metadata import version
pyproject_file = Path("pyproject.toml").read_text()
pyproject_version = pyproject_file.split("version", 1)[1].split('"')[1]
module_version = es.__version__

if esparto.__version__ == version("esparto"):
print("Version number up to date!")
else:
print("Please bump version number!")
if module_version == pyproject_version:
print("Version number up to date!")
exit(0)
else:
assert True
print("Please bump version number!")
print("pyproject.toml:", pyproject_version)
print("esparto.__version__:", module_version)
exit(1)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def test_all_content_classes_covered(content_list_fn):
module_all = set(chain.from_iterable(module_subclasses)) | module_classes
assert module_all <= test_classes

def test_all_content_classes_have_deps(content_list_fn):
deps = [c._dependencies for c in content_list_fn]
assert all(deps)


@pytest.mark.parametrize("a", content_list)
@pytest.mark.parametrize("b", content_list)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ commands =
alldeps: poetry install -v --no-root -E test
mindeps: poetry install -v --no-root --no-dev -E test
poetry run coverage run -am pytest
poetry run python -m tests.check_package_version

[testenv:setup]
deps =
Expand Down

0 comments on commit f79ff26

Please sign in to comment.