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):

@ -7,7 +7,7 @@ Node is a second object representing a node or system component.
## Basic ## Basic
Node is an abstract concept that represents a single system component object. Node is an abstract concept that represents a single system component object.
A node object consists of three parts: **provider**, **resource type** and **name**. You may already have seen each part in the previous example. A node object consists of three parts: **provider**, **resource type** and **name**. You may already have seen each part in the previous example.
@ -42,7 +42,7 @@ from diagrams.alibabacloud.storage import ObjectTableStore
# gcp resources # gcp resources
from diagrams.gcp.compute import AppEngine, GKE from diagrams.gcp.compute import AppEngine, GKE
from diagrams.gcp.ml import AutoML from diagrams.gcp.ml import AutoML
... ...
# k8s resources # k8s resources
@ -63,7 +63,7 @@ You can find all available nodes list in [Here](https://diagrams.mingrammer.com/
You can represent data flow by connecting the nodes with these operators: `>>`, `<<` and `-`. You can represent data flow by connecting the nodes with these operators: `>>`, `<<` and `-`.
* **>>**: Connect nodes in left to right direction. * **>>**: Connect nodes in left to right direction.
* **<<**: Connect nodes in right to left direction. * **<<**: Connect nodes in right to left direction.
* **-**: Connect nodes in no direction. Undirected. * **-**: Connect nodes in no direction. Undirected.
@ -80,7 +80,7 @@ with Diagram("Web Services", show=False):
(ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb") (ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb")
``` ```
> Be careful when using the `-` and any shift operators together, which could cause unexpected results due to operator precedence. > Be careful when using the `-` and any shift operators together, which could cause unexpected results due to operator precedence.
![web services diagram](/img/web_services_diagram.png) ![web services diagram](/img/web_services_diagram.png)

@ -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,20 +111,19 @@ 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"))
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)

@ -31,4 +31,4 @@
"nodes/custom" "nodes/custom"
] ]
} }
} }

@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
/* your custom css */ /* your custom css */
@media only screen and (min-device-width: 360px) and (max-device-width: 736px) { @media only screen and (min-device-width: 360px) and (max-device-width: 736px) {
@ -24,4 +24,4 @@
#buymeacoffee { #buymeacoffee {
height: 50px; height: 50px;
} }

Loading…
Cancel
Save