Added pre-commit hooks to check static styling

pull/855/head
Dov Benyomin Sohacheski 3 years ago
parent 101b732ae0
commit fe7aaf1532

@ -33,3 +33,5 @@ jobs:
run: | run: |
poetry install poetry install
poetry run python -m unittest -v tests/*.py poetry run python -m unittest -v tests/*.py
- name: Run static checks
run: pre-commit run --all-files

@ -1,9 +1,9 @@
repos: repos:
# - repo: https://github.com/pycqa/isort - repo: https://github.com/pycqa/isort
# rev: 5.12.0 rev: 5.12.0
# hooks: hooks:
# - id: isort - id: isort
# name: Run isort to sort imports in Python files name: Run isort to sort imports in Python files
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 rev: v4.4.0
@ -15,26 +15,8 @@ repos:
- id: trailing-whitespace - id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ] args: [ --markdown-linebreak-ext=md ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args: [ --write-changes ]
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 23.1.0 rev: 23.1.0
hooks: hooks:
- id: black - id: black
name: Run black (python formatter) name: Run black (python formatter)
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.198
hooks:
- id: ruff
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.991
# hooks:
# - id: mypy
# args: [ . ]
# pass_filenames: false

@ -2,7 +2,7 @@ import contextvars
import os import os
import uuid import uuid
from pathlib import Path from pathlib import Path
from typing import List, Union, Dict from typing import Dict, List, Union
from graphviz import Digraph from graphviz import Digraph

@ -3,7 +3,8 @@ A set of nodes and edges to visualize software architecture using the C4 model.
""" """
import html import html
import textwrap import textwrap
from diagrams import Cluster, Node, Edge
from diagrams import Cluster, Edge, Node
def _format_node_label(name, key, description): def _format_node_label(name, key, description):

@ -26,3 +26,6 @@ pre-commit = "^3.0.4"
[tool.black] [tool.black]
line-length = 120 line-length = 120
[tool.isort]
profile = "black"

@ -5,7 +5,8 @@ from typing import Iterable
from jinja2 import Environment, FileSystemLoader, Template, exceptions from jinja2 import Environment, FileSystemLoader, Template, exceptions
import config as cfg import config as cfg
from . import app_root_dir, doc_root_dir, resource_dir, template_dir, base_dir
from . import app_root_dir, base_dir, doc_root_dir, resource_dir, template_dir
_usage = "Usage: generate.py <provider>" _usage = "Usage: generate.py <provider>"
@ -42,11 +43,11 @@ def gen_classes(pvd: str, typ: str, paths: Iterable[str]) -> str:
def gen_apidoc(pvd: str, typ_paths: dict) -> str: def gen_apidoc(pvd: str, typ_paths: dict) -> str:
try: try:
default_tmp = cfg.TMPL_APIDOC.split('.') default_tmp = cfg.TMPL_APIDOC.split(".")
tmpl_file = f"{default_tmp[0]}_{pvd}.{default_tmp[1]}" tmpl_file = f"{default_tmp[0]}_{pvd}.{default_tmp[1]}"
tmpl = load_tmpl(tmpl_file) tmpl = load_tmpl(tmpl_file)
except exceptions.TemplateNotFound: except exceptions.TemplateNotFound:
tmpl = load_tmpl(cfg.TMPL_APIDOC) tmpl = load_tmpl(cfg.TMPL_APIDOC)
# TODO: remove # TODO: remove
def _gen_class_name(path: str) -> str: def _gen_class_name(path: str) -> str:

@ -11,6 +11,7 @@ import subprocess
import sys import sys
import config as cfg import config as cfg
from . import resource_dir from . import resource_dir
_usage = "Usage: resource.py <cmd> <pvd>" _usage = "Usage: resource.py <cmd> <pvd>"
@ -84,6 +85,7 @@ def cleaner_k8s(f):
break break
return f.lower() return f.lower()
def cleaner_digitalocean(f): def cleaner_digitalocean(f):
f = f.replace("-32", "") f = f.replace("-32", "")
for p in cfg.FILE_PREFIXES["digitalocean"]: for p in cfg.FILE_PREFIXES["digitalocean"]:

@ -3,9 +3,15 @@ import random
import string import string
import unittest import unittest
from diagrams import Diagram from diagrams import Diagram, setcluster, setdiagram
from diagrams import setcluster, setdiagram from diagrams.c4 import (
from diagrams.c4 import Person, Container, Database, System, SystemBoundary, Relationship Container,
Database,
Person,
Relationship,
System,
SystemBoundary,
)
class C4Test(unittest.TestCase): class C4Test(unittest.TestCase):

@ -1,10 +1,18 @@
import os import os
import pathlib
import shutil import shutil
import unittest import unittest
import pathlib
from diagrams import Cluster, Diagram, Edge, Node from diagrams import (
from diagrams import getcluster, getdiagram, setcluster, setdiagram Cluster,
Diagram,
Edge,
Node,
getcluster,
getdiagram,
setcluster,
setdiagram,
)
class DiagramTest(unittest.TestCase): class DiagramTest(unittest.TestCase):
@ -103,7 +111,7 @@ class DiagramTest(unittest.TestCase):
def test_empty_name(self): def test_empty_name(self):
"""Check that providing an empty name don't crash, but save in a diagrams_image.xxx file.""" """Check that providing an empty name don't crash, but save in a diagrams_image.xxx file."""
self.name = 'diagrams_image' self.name = "diagrams_image"
with Diagram(show=False): with Diagram(show=False):
Node("node1") Node("node1")
self.assertTrue(os.path.exists(f"{self.name}.png")) self.assertTrue(os.path.exists(f"{self.name}.png"))
@ -111,12 +119,11 @@ class DiagramTest(unittest.TestCase):
def test_autolabel(self): def test_autolabel(self):
with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False): with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False):
node1 = Node("node1") node1 = Node("node1")
self.assertTrue(node1.label,"Node\nnode1") self.assertTrue(node1.label, "Node\nnode1")
def test_outformat_list(self): def test_outformat_list(self):
"""Check that outformat render all the files from the list.""" """Check that outformat render all the files from the list."""
self.name = 'diagrams_image' self.name = "diagrams_image"
with Diagram(show=False, outformat=["dot", "png"]): with Diagram(show=False, outformat=["dot", "png"]):
Node("node1") Node("node1")
# both files must exist # both files must exist
@ -311,7 +318,6 @@ class ResourcesTest(unittest.TestCase):
i.e. resources/<provider>/<type>/<image>, so check that this depth isn't i.e. resources/<provider>/<type>/<image>, so check that this depth isn't
exceeded. exceeded.
""" """
resources_dir = pathlib.Path(__file__).parent.parent / 'resources' resources_dir = pathlib.Path(__file__).parent.parent / "resources"
max_depth = max(os.path.relpath(d, resources_dir).count(os.sep) + 1 max_depth = max(os.path.relpath(d, resources_dir).count(os.sep) + 1 for d, _, _ in os.walk(resources_dir))
for d, _, _ in os.walk(resources_dir))
self.assertLessEqual(max_depth, 2) self.assertLessEqual(max_depth, 2)

Loading…
Cancel
Save