Skip to content

Commit

Permalink
add pre-commit to verify commit before create PR (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvqphuoc01 authored Nov 25, 2024
1 parent fc425ad commit fa48533
Show file tree
Hide file tree
Showing 17 changed files with 833 additions and 520 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
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 = 120
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: v3.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort

- repo: https://github.com/hhatto/autopep8
rev: v2.3.1
hooks:
- id: autopep8
args: [--in-place, --aggressive, --aggressive, --max-line-length=120]
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.
30 changes: 23 additions & 7 deletions diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def __init__(
if isinstance(outformat, list):
for one_format in outformat:
if not self._validate_outformat(one_format):
raise ValueError(f'"{one_format}" is not a valid output format')
raise ValueError(
f'"{one_format}" is not a valid output format')
else:
if not self._validate_outformat(outformat):
raise ValueError(f'"{outformat}" is not a valid output format')
Expand Down Expand Up @@ -478,7 +479,8 @@ def __init__(

if label:
# Graphviz complaining about using label for edges, so replace it with xlabel.
# Update: xlabel option causes the misaligned label position: https://github.com/mingrammer/diagrams/issues/83
# Update: xlabel option causes the misaligned label position:
# https://github.com/mingrammer/diagrams/issues/83
self._attrs["label"] = label
if color:
self._attrs["color"] = color
Expand All @@ -490,7 +492,8 @@ def __sub__(self, other: Union["Node", "Edge", List["Node"]]):
"""Implement Self - Node or Edge and Self - [Nodes]"""
return self.connect(other)

def __rsub__(self, other: Union[List["Node"], List["Edge"]]) -> List["Edge"]:
def __rsub__(self, other: Union[List["Node"],
List["Edge"]]) -> List["Edge"]:
"""Called for [Nodes] or [Edges] - Self because list don't have __sub__ operators."""
return self.append(other)

Expand All @@ -504,15 +507,23 @@ def __lshift__(self, other: Union["Node", "Edge", List["Node"]]):
self.reverse = True
return self.connect(other)

def __rrshift__(self, other: Union[List["Node"], List["Edge"]]) -> List["Edge"]:
def __rrshift__(self,
other: Union[List["Node"],
List["Edge"]]) -> List["Edge"]:
"""Called for [Nodes] or [Edges] >> Self because list of Edges don't have __rshift__ operators."""
return self.append(other, forward=True)

def __rlshift__(self, other: Union[List["Node"], List["Edge"]]) -> List["Edge"]:
def __rlshift__(self,
other: Union[List["Node"],
List["Edge"]]) -> List["Edge"]:
"""Called for [Nodes] or [Edges] << Self because list of Edges don't have __lshift__ operators."""
return self.append(other, reverse=True)

def append(self, other: Union[List["Node"], List["Edge"]], forward=None, reverse=None) -> List["Edge"]:
def append(self,
other: Union[List["Node"],
List["Edge"]],
forward=None,
reverse=None) -> List["Edge"]:
result = []
for o in other:
if isinstance(o, Edge):
Expand All @@ -521,7 +532,12 @@ def append(self, other: Union[List["Node"], List["Edge"]], forward=None, reverse
self._attrs = o.attrs.copy()
result.append(o)
else:
result.append(Edge(o, forward=forward, reverse=reverse, **self._attrs))
result.append(
Edge(
o,
forward=forward,
reverse=reverse,
**self._attrs))
return result

def connect(self, other: Union["Node", "Edge", List["Node"]]):
Expand Down
6 changes: 4 additions & 2 deletions 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 All @@ -26,7 +27,8 @@ def _format_description(description):
"""
wrapper = textwrap.TextWrapper(width=40, max_lines=3)
lines = [html.escape(line) for line in wrapper.wrap(description)]
lines += [""] * (3 - len(lines)) # fill up with empty lines so it is always three
# fill up with empty lines so it is always three
lines += [""] * (3 - len(lines))
return "<br/>".join(lines)


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
Loading

0 comments on commit fa48533

Please sign in to comment.