Kaydet (Commit) 1227c318 authored tarafından Batuhan Osman TASKAYA's avatar Batuhan Osman TASKAYA

flake 8 integration

üst 7ac05275
...@@ -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 mypy pip install pytest twine mypy flake8 mccabe lake8-junit-repor
pip install -e .""" pip install -e ."""
} }
} }
...@@ -16,10 +16,19 @@ pipeline { ...@@ -16,10 +16,19 @@ pipeline {
""" """
} }
} }
stage('flake8') {
steps {
sh """. .venv/bin/activate
flake8 --max-complexity 7 --output-file flake8_results.txt darwc
flake8_junit flake8_results.txt test_flake8.xml
rm flake8_results.txt
"""
}
}
stage('mypy') { stage('mypy') {
steps { steps {
sh """. .venv/bin/activate sh """. .venv/bin/activate
mypy --junit-xml=test_mpy.xml darwcss/ mypy --junit-xml=test_mypy.xml darwcss/
""" """
} }
} }
......
from __future__ import annotations 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, Optional, Generator, Dict from typing import List, Any, Union, Optional, Generator, Dict, Tuple
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
from enum import Enum
def render(obj: Any) -> str: def render(obj: Any) -> str:
...@@ -20,26 +21,41 @@ class RenderableObject: ...@@ -20,26 +21,41 @@ class RenderableObject:
def __render__(self) -> str: def __render__(self) -> str:
pass pass
def __add__(self, other: RenderableObject) -> str: def __add__(self, other: RenderableObject) -> str: # noqa:F821 https://github.com/PyCQA/pyflakes/issues/373
return f"{render(self)} {render(other)}" return f"{render(self)} {render(other)}"
def __radd__(self, other: RenderableObject) -> str: def __radd__(self, other: RenderableObject) -> str: # noqa:F821
return f"{render(other)} {render(self)}" return f"{render(other)} {render(self)}"
class ColorTypes(Enum):
RGB = 0
HLS = 1
HEX = 2
@dataclass @dataclass
class ColorValue(RenderableObject): class ColorValue(RenderableObject):
red: int red: int
green: int green: int
blue: int blue: int
typ: str = "rgb" typ: ColorTypes = ColorTypes.RGB
def __render__(self) -> str: def __render__(self) -> str:
return ( if self.typ is ColorTypes.RGB:
f"rgb({self.red}, {self.green}, {self.blue})" return f"rgb({self.red}, {self.green}, {self.blue})"
if self.typ == "rgb" elif self.typ is ColorTypes.HLS:
else f"#{self.red}{self.green}{self.blue}" return f"hls({self.red}, {self.green}%, {self.blue}%)"
) elif self.typ is ColorTypes.HEX:
return f"#{self.red}{self.green}{self.blue}"
else:
raise ValueError("ColorValue type must be a valid ColorTypes attribute")
def to_hls(self) -> Union[Tuple[float, float, float], NotImplemented]:
if self.typ is ColorTypes.RGB:
return rgb_to_hls(self.red, self.green, self.blue)
else:
return NotImplemented
@dataclass @dataclass
...@@ -59,7 +75,7 @@ class Style: ...@@ -59,7 +75,7 @@ class Style:
def __post_init__(self) -> None: def __post_init__(self) -> None:
self.value = render(self.value) self.value = render(self.value)
f = currentframe().f_back.f_back # type: ignore 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:
...@@ -81,7 +97,7 @@ class Selector: ...@@ -81,7 +97,7 @@ class Selector:
def __add__(self, other: Style) -> None: def __add__(self, other: Style) -> None:
self.styles.append(other) self.styles.append(other)
def __iadd__(self, other: Style) -> Selector: def __iadd__(self, other: Style) -> Selector: # noqa:F821
self + other self + other
return self return self
......
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