Skip to content

Commit 9660735

Browse files
Add ruff auto fix (#657)
* Add ruff Signed-off-by: Bernd Verst <[email protected]> * Autoformat all files using ruff Signed-off-by: Bernd Verst <[email protected]> * Run ruff check on CI Signed-off-by: Bernd Verst <[email protected]> * fix up type checker exemption Signed-off-by: Bernd Verst <[email protected]> --------- Signed-off-by: Bernd Verst <[email protected]> Co-authored-by: Bernd Verst <[email protected]>
1 parent 593eb07 commit 9660735

File tree

146 files changed

+4725
-3956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+4725
-3956
lines changed

.github/workflows/build.yaml

+28-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,35 @@ on:
2020
merge_group:
2121

2222
jobs:
23+
lint:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Set up Python 3.9
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: 3.9
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install setuptools wheel tox
35+
- name: Run Autoformatter
36+
run: |
37+
tox -e ruff
38+
statusResult=$(git status -u --porcelain)
39+
if [ -z $statusResult ]
40+
then
41+
exit 0
42+
else
43+
echo "Source files are not formatted correctly. Run 'tox -e ruff' to autoformat."
44+
exit 1
45+
fi
46+
- name: Run Linter
47+
run: |
48+
tox -e flake8
49+
2350
build:
51+
needs: lint
2452
runs-on: ubuntu-latest
2553
strategy:
2654
fail-fast: false
@@ -36,9 +64,6 @@ jobs:
3664
run: |
3765
python -m pip install --upgrade pip
3866
pip install setuptools wheel tox
39-
- name: Run Linter
40-
run: |
41-
tox -e flake8
4267
- name: Check Typing
4368
run: |
4469
tox -e type

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,25 @@ pip3 install -r dev-requirements.txt
9696
tox -e flake8
9797
```
9898

99-
5. Run unit-test
99+
5. Run autofix
100+
101+
```bash
102+
tox -e ruff
103+
```
104+
105+
6. Run unit-test
100106

101107
```bash
102108
tox -e py311
103109
```
104110

105-
6. Run type check
111+
7. Run type check
106112

107113
```bash
108114
tox -e type
109115
```
110116

111-
7. Run examples
117+
8. Run examples
112118

113119
```bash
114120
tox -e examples

dapr/actor/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323

2424
__all__ = [
25-
'ActorInterface',
26-
'ActorProxy',
27-
'ActorProxyFactory',
28-
'ActorId',
29-
'Actor',
30-
'ActorRuntime',
31-
'Remindable',
32-
'actormethod',
25+
"ActorInterface",
26+
"ActorProxy",
27+
"ActorProxyFactory",
28+
"ActorId",
29+
"Actor",
30+
"ActorRuntime",
31+
"Remindable",
32+
"actormethod",
3333
]

dapr/actor/actor_interface.py

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async def do_actor_method1(self, param):
3333
async def do_actor_method2(self, param):
3434
...
3535
"""
36+
3637
...
3738

3839

@@ -51,8 +52,10 @@ async def do_actor_call(self, param):
5152
Args:
5253
name (str, optional): the name of actor method.
5354
"""
55+
5456
def wrapper(funcobj):
5557
funcobj.__actormethod__ = name
5658
funcobj.__isabstractmethod__ = True
5759
return funcobj
60+
5861
return wrapper

dapr/actor/client/proxy.py

+42-29
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
from dapr.conf import settings
2525

2626
# Actor factory Callable type hint.
27-
ACTOR_FACTORY_CALLBACK = Callable[[ActorInterface, str, str], 'ActorProxy']
27+
ACTOR_FACTORY_CALLBACK = Callable[[ActorInterface, str, str], "ActorProxy"]
2828

2929

3030
class ActorFactoryBase(ABC):
3131
@abstractmethod
3232
def create(
33-
self, actor_type: str, actor_id: ActorId,
34-
actor_interface: Optional[Type[ActorInterface]] = None) -> 'ActorProxy':
33+
self,
34+
actor_type: str,
35+
actor_id: ActorId,
36+
actor_interface: Optional[Type[ActorInterface]] = None,
37+
) -> "ActorProxy":
3538
...
3639

3740

