Kaydet (Commit) 9563e8ab authored tarafından Batuhan Osman TASKAYA's avatar Batuhan Osman TASKAYA

type annoations, mypy integration

üst c7c1e699
...@@ -5,7 +5,7 @@ pipeline { ...@@ -5,7 +5,7 @@ pipeline {
steps { steps {
sh 'python -m venv .venv' sh 'python -m venv .venv'
sh """. .venv/bin/activate sh """. .venv/bin/activate
pip install pytest twine pip install pytest twine mypy
pip install -e .""" pip install -e ."""
} }
} }
...@@ -16,6 +16,13 @@ pipeline { ...@@ -16,6 +16,13 @@ pipeline {
""" """
} }
} }
stage('mypy') {
steps {
sh """. .venv/bin/activate
mypy --junit-xml=test_annotations.xml darwcss/
"""
}
}
stage('build') { stage('build') {
steps { steps {
sh """. .venv/bin/activate sh """. .venv/bin/activate
...@@ -47,6 +54,7 @@ pipeline { ...@@ -47,6 +54,7 @@ pipeline {
post { post {
always { always {
junit 'test_results.xml' junit 'test_results.xml'
junit 'test_annotations.xml'
} }
} }
} }
from __future__ import annotations
from contextlib import contextmanager from contextlib import contextmanager
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import List, Any, Union from typing import List, Any, Union, Optional, Generator, Dict
from inspect import currentframe from inspect import currentframe
from textwrap import indent from textwrap import indent
from colorsys import rgb_to_hls, rgb_to_hsv, rgb_to_yiq from colorsys import rgb_to_hls, rgb_to_hsv, rgb_to_yiq
def render(obj): def render(obj: Any) -> str:
if hasattr(obj, "__render__"): if hasattr(obj, "__render__"):
return obj.__render__() return obj.__render__()
elif obj is None: elif obj is None:
...@@ -16,13 +17,13 @@ def render(obj): ...@@ -16,13 +17,13 @@ def render(obj):
class RenderableObject: class RenderableObject:
def __render__(self): def __render__(self) -> str:
pass pass
def __add__(self, other): def __add__(self, other: RenderableObject) -> str:
return f"{render(self)} {render(other)}" return f"{render(self)} {render(other)}"
def __radd__(self, other): def __radd__(self, other: RenderableObject) -> str:
return f"{render(other)} {render(self)}" return f"{render(other)} {render(self)}"
...@@ -33,7 +34,7 @@ class ColorValue(RenderableObject): ...@@ -33,7 +34,7 @@ class ColorValue(RenderableObject):
blue: int blue: int
typ: str = "rgb" typ: str = "rgb"
def __render__(self): def __render__(self) -> str:
return ( return (
f"rgb({self.red}, {self.green}, {self.blue})" f"rgb({self.red}, {self.green}, {self.blue})"
if self.typ == "rgb" if self.typ == "rgb"
...@@ -46,7 +47,7 @@ class NumericValue(RenderableObject): ...@@ -46,7 +47,7 @@ class NumericValue(RenderableObject):
value: Union[float, int] value: Union[float, int]
unit: str unit: str
def __render__(self): def __render__(self) -> str:
return f"{self.value}{self.unit}" return f"{self.value}{self.unit}"
...@@ -56,9 +57,9 @@ class Style: ...@@ -56,9 +57,9 @@ class Style:
value: Any value: Any
important: bool = False important: bool = False
def __post_init__(self): def __post_init__(self) -> None:
self.value = render(self.value) self.value = render(self.value)
f = currentframe().f_back.f_back f = currentframe().f_back.f_back # type: ignore
l, g = f.f_locals, f.f_globals l, g = f.f_locals, f.f_globals
if l.get("DARWCSS_AUTO", g.get("DARWCSS_AUTO", False)): if l.get("DARWCSS_AUTO", g.get("DARWCSS_AUTO", False)):
try: try:
...@@ -77,23 +78,23 @@ class Selector: ...@@ -77,23 +78,23 @@ class Selector:
area: str area: str
styles: List[Style] = field(default_factory=list) styles: List[Style] = field(default_factory=list)
def __add__(self, other): def __add__(self, other: Style) -> None:
self.styles.append(other) self.styles.append(other)
def __iadd__(self, other): def __iadd__(self, other: Style) -> Selector:
self + other self + other
return self return self
def append(self, other): def append(self, other: Style) -> None:
self.styles.append(other) self.styles.append(other)
class CSS: class CSS:
def __init__(self, conf=None): def __init__(self, conf: Optional[Dict] = None) -> None:
self.selectors = [] self.selectors: List[Selector] = []
self.conf = conf or {} self.conf = conf or {}
def render(self): def render(self) -> str:
css = "" css = ""
for selector in self.selectors: for selector in self.selectors:
rules = "" rules = ""
...@@ -103,7 +104,7 @@ class CSS: ...@@ -103,7 +104,7 @@ class CSS:
return css return css
@contextmanager @contextmanager
def selector(self, area): def selector(self, area: str) -> Generator[Selector, None, None]:
selector = Selector(area) selector = Selector(area)
try: try:
yield selector yield selector
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment