add pre-commit

pull/1071/head
phuoc.tran 10 months ago
parent 11565902ed
commit 77e56252a4

@ -0,0 +1,5 @@
[settings]
line_length = 79
multi_line_output = 3
include_trailing_comma = True
known_third_party = graphviz,jinja2

@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.3
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3.10

@ -407,4 +407,4 @@ The following import changes:
| Old import path | New import path |
| -------------------------------------------------------------------| --------------------------------------------------------------|
| `from diagrams.oci.connectivity import CustomerPremiseWhite` | `from diagrams.oci.connectivity import CustomerPremisesWhite` |
| `from diagrams.oci.connectivity import CustomerPremises` | `from diagrams.oci.connectivity import CustomerPremises` |
| `from diagrams.oci.connectivity import CustomerPremises` | `from diagrams.oci.connectivity import CustomerPremises` |

@ -75,4 +75,4 @@ To be able to develop and run diagrams locally on you Mac device, you should hav
./autogen.sh
```
7. If the unit tests and the bash script `autogen.sh` is working correctly, then your system is now ready for development.
7. If the unit tests and the bash script `autogen.sh` is working correctly, then your system is now ready for development.

@ -4,7 +4,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):

@ -53,7 +53,7 @@ class Hibernate(_Framework):
class Jhipster(_Framework):
_icon = "jhipster.png"
_icon = "jhipster.png"
class Laravel(_Framework):
@ -62,15 +62,15 @@ class Laravel(_Framework):
class Micronaut(_Framework):
_icon = "micronaut.png"
class Nextjs(_Framework):
_icon = "nextjs.png"
class Phoenix(_Framework):
_icon = "phoenix.png"
class Quarkus(_Framework):
_icon = "quarkus.png"

@ -25,4 +25,4 @@ WORKDIR /usr/src/diagrams
COPY . .
# install python requirements.
RUN pip install black graphviz jinja2
RUN pip install black graphviz jinja2

1061
poetry.lock generated

File diff suppressed because it is too large Load Diff

@ -17,6 +17,7 @@ python = "^3.9"
graphviz = ">=0.13.2,<0.21.0"
jinja2 = ">=2.10,<4.0"
typed-ast = {version="^1.5.5", markers="python_version<'3.8'"}
pre-commit = "^4.0.1"
[tool.poetry.dev-dependencies]
pytest = "^8.2"

@ -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,11 +43,11 @@ 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('.')
tmpl_file = f"{default_tmp[0]}_{pvd}.{default_tmp[1]}"
tmpl = load_tmpl(tmpl_file)
default_tmp = cfg.TMPL_APIDOC.split(".")
tmpl_file = f"{default_tmp[0]}_{pvd}.{default_tmp[1]}"
tmpl = load_tmpl(tmpl_file)
except exceptions.TemplateNotFound:
tmpl = load_tmpl(cfg.TMPL_APIDOC)
tmpl = load_tmpl(cfg.TMPL_APIDOC)
# TODO: remove
def _gen_class_name(path: str) -> str:

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

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

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

Loading…
Cancel
Save