diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed784b99..7a73330d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ffe41c4..8c9f2f12 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 \ No newline at end of file diff --git a/diagrams/__init__.py b/diagrams/__init__.py index 6e282d99..2cc854c8 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -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 diff --git a/diagrams/c4/__init__.py b/diagrams/c4/__init__.py index 90ce7a92..f81e2cc6 100644 --- a/diagrams/c4/__init__.py +++ b/diagrams/c4/__init__.py @@ -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): diff --git a/docs/guides/node.md b/docs/guides/node.md index f0f524a7..0392dcad 100644 --- a/docs/guides/node.md +++ b/docs/guides/node.md @@ -7,7 +7,7 @@ Node is a second object representing a node or system component. ## 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. @@ -42,7 +42,7 @@ from diagrams.alibabacloud.storage import ObjectTableStore # gcp resources from diagrams.gcp.compute import AppEngine, GKE -from diagrams.gcp.ml import AutoML +from diagrams.gcp.ml import AutoML ... # 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 `-`. -* **>>**: Connect nodes in left to right direction. +* **>>**: Connect nodes in left to right direction. * **<<**: Connect nodes in right to left direction. * **-**: Connect nodes in no direction. Undirected. @@ -80,7 +80,7 @@ with Diagram("Web Services", show=False): (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) diff --git a/pyproject.toml b/pyproject.toml index d8061521..62c602ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,3 +26,6 @@ pre-commit = "^3.0.4" [tool.black] line-length = 120 + +[tool.isort] +profile = "black" diff --git a/scripts/generate.py b/scripts/generate.py index 299f3941..80b73071 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -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 " @@ -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: diff --git a/scripts/resource.py b/scripts/resource.py index cdea9379..09c5449c 100644 --- a/scripts/resource.py +++ b/scripts/resource.py @@ -11,6 +11,7 @@ import subprocess import sys import config as cfg + from . import resource_dir _usage = "Usage: resource.py " @@ -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"]: diff --git a/tests/test_c4.py b/tests/test_c4.py index 3877ec0f..fd88d6ed 100644 --- a/tests/test_c4.py +++ b/tests/test_c4.py @@ -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): diff --git a/tests/test_diagram.py b/tests/test_diagram.py index 00bdacc6..2b233229 100644 --- a/tests/test_diagram.py +++ b/tests/test_diagram.py @@ -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///, 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) diff --git a/website/sidebars.json b/website/sidebars.json index 6693b599..97086c08 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -31,4 +31,4 @@ "nodes/custom" ] } -} \ No newline at end of file +} diff --git a/website/static/css/custom.css b/website/static/css/custom.css index 235f6269..3d6682ae 100644 --- a/website/static/css/custom.css +++ b/website/static/css/custom.css @@ -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; -} \ No newline at end of file +}