@@ -44,32 +47,36 @@ class ActorProxyFactory(ActorFactoryBase):
4447
"""
4548

4649
def __init__(
47-
self,
48-
message_serializer=DefaultJSONSerializer(),
49-
http_timeout_seconds: int = settings.DAPR_HTTP_TIMEOUT_SECONDS):
50+
self,
51+
message_serializer=DefaultJSONSerializer(),
52+
http_timeout_seconds: int = settings.DAPR_HTTP_TIMEOUT_SECONDS,
53+
):
5054
# TODO: support serializer for state store later
5155
self._dapr_client = DaprActorHttpClient(message_serializer, timeout=http_timeout_seconds)
5256
self._message_serializer = message_serializer
5357

5458
def create(
55-
self, actor_type: str, actor_id: ActorId,
56-
actor_interface: Optional[Type[ActorInterface]] = None) -> 'ActorProxy':
59+
self,
60+
actor_type: str,
61+
actor_id: ActorId,
62+
actor_interface: Optional[Type[ActorInterface]] = None,
63+
) -> "ActorProxy":
5764
return ActorProxy(
58-
self._dapr_client, actor_type, actor_id,
59-
actor_interface, self._message_serializer)
65+
self._dapr_client, actor_type, actor_id, actor_interface, self._message_serializer
66+
)
6067

6168

6269
class CallableProxy:
6370
def __init__(
64-
self, proxy: 'ActorProxy', attr_call_type: Dict[str, Any],
65-
message_serializer: Serializer):
71+
self, proxy: "ActorProxy", attr_call_type: Dict[str, Any], message_serializer: Serializer
72+
):
6673
self._proxy = proxy
6774
self._attr_call_type = attr_call_type
6875
self._message_serializer = message_serializer
6976

7077
async def __call__(self, *args, **kwargs) -> Any:
7178
if len(args) > 1:
72-
raise ValueError('does not support multiple arguments')
79+
raise ValueError("does not support multiple arguments")
7380

7481
bytes_data = None
7582
if len(args) > 0:
@@ -78,9 +85,9 @@ async def __call__(self, *args, **kwargs) -> Any:
7885
else:
7986
bytes_data = self._message_serializer.serialize(args[0])
8087

81-
rtnval = await self._proxy.invoke_method(self._attr_call_type['actor_method'], bytes_data)
88+
rtnval = await self._proxy.invoke_method(self._attr_call_type["actor_method"], bytes_data)
8289

83-
return self._message_serializer.deserialize(rtnval, self._attr_call_type['return_types'])
90+
return self._message_serializer.deserialize(rtnval, self._attr_call_type["return_types"])
8491

8592

8693
class ActorProxy:
@@ -94,11 +101,13 @@ class ActorProxy:
94101
_default_proxy_factory = ActorProxyFactory()
95102

96103
def __init__(
97-
self, client: DaprActorClientBase,
98-
actor_type: str,
99-
actor_id: ActorId,
100-
actor_interface: Optional[Type[ActorInterface]],
101-
message_serializer: Serializer):
104+
self,
105+
client: DaprActorClientBase,
106+
actor_type: str,
107+
actor_id: ActorId,
108+
actor_interface: Optional[Type[ActorInterface]],
109+
message_serializer: Serializer,
110+
):
102111
self._dapr_client = client
103112
self._actor_id = actor_id
104113
self._actor_type = actor_type
@@ -120,10 +129,12 @@ def actor_type(self) -> str:
120129

121130
@classmethod
122131
def create(
123-
cls,
124-
actor_type: str, actor_id: ActorId,
125-
actor_interface: Optional[Type[ActorInterface]] = None,
126-
actor_proxy_factory: Optional[ActorFactoryBase] = None) -> 'ActorProxy':
132+
cls,
133+
actor_type: str,
134+
actor_id: ActorId,
135+
actor_interface: Optional[Type[ActorInterface]] = None,
136+
actor_proxy_factory: Optional[ActorFactoryBase] = None,
137+
) -> "ActorProxy":
127138
"""Creates ActorProxy client to call actor.
128139
129140
Args:
@@ -157,10 +168,11 @@ async def invoke_method(self, method: str, raw_body: Optional[bytes] = None) ->
157168
"""
158169

159170
if raw_body is not None and not isinstance(raw_body, bytes):
160-
raise ValueError(f'raw_body {type(raw_body)} is not bytes type')
171+
raise ValueError(f"raw_body {type(raw_body)} is not bytes type")
161172

162173
return await self._dapr_client.invoke_method(
163-
self._actor_type, str(self._actor_id), method, raw_body)
174+
self._actor_type, str(self._actor_id), method, raw_body
175+
)
164176

165177
def __getattr__(self, name: str) -> CallableProxy:
166178
"""Enables RPC style actor method invocation.
@@ -177,17 +189,18 @@ def __getattr__(self, name: str) -> CallableProxy:
177189
AttributeError: method is not defined in Actor interface.
178190
"""
179191
if not self._actor_interface:
180-
raise ValueError('actor_interface is not set. use invoke method.')
192+
raise ValueError("actor_interface is not set. use invoke method.")
181193

182194
if name not in self._dispatchable_attr:
183195
get_dispatchable_attrs_from_interface(self._actor_interface, self._dispatchable_attr)
184196

185197
attr_call_type = self._dispatchable_attr.get(name)
186198
if attr_call_type is None:
187-
raise AttributeError(f'{self._actor_interface.__class__} has no attribute {name}')
199+
raise AttributeError(f"{self._actor_interface.__class__} has no attribute {name}")
188200

189201
if name not in self._callable_proxies:
190202
self._callable_proxies[name] = CallableProxy(
191-
self, attr_call_type, self._message_serializer)
203+
self, attr_call_type, self._message_serializer
204+
)
192205

193206
return self._callable_proxies[name]

dapr/actor/runtime/_call_type.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ActorCallType(Enum):
2121
:class:`ActorMethodContext` includes :class:`ActorCallType` passing to
2222
:meth:`Actor._on_pre_actor_method` and :meth:`Actor._on_post_actor_method`
2323
"""
24+
2425
# Specifies that the method invoked is an actor interface method for a given client request.
2526
actor_interface_method = 0
2627
# Specifies that the method invoked is a timer callback method.

