Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pre-commit to verify commit before create PR #1066

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
line_length = 79
multi_line_output = 3
include_trailing_comma = True
known_third_party = graphviz,jinja2
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion diagrams/c4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import html
import textwrap
from diagrams import Cluster, Node, Edge

from diagrams import Cluster, Edge, Node


def _format_node_label(name, key, description):
Expand Down
8 changes: 4 additions & 4 deletions diagrams/programming/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Hibernate(_Framework):


class Jhipster(_Framework):
_icon = "jhipster.png"
_icon = "jhipster.png"


class Laravel(_Framework):
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ WORKDIR /usr/src/diagrams
COPY . .

# install python requirements.
RUN pip install black graphviz jinja2
RUN pip install black graphviz jinja2
1,061 changes: 612 additions & 449 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
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>"

Expand Down Expand Up @@ -42,11 +43,11 @@ def _gen_class_meta(path: str) -> dict:

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:
Expand Down
2 changes: 2 additions & 0 deletions scripts/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys

import config as cfg

from . import resource_dir

_usage = "Usage: resource.py <cmd> <pvd>"
Expand Down Expand Up @@ -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"]:
Expand Down
12 changes: 9 additions & 3 deletions tests/test_c4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
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):
Expand Down
28 changes: 17 additions & 11 deletions tests/test_diagram.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -103,20 +111,19 @@ def test_custom_filename(self):

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
Expand Down Expand Up @@ -311,7 +318,6 @@ def test_folder_depth(self):
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)
2 changes: 1 addition & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"nodes/custom"
]
}
}
}
4 changes: 2 additions & 2 deletions website/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,4 +24,4 @@

#buymeacoffee {
height: 50px;
}
}
Loading