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: |
poetry install
poetry run python -m unittest -v tests/*.py
- name: Run static checks
run: pre-commit run --all-files

@ -1,9 +1,9 @@
repos:
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# name: Run isort to sort imports in Python files
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: Run isort to sort imports in Python files
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
@ -15,26 +15,8 @@ repos:
- id: trailing-whitespace
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
rev: 23.1.0
hooks:
- id: black
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 uuid
from pathlib import Path
from typing import List, Union, Dict
from typing import Dict, List, Union
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 textwrap
from diagrams import Cluster, Node, Edge
from diagrams import Cluster, Edge, Node
def _format_node_label(name, key, description):

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

@ -5,7 +5,8 @@ from typing import Iterable
from jinja2 import Environment, FileSystemLoader, Template, exceptions
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>"
@ -42,7 +43,7 @@ def gen_classes(pvd: str, typ: str, paths: Iterable[str]) -> str:
def gen_apidoc(pvd: str, typ_paths: dict) -> str:
try:
default_tmp = cfg.TMPL_APIDOC.split('.')
default_tmp = cfg.TMPL_APIDOC.split(".")
tmpl_file = f"{default_tmp[0]}_{pvd}.{default_tmp[1]}"
tmpl = load_tmpl(tmpl_file)
except exceptions.TemplateNotFound:

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

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

@ -1,10 +1,18 @@
import os
import pathlib
import shutil
import unittest
import pathlib
from diagrams import Cluster, Diagram, Edge, Node
from diagrams import getcluster, getdiagram, setcluster, setdiagram
from diagrams import (
Cluster,
Diagram,
Edge,
Node,
getcluster,
getdiagram,
setcluster,
setdiagram,
)
class DiagramTest(unittest.TestCase):
@ -103,7 +111,7 @@ class DiagramTest(unittest.TestCase):
def test_empty_name(self):
"""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):
Node("node1")
self.assertTrue(os.path.exists(f"{self.name}.png"))
@ -111,12 +119,11 @@ class DiagramTest(unittest.TestCase):
def test_autolabel(self):
with Diagram(name=os.path.join(self.name, "nodes_to_node"), show=False):
node1 = Node("node1")
self.assertTrue(node1.label,"Node\nnode1")
self.assertTrue(node1.label, "Node\nnode1")
def test_outformat_list(self):
"""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"]):
Node("node1")
# 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
exceeded.
"""
resources_dir = pathlib.Path(__file__).parent.parent / 'resources'
max_depth = max(os.path.relpath(d, resources_dir).count(os.sep) + 1
for d, _, _ in os.walk(resources_dir))
resources_dir = pathlib.Path(__file__).parent.parent / "resources"
max_depth = max(os.path.relpath(d, resources_dir).count(os.sep) + 1 for d, _, _ in os.walk(resources_dir))
self.assertLessEqual(max_depth, 2)

Loading…
Cancel
Save