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 {
steps {
sh 'python -m venv .venv'
sh """. .venv/bin/activate
pip install pytest twine
pip install pytest twine mypy
pip install -e ."""
}
}
......@@ -16,6 +16,13 @@ pipeline {
"""
}
}
stage('mypy') {
steps {
sh """. .venv/bin/activate
mypy --junit-xml=test_annotations.xml darwcss/
"""
}
}
stage('build') {
steps {
sh """. .venv/bin/activate
......@@ -47,6 +54,7 @@ pipeline {
post {
always {
junit 'test_results.xml'
junit 'test_annotations.xml'
}
}
}
from __future__ import annotations
from contextlib import contextmanager
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 textwrap import indent
from colorsys import rgb_to_hls, rgb_to_hsv, rgb_to_yiq
def render(obj):
def render(obj: Any) -> str:
if hasattr(obj, "__render__"):
return obj.__render__()
elif obj is None:
......@@ -16,13 +17,13 @@ def render(obj):
class RenderableObject:
def __render__(self):
def __render__(self) -> str:
pass
def __add__(self, other):
def __add__(self, other: RenderableObject) -> str:
return f"{render(self)} {render(other)}"
def __radd__(self, other):
def __radd__(self, other: RenderableObject) -> str:
return f"{render(other)} {render(self)}"
......@@ -33,7 +34,7 @@ class ColorValue(RenderableObject):
blue: int
typ: str = "rgb"
def __render__(self):
def __render__(self) -> str:
return (
f"rgb({self.red}, {self.green}, {self.blue})"
if self.typ == "rgb"
......@@ -46,7 +47,7 @@ class NumericValue(RenderableObject):
value: Union[float, int]
unit: str
def __render__(self):
def __render__(self) -> str:
return f"{self.value}{self.unit}"
......@@ -56,9 +57,9 @@ class Style:
value: Any
important: bool = False
def __post_init__(self):
def __post_init__(self) -> None:
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
if l.get("DARWCSS_AUTO", g.get("DARWCSS_AUTO", False)):
try:
......@@ -77,23 +78,23 @@ class Selector:
area: str
styles: List[Style] = field(default_factory=list)
def __add__(self, other):
def __add__(self, other: Style) -> None:
self.styles.append(other)
def __iadd__(self, other):
def __iadd__(self, other: Style) -> Selector:
self + other
return self
def append(self, other):
def append(self, other: Style) -> None:
self.styles.append(other)
class CSS:
def __init__(self, conf=None):
self.selectors = []
def __init__(self, conf: Optional[Dict] = None) -> None:
self.selectors: List[Selector] = []
self.conf = conf or {}
def render(self):
def render(self) -> str:
css = ""
for selector in self.selectors:
rules = ""
......@@ -103,7 +104,7 @@ class CSS:
return css
@contextmanager
def selector(self, area):
def selector(self, area: str) -> Generator[Selector, None, None]:
selector = Selector(area)
try:
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