Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add as_float, change repr(x) -> str(x) #214

Merged
merged 15 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Regression tests

on:
push:
branches: [ main ]
branches: [ main, remove-animation ]
pull_request:
branches: [ main ]

Expand All @@ -12,7 +12,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
numpy-version: ["numpy<2.0.0", "numpy>=2.0.0"]
exclude:
- python-version: "3.8"
numpy-version: "numpy>=2.0.0"

steps:
- uses: actions/checkout@v3
Expand All @@ -25,6 +29,7 @@ jobs:
sudo apt-get install ffmpeg ghostscript
python -m pip install --upgrade pip
pip install coveralls
pip install "${{ matrix.numpy-version }}"
pip install .[all]
- name: Run tests
run: |
Expand Down
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
9 changes: 0 additions & 9 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ Ghostscript, which can't be installed via pip. If you use `Conda <https://docs.

$ conda install ghostscript

ffmpeg
------

If you plan to render animated Toyplot figures as MP4 files, you'll need
ffmpeg, which also can't be installed via pip. If you use `Conda <https://docs.conda.io/en/latest/>`_
(again, strongly recommended), you can install it as follows::

$ conda install ffmpeg

.. _documentation:

Documentation
Expand Down
1 change: 0 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Python API
toyplot.locator.rst
toyplot.mark.rst
toyplot.marker.rst
toyplot.mp4.rst
toyplot.pdf.rst
toyplot.png.rst
toyplot.projection.rst
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ custom_inherit
ipython
multipledispatch
nbsphinx
numpy
numpy < 2.0.0
pypng
reportlab
sphinx >= 3.5
Expand Down
7 changes: 0 additions & 7 deletions docs/toyplot.mp4.rst

This file was deleted.

1,405 changes: 233 additions & 1,172 deletions docs/tutorial.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion features/steps/administrivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# rights in this software.

from behave import *
import nose.tools

import os
import pkgutil
Expand Down
42 changes: 21 additions & 21 deletions features/steps/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import importlib
import io
import nose.tools
import numpy
import os
import xml.etree.ElementTree as xml

import test
import testing

if not os.path.exists(testing.backend_dir):
Expand All @@ -30,22 +30,22 @@ def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.html" % context.name)
context.backend.render(context.canvas, target)
#html = xml.parse(target)
#nose.tools.assert_equal(html.getroot().tag, "{http://www.w3.org/2000/svg}svg")
#test.assert_equal(html.getroot().tag, "{http://www.w3.org/2000/svg}svg")


@then(u'the canvas can be rendered to an html buffer')
def step_impl(context):
buffer = io.BytesIO()
context.backend.render(context.canvas, buffer)
#html = xml.parse(buffer.getvalue())
#nose.tools.assert_equal(html.getroot().tag, "html")
#test.assert_equal(html.getroot().tag, "html")


@then(u'the canvas can be rendered to a returned html dom')
def step_impl(context):
html = context.backend.render(context.canvas)
nose.tools.assert_is_instance(html, xml.Element)
nose.tools.assert_equal(html.tag, "div")
test.assert_is_instance(html, xml.Element)
test.assert_equal(html.tag, "div")


@then(u'the canvas can be rendered to a pdf file')
Expand All @@ -70,8 +70,8 @@ def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.png" % context.name)
context.backend.render(context.canvas, target)
image = testing.read_png(target)
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a png buffer')
Expand All @@ -81,58 +81,58 @@ def step_impl(context):
buffer.seek(0)

image = testing.read_png(buffer)
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a returned png document')
def step_impl(context):
png = context.backend.render(context.canvas)
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to a 200 pixel wide png document')
def step_impl(context):
png = context.backend.render(context.canvas, width="200px")
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (200, 200, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (200, 200, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'the canvas can be rendered to a 150 pixel high png document')
def step_impl(context):
png = context.backend.render(context.canvas, height="150px")
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (150, 150, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (150, 150, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'the canvas can be rendered to a half scale png document')
def step_impl(context):
png = context.backend.render(context.canvas, scale=0.5)
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (300, 300, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (300, 300, 4))
test.assert_equal(image.dtype, "uint8")


@then(u'the canvas can be rendered to an svg file')
def step_impl(context):
target = os.path.join(testing.backend_dir, "%s.svg" % context.name)
context.backend.render(context.canvas, target)
svg = xml.parse(target)
nose.tools.assert_equal(svg.getroot().tag, "{http://www.w3.org/2000/svg}svg")
test.assert_equal(svg.getroot().tag, "{http://www.w3.org/2000/svg}svg")


@then(u'the canvas can be rendered to an svg buffer')
def step_impl(context):
buffer = io.BytesIO()
context.backend.render(context.canvas, buffer)
#svg = xml.parse(buffer.getvalue())
#nose.tools.assert_equal(svg.getroot().tag, "svg")
#test.assert_equal(svg.getroot().tag, "svg")


@then(u'the canvas can be rendered to a returned svg dom')
def step_impl(context):
svg = context.backend.render(context.canvas)
nose.tools.assert_is_instance(svg, xml.Element)
nose.tools.assert_equal(svg.tag, "svg")
test.assert_is_instance(svg, xml.Element)
test.assert_equal(svg.tag, "svg")
1 change: 0 additions & 1 deletion features/steps/bar-visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import collections

import nose.tools
import numpy.testing
import toyplot

Expand Down
10 changes: 5 additions & 5 deletions features/steps/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from behave import *

import nose.tools
import test
import numpy
import sys
import toyplot.browser
Expand All @@ -17,10 +17,10 @@ def step_impl(context):
canvas, axes, mark = toyplot.plot(numpy.sin(numpy.linspace(0, 10)))
with unittest.mock.patch("webbrowser.open") as webbrowser_open:
toyplot.browser.show(canvas)
nose.tools.assert_equal(webbrowser_open.call_count, 1)
nose.tools.assert_true(
test.assert_equal(webbrowser_open.call_count, 1)
test.assert_true(
webbrowser_open.call_args[0][0].startswith("file://"))
nose.tools.assert_equal(webbrowser_open.call_args[1]["new"], 1)
nose.tools.assert_equal(webbrowser_open.call_args[1]["autoraise"], True)
test.assert_equal(webbrowser_open.call_args[1]["new"], 1)
test.assert_equal(webbrowser_open.call_args[1]["autoraise"], True)


8 changes: 4 additions & 4 deletions features/steps/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io

import nose.tools
import test
import numpy.testing
import toyplot

Expand Down Expand Up @@ -65,14 +65,14 @@ def step_impl(context):
@then(u'the canvas can be rendered in Jupyter as HTML')
def step_impl(context):
html = context.canvas._repr_html_()
nose.tools.assert_is_instance(html, str)
test.assert_is_instance(html, str)

@then(u'the canvas can be rendered in Jupyter as a PNG image')
def step_impl(context):
png = context.canvas._repr_png_()
image = testing.read_png(io.BytesIO(png))
nose.tools.assert_equal(image.shape, (600, 600, 4))
nose.tools.assert_equal(image.dtype, "uint8")
test.assert_equal(image.shape, (600, 600, 4))
test.assert_equal(image.dtype, "uint8")

@then(u'numberlines can be added to the canvas using relative coordinates')
def step_impl(context):
Expand Down
Loading
Loading