Skip to content

Commit

Permalink
Merge pull request #13 from evtn/dev
Browse files Browse the repository at this point in the history
1.1.5
  • Loading branch information
evtn authored Apr 26, 2023
2 parents 54cedc9 + d62c8b6 commit 8730ab1
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 252 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:

- run: python -m pip install mypy

- run: python -m mypy soda/*.py --disallow-any-expr --enable-recursive-aliases
- run: python -m mypy soda/*.py --disallow-any-expr --pretty --show-error-codes

run-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

name: Run Tests

Expand All @@ -46,7 +46,30 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- run: python -m pip install pytest
# I couldn't get poetry install to work on CI ¯\_(ツ)_/¯
- run: python -m pip install pytest coverage coveralls typing-extensions

- name: Test
run: python -m pytest test/
run: coverage run -m pytest test/

update-coverage:
runs-on: ubuntu-latest
name: Update Coverage

steps:
- name: git-checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4

- run: python -m pip install pytest coverage coveralls typing-extensions

- name: Test
run: coverage run --include "soda/*" -m pytest test/

- name: Coveralls update

run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ print(root.render(pretty=True))

## Installation

Just use `python setup.py` or `python -m pip install soda-svg`
Install `soda-svg` from PyPI, like `python -m pip install soda-svg`.

Note that `soda` on PyPI is a different package.

## Tag construction

Expand Down Expand Up @@ -506,15 +508,9 @@ soda is able to render tens of thousands tags per second, but if you wanna optim

### Building a tree efficiently

If you using the same structure many times (especially if it's a heavy one), avoid rebuilds. Rather than building a new tree every time, consider changing specific parts of it when needed. It won't speed up the render time, though
If you using the same structure many times (especially if it's a heavy one), avoid rebuilds. Rather than building a new tree every time, consider changing specific parts of it when needed. It won't speed up the render time, though (check Prerendering right below for that)

### Prerendering

If you have some static tags, you can use `tag.prerender()` to get a prerendered `Literal`.
This could speed up your render significantly in some cases.

### Pretty or not?

Pretty render gives a nice formatted output, which is very readable.
~~But using `pretty=True` in rendering would make renders 3-5x slower than default `pretty=False`.~~
Starting with 0.1.5 version, pretty rendering is roughly the same in speed as default one.
This could speed up your render significantly in some complex cases.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "soda-svg"
packages = [{include = "soda"}]
version = "1.1.3"
version = "1.1.5"
description = "Fast SVG generation tool"
authors = ["Dmitry Gritsenko <[email protected]>"]
license = "MIT"
Expand All @@ -11,7 +11,7 @@ homepage = "https://github.com/evtn/soda"
keywords = ["soda", "svg", "xml"]

[tool.poetry.dependencies]
python = "^3.7"
python = ">=3.7.0"

[tool.poetry.dev-dependencies]

Expand Down
10 changes: 5 additions & 5 deletions soda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .tags import Tag, Literal, Fragment
from .custom_tags import Root, XMLDeclaration
from .paths import Path
from .point import Point, PointPath
from .config import config
from .tags import Tag as Tag, Literal as Literal, Fragment as Fragment
from .custom_tags import Root as Root, XMLDeclaration as XMLDeclaration
from .paths import Path as Path
from .point import Point as Point, PointPath as PointPath
from .config_mod import config as config
File renamed without changes.
27 changes: 15 additions & 12 deletions soda/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from base64 import b64encode
from typing import BinaryIO
from soda.tags import Node, Tag
from .tags import Node, Tag


class Root(Tag):
Expand All @@ -29,17 +29,24 @@ def __init__(self, version: str = "1.0", encoding: str = "UTF-8"):

class Image(Tag):
"""
Simple <image> tag wrapper.
- Pass a url as a `source`.
Simple <image> tag wrapper.
- Pass a url as a `source`.
- To use `xlink:href` along `href` pass `use_xlink=True`
- To use only `xlink:href`, pass `use_xlink_only=True`
- To create from file (as base64 dataurl) use `Image.from_file(file_object: BinaryIO, extension: str, **init_kwargs)`
- ...or `Image.from_filename(filename: str, extension: str, **init_kwargs)`
"""
def __init__(self, source: str, use_xlink: bool = False, use_xlink_only: bool = False, **attributes: Node):

def __init__(
self,
source: str,
use_xlink: bool = False,
use_xlink_only: bool = False,
**attributes: Node,
):
super().__init__("image")
if not use_xlink_only:
self.set_attribute("href", source)
Expand All @@ -49,17 +56,13 @@ def __init__(self, source: str, use_xlink: bool = False, use_xlink_only: bool =

self(**attributes)


@staticmethod
def from_file(file_object: BinaryIO, extension: str, **init_kwargs: bool) -> Image:
contents: str = b64encode(file_object.read()).decode('ascii')
contents: str = b64encode(file_object.read()).decode("ascii")

return Image(
f"data:image/{extension};base64,{contents}",
**init_kwargs
)
return Image(f"data:image/{extension};base64,{contents}", **init_kwargs)

@staticmethod
def from_filename(filename: str, extension: str, **init_kwargs: bool) -> Image:
with open(filename, "rb") as file:
return Image.from_file(file, extension, **init_kwargs)
return Image.from_file(file, extension, **init_kwargs)
Loading

0 comments on commit 8730ab1

Please sign in to comment.