dapr/actor/runtime/_reminder_data.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ class ActorReminderData:
3232
"""
3333

3434
def __init__(
35-
self, reminder_name: str, state: Optional[bytes],
36-
due_time: timedelta, period: timedelta, ttl: Optional[timedelta] = None):
35+
self,
36+
reminder_name: str,
37+
state: Optional[bytes],
38+
due_time: timedelta,
39+
period: timedelta,
40+
ttl: Optional[timedelta] = None,
41+
):
3742
"""Creates new :class:`ActorReminderData` instance.
3843
3944
Args:
@@ -52,7 +57,7 @@ def __init__(
5257
self._ttl = ttl
5358

5459
if not isinstance(state, bytes):
55-
raise ValueError(f'only bytes are allowed for state: {type(state)}')
60+
raise ValueError(f"only bytes are allowed for state: {type(state)}")
5661

5762
self._state = state
5863

@@ -87,26 +92,27 @@ def as_dict(self) -> Dict[str, Any]:
8792
if self._state is not None:
8893
encoded_state = base64.b64encode(self._state)
8994
reminderDict: Dict[str, Any] = {
90-
'reminderName': self._reminder_name,
91-
'dueTime': self._due_time,
92-
'period': self._period,
93-
'data': encoded_state.decode("utf-8")
95+
"reminderName": self._reminder_name,
96+
"dueTime": self._due_time,
97+
"period": self._period,
98+
"data": encoded_state.decode("utf-8"),
9499
}
95100

96101
if self._ttl is not None:
97-
reminderDict.update({'ttl': self._ttl})
102+
reminderDict.update({"ttl": self._ttl})
98103

99104
return reminderDict
100105

101106
@classmethod
102-
def from_dict(cls, reminder_name: str, obj: Dict[str, Any]) -> 'ActorReminderData':
107+
def from_dict(cls, reminder_name: str, obj: Dict[str, Any]) -> "ActorReminderData":
103108
"""Creates :class:`ActorReminderData` object from dict object."""
104-
b64encoded_state = obj.get('data')
109+
b64encoded_state = obj.get("data")
105110
state_bytes = None
106111
if b64encoded_state is not None and len(b64encoded_state) > 0:
107112
state_bytes = base64.b64decode(b64encoded_state)
108-
if 'ttl' in obj:
109-
return ActorReminderData(reminder_name, state_bytes, obj['dueTime'], obj['period'],
110-
obj['ttl'])
113+
if "ttl" in obj:
114+
return ActorReminderData(
115+
reminder_name, state_bytes, obj["dueTime"], obj["period"], obj["ttl"]
116+
)
111117
else:
112-
return ActorReminderData(reminder_name, state_bytes, obj['dueTime'], obj['period'])
118+
return ActorReminderData(reminder_name, state_bytes, obj["dueTime"], obj["period"])

0 commit comments

Comments
 (0)