Skip to content

Commit

Permalink
remove deprecated attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Aug 28, 2021
1 parent 77eb2a0 commit 730544f
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Features:

+ Compatible with all SVG standards: 1.1, 1.2, 2.0, Tiny.
+ 100% type safe.
+ Pure Python
+ Pure Python.
+ No third-party runtime dependencies.
+ No deprecated attributes, only what actually works.

Based on [svg-xsd-schema](https://github.com/dumistoklus/svg-xsd-schema/blob/master/svg.xsd).
29 changes: 29 additions & 0 deletions scripts/actualize_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path

PROJECT_ROOT = Path(__file__).parent.parent.absolute()


def get_attrs_ref_root() -> Path:
mdn_root = PROJECT_ROOT.parent / 'mdn-source'
svg_ref_root = mdn_root / 'files' / 'en-us' / 'web' / 'svg'
return svg_ref_root / 'attribute'


def is_deprecated(path: Path) -> bool:
path /= 'index.html'
if not path.is_file():
return False
content = path.read_text()
return '{{Deprecated_Header}}' in content


def run() -> None:
out_path = PROJECT_ROOT / 'tests' / 'fixtures' / 'deprecated.txt'
with out_path.open('w') as out_stream:
for ref_path in get_attrs_ref_root().iterdir():
if is_deprecated(ref_path):
print(ref_path.name, file=out_stream)


if __name__ == '__main__':
run()
Binary file added svg/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added svg/__pycache__/_mixins.cpython-39.pyc
Binary file not shown.
Binary file added svg/__pycache__/elements.cpython-39.pyc
Binary file not shown.
Binary file added svg/__pycache__/enums.cpython-39.pyc
Binary file not shown.
Binary file added svg/__pycache__/filters.cpython-39.pyc
Binary file not shown.
Binary file added svg/__pycache__/values.cpython-39.pyc
Binary file not shown.
9 changes: 0 additions & 9 deletions svg/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ class Color(AttrsMixin):
color_rendering: Optional[enums.Rendering] = None


@dataclass
class Containers(AttrsMixin):
enable_background: Optional[values.EnableBackground] = None


@dataclass
class FeFlood(AttrsMixin):
flood_color: Optional[str] = None
Expand Down Expand Up @@ -129,8 +124,6 @@ class TextContentElements(AttrsMixin):
baseline_shift: Optional[enums.BaselineShift] = None
direction: Optional[enums.TextDirection] = None
dominant_baseline: Optional[enums.DominantBaseline] = None
glyph_orientation_horizontal: Optional[values.GlyphOrientationHorizontal] = None
glyph_orientation_vertical: Optional[values.GlyphOrientationVertical] = None
letter_spacing: Optional[enums.TextSpacing] = None
text_anchor: Optional[enums.TextAnchor] = None
text_decoration: Optional[enums.TextDecoration] = None
Expand All @@ -151,7 +144,6 @@ class Viewports(AttrsMixin):

class Presentation(
Color,
Containers,
FeFlood,
FillStroke,
FilterPrimitives,
Expand Down Expand Up @@ -182,7 +174,6 @@ class FilterPrimitive(AttrsMixin):
class ComponentTransferFunction(AttrsMixin):
type: enums.ComponentTransferType
tableValues: Optional[str] = None
slope: Optional[float] = None
intercept: Optional[float] = None
amplitude: Optional[float] = None
exponent: Optional[float] = None
Expand Down
1 change: 0 additions & 1 deletion svg/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ class FontFace(Element, m.StdAttrs):
panose_1: Optional[str] = None
stemv: Optional[float] = None
stemh: Optional[float] = None
slope: Optional[float] = None
cap_height: Optional[float] = None
x_height: Optional[float] = None
accent_height: Optional[float] = None
Expand Down
2 changes: 0 additions & 2 deletions svg/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class ViewBoxSpec:
Coordinate = Union[Number, Length]
FontSize = Union[Length, INHERIT]
FontSizeAdjust = Union[Number, NONE, INHERIT]
GlyphOrientationHorizontal = Union[Angle, INHERIT]
GlyphOrientationVertical = Union[Angle, INHERIT, AUTO]
Kerning = Union[Length, AUTO, INHERIT]
NumberOptionalNumber = Union[Number, Tuple[Number, Number]]
Opacity = Union[Number, INHERIT]
Expand Down
Binary file not shown.
55 changes: 55 additions & 0 deletions tests/fixtures/deprecated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
u2
v-ideographic
format
glyph-orientation-horizontal
k
unicode-range
vert-adv-y
cap-height
xlink_colon_show
g2
attributetype
glyphref
string
g1
xlink_colon_title
panose-1
glyph-name
hanging
v-hanging
xlink_colon_type
slope
unicode
u1
xml_colon_space
baseprofile
xlink_colon_arcrole
horiz-origin-y
zoomandpan
kernelunitlength
xml_colon_base
orientation
stemv
version
v-alphabetic
horiz-origin-x
vert-origin-y
glyph-orientation-vertical
stemh
v-mathematical
vert-origin-x
ideographic
kerning
requiredfeatures
mathematical
color-profile
name
arabic-form
units-per-em
widths
viewtarget
x-height
descent
enable-background
xlink_colon_href
horiz-adv-x
33 changes: 33 additions & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

from dataclasses import fields
from typing import Set
from pathlib import Path
import pytest

import svg
from svg._mixins import AttrsMixin


FIXTURES = Path(__file__).parent / 'fixtures'
DEPRECATED = (FIXTURES / 'deprecated.txt').read_text().split()


def get_attrs(cls) -> Set[str]:
result = set()
for field in fields(cls):
key = field.name
if key == 'elements':
continue
key = key.rstrip('_')
key = key.replace('__', ':')
key = key.replace('_', '-')
result.add(key)
return result


@pytest.mark.parametrize('cls', AttrsMixin.__subclasses__())
@pytest.mark.parametrize('name', DEPRECATED)
def test_no_deprecated_mixins(cls: AttrsMixin, name: str):
name = name.replace('_colon_', ':')
attrs = get_attrs(cls)
assert name not in attrs

0 comments on commit 730544f

Please sign in to comment.