Skip to content

Commit

Permalink
Merge pull request #21 from evtn/dev
Browse files Browse the repository at this point in the history
formatting and hashing
  • Loading branch information
evtn authored Oct 10, 2024
2 parents de3d8fc + 67554be commit 97710c6
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion 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 = "2.0.2"
version = "2.0.3"
description = "Fast SVG generation tool"
authors = ["Dmitry Gritsenko <soda@evtn.ru>"]
license = "MIT"
Expand Down
18 changes: 14 additions & 4 deletions soda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from .tags import Tag as Tag, Literal as Literal, Fragment as Fragment
from .tags import Fragment as Fragment
from .tags import Literal as Literal
from .tags import Tag as Tag

from .config_mod import config as config
from .custom_tags import (
Root as Root,
XMLDeclaration as XMLDeclaration,
)

from .custom_tags import (
XMLComment as XMLComment,
)
from .custom_tags import (
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
from .point import Point as Point
from .point import PointPath as PointPath
2 changes: 1 addition & 1 deletion soda/config_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ class config:
decimal_length = 3
replace_underscores = True
strip_underscores = True
tab_char: str = " "
tab_char: str = " "
3 changes: 2 additions & 1 deletion soda/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from base64 import b64encode
from os import PathLike
from pathlib import Path
from typing import BinaryIO

from wordstreamer import Context, TokenStream

from .tags import Literal, Node, Tag
from pathlib import Path


class Root(Tag):
Expand Down
1 change: 1 addition & 0 deletions soda/paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

from .utils import trunc


Expand Down
15 changes: 9 additions & 6 deletions soda/point.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from math import acos, cos, hypot, sin
from math import radians as degrees_to_radians
from typing import Iterator, Sequence, Union, overload
from math import cos, sin, hypot, acos, radians as degrees_to_radians

from .utils import eq
from .paths import Path, compact_path
from .tags import Node, Tag
from .utils import eq

PointLike = Union["Point", float, Sequence[float]]

Expand Down Expand Up @@ -92,14 +94,12 @@ def __iter__(self) -> Iterator[float]:
@overload
def rotate(
self, center: PointLike = 0, *, degrees: float, radians: None = None
) -> Point:
...
) -> Point: ...

@overload
def rotate(
self, center: PointLike = 0, *, degrees: None = None, radians: float
) -> Point:
...
) -> Point: ...

def rotate(
self,
Expand Down Expand Up @@ -157,6 +157,9 @@ def __eq__(self, other: object) -> bool:
other = Point.from_(other)
return eq((self - other).distance(), 0)

def __hash__(self) -> int:
return hash(self.coords)


class PointPath:
@staticmethod
Expand Down
33 changes: 13 additions & 20 deletions soda/tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from typing import Iterator, Optional, Sequence, Union, overload
from wordstreamer import Renderable, Context, TokenStream

from wordstreamer import Context, Renderable, TokenStream
from wordstreamer.stream_utils import separated

FlatNode = Union["Renderable", str, float]
Expand Down Expand Up @@ -60,16 +62,13 @@ def copy(self) -> Tag:
)

@overload
def set_attribute(self, attr: str, value: None) -> None:
...
def set_attribute(self, attr: str, value: None) -> None: ...

@overload
def set_attribute(self, attr: str, value: Node) -> Node:
...
def set_attribute(self, attr: str, value: Node) -> Node: ...

@overload
def set_attribute(self, attr: str, value: Node | None) -> Node | None:
...
def set_attribute(self, attr: str, value: Node | None) -> Node | None: ...

def set_attribute(self, attr: str, value: Optional[Node]) -> Optional[Node]:
"""sets tag attribute to value. If None is passed, deletes attribute"""
Expand All @@ -86,18 +85,15 @@ def get_attribute(self, attr: str) -> Optional[Node]:
return self.attributes.get(normalize_ident(attr))

@overload
def __setitem__(self, item: str | int | slice, value: Node) -> Node:
...
def __setitem__(self, item: str | int | slice, value: Node) -> Node: ...

@overload
def __setitem__(self, item: str | int | slice, value: None) -> None:
...
def __setitem__(self, item: str | int | slice, value: None) -> None: ...

@overload
def __setitem__(
self, item: str | int | slice, value: Optional[Node]
) -> Optional[Node]:
...
) -> Optional[Node]: ...

def __setitem__(
self, item: str | int | slice, value: Optional[Node]
Expand All @@ -120,16 +116,13 @@ def __setitem__(
return self.set_attribute(item, value)

@overload
def __getitem__(self, item: int) -> Node:
...
def __getitem__(self, item: int) -> Node: ...

@overload
def __getitem__(self, item: slice) -> list[Node]:
...
def __getitem__(self, item: slice) -> list[Node]: ...

@overload
def __getitem__(self, item: str) -> Node:
...
def __getitem__(self, item: str) -> Node: ...

def __getitem__(
self, item: Union[str, int, slice]
Expand Down Expand Up @@ -397,5 +390,5 @@ def copy(self) -> Fragment:
return Fragment(*self.children)


from .xml_parse import xml_to_tag
from .utils import escape, node_iterator, normalize_ident, trunc
from .xml_parse import xml_to_tag
2 changes: 1 addition & 1 deletion soda/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Callable, Iterable

from .tags import FlatNode, Fragment, Node
from .config_mod import config
from .tags import FlatNode, Fragment, Node

char_range: Callable[[str, str], "map[str]"] = lambda s, e: map(
chr, range(ord(s), ord(e) + 1)
Expand Down
3 changes: 3 additions & 0 deletions soda/xml_parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from typing import Iterable

import lxml.etree as etree

from .custom_tags import XMLComment
from .tags import Literal, Tag

Expand Down
5 changes: 3 additions & 2 deletions test/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from os import remove
from pathlib import Path
from typing import BinaryIO

from soda.custom_tags import Image, Root, XMLComment, XMLDeclaration
from pathlib import Path
from os import remove


class FileMock(BinaryIO):
Expand Down
3 changes: 2 additions & 1 deletion test/test_point.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from math import pi

import pytest
from soda import Point
from soda.utils import eq
import pytest


class TestClass:
Expand Down
3 changes: 1 addition & 2 deletions test/test_render.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from soda import Tag, Literal
from soda import config
from soda import Literal, Tag, config
from soda.tags import Fragment


Expand Down

0 comments on commit 97710c6

Please sign in to comment.