Skip to content

Commit 46b1f47

Browse files
jens-kuertenJens Kürten
andauthored
switch to ruff and upgrade bandit (#16)
* switch to ruff and upgrade bandit * fix ruff errors --------- Co-authored-by: Jens Kürten <[email protected]>
1 parent 6ba7093 commit 46b1f47

File tree

12 files changed

+100
-39
lines changed

12 files changed

+100
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ venv/
99
dist/
1010
.pytest_cache
1111
site/
12+
.ruff_cache

.pre-commit-config.yaml

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,15 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
exclude: ^.*migrations/versions
44
repos:
5-
- repo: https://github.com/timothycrosley/isort
6-
rev: 5.12.0
5+
- repo: https://github.com/astral-sh/ruff-pre-commit
6+
# Ruff version.
7+
rev: v0.7.0
78
hooks:
8-
- id: isort
9-
exclude: ^.*migrations/versions
10-
args: [
11-
"--line-length=120","--profile=black"
12-
]
13-
- repo: https://github.com/ambv/black
14-
rev: 23.7.0
15-
hooks:
16-
- id: black
17-
18-
19-
- repo: https://github.com/PyCQA/flake8
20-
rev: 6.1.0
21-
hooks:
22-
- id: flake8
23-
args: [ "--max-line-length=120", "--per-file-ignores=*/__init__.py: F401"]
9+
# Run the linter.
10+
- id: ruff
11+
args: [ --fix ]
12+
# Run the formatter.
13+
- id: ruff-format
2414

2515
- repo: https://github.com/pre-commit/pre-commit-hooks
2616
rev: v4.4.0
@@ -39,13 +29,7 @@ repos:
3929
- id: end-of-file-fixer
4030
- id: mixed-line-ending
4131
- id: trailing-whitespace
42-
- repo: https://github.com/pycqa/pylint
43-
rev: v2.15.7
44-
hooks:
45-
- id: pylint
46-
args: ["--output-format", "parseable", "-d", "W0511", "-j", "4"]
47-
4832
- repo: https://github.com/PyCQA/bandit
49-
rev: 1.7.5
33+
rev: 1.7.10
5034
hooks:
5135
- id: bandit

csfunctions/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@
77
from .request import Request
88
from .response import DataResponse, ErrorResponse, Response, WorkloadResponse
99
from .service import Service
10+
11+
__all__ = [
12+
"Event",
13+
"MetaData",
14+
"Request",
15+
"Response",
16+
"DataResponse",
17+
"ErrorResponse",
18+
"WorkloadResponse",
19+
"Service",
20+
]

csfunctions/actions/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88

99
ActionUnion = Union[AbortAndShowErrorAction, DummyAction]
1010
Action = Annotated[ActionUnion, Field(discriminator="name")]
11+
12+
__all__ = [
13+
"Action",
14+
"ActionNames",
15+
"DummyAction",
16+
"AbortAndShowErrorAction",
17+
"ActionUnion",
18+
]

csfunctions/events/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,26 @@
3838
EngineeringChangeReleaseCheckData,
3939
WorkflowTaskTriggerEventData,
4040
]
41+
42+
__all__ = [
43+
"DocumentReleaseEvent",
44+
"DocumentReleaseCheckEvent",
45+
"PartReleaseEvent",
46+
"PartReleaseCheckEvent",
47+
"FieldValueCalculationEvent",
48+
"DummyEvent",
49+
"EngineeringChangeRelease",
50+
"EngineeringChangeReleaseCheck",
51+
"WorkflowTaskTriggerEvent",
52+
"DocumentReleaseData",
53+
"DocumentReleaseCheckData",
54+
"PartReleaseData",
55+
"PartReleaseCheckData",
56+
"FieldValueCalculationData",
57+
"DummyEventData",
58+
"EngineeringChangeReleaseData",
59+
"EngineeringChangeReleaseCheckData",
60+
"WorkflowTaskTriggerEventData",
61+
"DocumentReleaseDialogData",
62+
"PartReleaseDialogData",
63+
]

csfunctions/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(
1313
transaction_id: str,
1414
instance_url: str,
1515
db_service_url: str | None = None,
16-
**kwargs
16+
**kwargs,
1717
):
1818
super().__init__(
1919
app_lang=app_lang,
@@ -23,7 +23,7 @@ def __init__(
2323
request_datetime=request_datetime,
2424
transaction_id=transaction_id,
2525
instance_url=instance_url,
26-
**kwargs
26+
**kwargs,
2727
)
2828

2929
app_lang: str = Field(..., description="ISO code of the session language that triggered the webhook.")

csfunctions/objects/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@
2626
],
2727
Field(discriminator="object_type"),
2828
]
29+
30+
31+
__all__ = [
32+
"Document",
33+
"CADDocument",
34+
"Part",
35+
"File",
36+
"EngineeringChange",
37+
"Material",
38+
"BOMItem",
39+
"ObjectPropertyValue",
40+
"Briefcase",
41+
"Workflow",
42+
"BaseObject",
43+
]

csfunctions/objects/briefcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Briefcase(BaseObject):
3333
def link_objects(self, data: "EventData"):
3434
parts = getattr(data, "parts", None)
3535
documents = getattr(data, "documents", None)
36-
engineering_changes = getattr(data, "engineering_changes")
36+
engineering_changes = getattr(data, "engineering_changes", None)
3737

3838
if parts and self.part_ids:
3939
self._link_parts(parts)

csfunctions/objects/document.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import suppress
12
from datetime import date, datetime
23
from typing import TYPE_CHECKING, Literal, Optional
34

@@ -8,10 +9,8 @@
89
from .base import BaseObject, ObjectType
910
from .file import File
1011

11-
try:
12+
with suppress(ImportError):
1213
from .part import Part
13-
except ImportError:
14-
pass
1514

1615
if TYPE_CHECKING:
1716
from csfunctions.events import EventData
@@ -81,6 +80,8 @@ class Document(BaseObject):
8180
part: Optional["Part"] = Field(None, exclude=True)
8281

8382
def link_objects(self, data: "EventData"):
83+
from .part import Part
84+
8485
if self.teilenummer:
8586
parts = get_items_of_type(data, Part)
8687
self._link_part(parts)

csfunctions/objects/part.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import suppress
12
from datetime import date, datetime
23
from typing import TYPE_CHECKING, Literal, Optional
34

@@ -10,10 +11,8 @@
1011
if TYPE_CHECKING:
1112
from csfunctions.events import EventData
1213

13-
try:
14+
with suppress(ImportError):
1415
from .document import Document
15-
except ImportError:
16-
pass
1716

1817

1918
class Part(BaseObject):
@@ -82,6 +81,8 @@ class Part(BaseObject):
8281
documents: list["Document"] = Field([], exclude=True)
8382

8483
def link_objects(self, data: "EventData"):
84+
from .document import Document
85+
8586
if self.document_ids:
8687
documents = get_items_of_type(data, Document)
8788
self._link_documents(documents)

0 commit comments

Comments
 (0)