Skip to content

Commit 1c5ee97

Browse files
committed
svc2svc - fix a few typing errors, lint/format
Signed-off-by: Lance Drane <[email protected]>
1 parent 20f1f57 commit 1c5ee97

File tree

15 files changed

+203
-145
lines changed

15 files changed

+203
-145
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
args: [ --fix ]
1515
- id: ruff-format
1616
- repo: https://github.com/pdm-project/pdm
17-
rev: 2.11.2
17+
rev: 2.17.2
1818
hooks:
1919
- id: pdm-export
2020
args: ['--without-hashes']

examples/1_hello_world/hello_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def say_hello_to_name(self, name: str) -> str:
7979
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
8080
"""
8181
capability = HelloServiceCapabilityImplementation()
82-
capability.capability_name = "HelloExample"
82+
capability.capability_name = 'HelloExample'
8383

8484
"""
8585
step three - create service from both the configuration and your own capability

examples/1_hello_world_amqp/hello_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def say_hello_to_name(self, name: str) -> str:
8080
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
8181
"""
8282
capability = HelloServiceCapabilityImplementation()
83-
capability.capability_name = "HelloExample"
83+
capability.capability_name = 'HelloExample'
8484

8585
"""
8686
step three - create service from both the configuration and your own capability

examples/1_hello_world_events/hello_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def say_hello_to_name(self, name: str) -> str:
8383
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
8484
"""
8585
capability = HelloServiceCapabilityImplementation()
86-
capability.capability_name = "HelloExample"
86+
capability.capability_name = 'HelloExample'
8787

8888
"""
8989
step three - create service from both the configuration and your own capability

examples/2_counting/counting_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _run_count(self) -> None:
191191
**from_config_file,
192192
)
193193
capability = CountingServiceCapabilityImplementation()
194-
capability.capability_name = "CountingExample"
194+
capability.capability_name = 'CountingExample'
195195
service = IntersectService([capability], config)
196196
logger.info('Starting counting_service, use Ctrl+C to exit.')
197197
default_intersect_lifecycle_loop(

examples/2_counting_events/counting_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def increment_counter_function(self) -> None:
8383
**from_config_file,
8484
)
8585
capability = CountingServiceCapabilityImplementation()
86-
capability.capability_name = "CountingExample"
86+
capability.capability_name = 'CountingExample'
8787
service = IntersectService([capability], config)
8888
logger.info('Starting counting_service, use Ctrl+C to exit.')
8989

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ isort = { known-first-party = ['src'] }
8484
pydocstyle = { convention = 'google'}
8585
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
8686
mccabe = { max-complexity = 20 }
87-
pylint = { max-args = 10, max-branches = 20, max-returns = 10 }
87+
pylint = { max-args = 10, max-branches = 20, max-returns = 10, max-statements = 75 }
8888
# pyflakes and the relevant pycodestyle rules are already configured
8989
extend-select = [
9090
'C90', # mccabe complexity

src/intersect_sdk/_internal/messages/userspace.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
from services they explicitly messaged.
1010
"""
1111

12+
from __future__ import annotations
13+
1214
import datetime
1315
import uuid
1416
from typing import Any, Union
1517

1618
from pydantic import AwareDatetime, Field, TypeAdapter
1719
from typing_extensions import Annotated, TypedDict
1820

19-
from ...constants import SYSTEM_OF_SYSTEM_REGEX
20-
from ...core_definitions import IntersectDataHandler, IntersectMimeType
21+
from ...constants import SYSTEM_OF_SYSTEM_REGEX # noqa: TCH001 (this is runtime checked)
22+
from ...core_definitions import ( # noqa: TCH001 (this is runtime checked)
23+
IntersectDataHandler,
24+
IntersectMimeType,
25+
)
2126
from ...version import version_string
22-
from ..data_plane.minio_utils import MinioPayload
27+
from ..data_plane.minio_utils import MinioPayload # noqa: TCH001 (this is runtime checked)
2328

2429

2530
class UserspaceMessageHeader(TypedDict):
@@ -115,7 +120,7 @@ class UserspaceMessage(TypedDict):
115120
the headers of the message
116121
"""
117122

118-
payload: Union[bytes, MinioPayload] # noqa: FA100 (Pydantic uses runtime annotations)
123+
payload: Union[bytes, MinioPayload] # noqa: UP007 (Pydantic uses runtime annotations)
119124
"""
120125
main payload of the message. Needs to match the schema format, including the content type.
121126
@@ -141,7 +146,7 @@ def create_userspace_message(
141146
content_type: IntersectMimeType,
142147
data_handler: IntersectDataHandler,
143148
payload: Any,
144-
message_id: uuid.UUID = None,
149+
message_id: uuid.UUID | None = None,
145150
has_error: bool = False,
146151
) -> UserspaceMessage:
147152
"""Payloads depend on the data_handler and has_error."""

src/intersect_sdk/_internal/schema.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
TYPE_CHECKING,
99
Any,
1010
Callable,
11-
List,
1211
Mapping,
1312
NamedTuple,
1413
get_origin,
@@ -339,7 +338,7 @@ def _introspection_baseline(
339338
# parse functions
340339
for class_name, name, method, min_params in response_funcs:
341340
public_name = f'{cap_name}.{name}'
342-
341+
343342
# TODO - I'm placing this here for now because we'll eventually want to capture data plane and broker configs in the schema.
344343
# (It's possible we may want to separate the backing service schema from the application logic, but it's unlikely.)
345344
# At the moment, we're just validating that users can support their response_data_handler property.
@@ -495,7 +494,7 @@ def _introspection_baseline(
495494

496495

497496
def get_schema_and_functions_from_capability_implementations(
498-
capabilities: List[IntersectBaseCapabilityImplementation],
497+
capabilities: list[IntersectBaseCapabilityImplementation],
499498
service_name: HierarchyConfig,
500499
excluded_data_handlers: set[IntersectDataHandler],
501500
) -> tuple[
@@ -510,16 +509,16 @@ def get_schema_and_functions_from_capability_implementations(
510509
511510
In-depth introspection is handled later on.
512511
"""
513-
capability_type_docs : str = ""
514-
status_function_cap : IntersectBaseCapabilityImplementation = None
515-
status_function_name : str = None
516-
status_function_schema : dict[str, Any] = None
517-
status_function_adapter : TypeAdapter[Any] = None
518-
schemas : dict[Any, Any] = dict()
519-
channels : dict[str, dict[str, dict[str, Any]]] = dict() # endpoint schemas
520-
function_map : dict[str, FunctionMetadata] = dict() # endpoint functionality
521-
events : dict[str, Any] = dict() # event schemas
522-
event_map : dict[str, EventMetadata] = dict() # event functionality
512+
capability_type_docs: str = ''
513+
status_function_cap: IntersectBaseCapabilityImplementation | None = None
514+
status_function_name: str | None = None
515+
status_function_schema: dict[str, Any] | None = None
516+
status_function_adapter: TypeAdapter[Any] | None = None
517+
schemas: dict[Any, Any] = {}
518+
channels: dict[str, dict[str, dict[str, Any]]] = {} # endpoint schemas
519+
function_map: dict[str, FunctionMetadata] = {} # endpoint functionality
520+
events: dict[str, Any] = {} # event schemas
521+
event_map: dict[str, EventMetadata] = {} # event functionality
523522
for capability in capabilities:
524523
capability_type: type[IntersectBaseCapabilityImplementation] = type(capability)
525524
if capability_type.__doc__:
@@ -532,7 +531,7 @@ def get_schema_and_functions_from_capability_implementations(
532531
cap_events,
533532
cap_event_map,
534533
) = _introspection_baseline(capability, excluded_data_handlers)
535-
534+
536535
if cap_status_fn_name and cap_status_schema and cap_status_type_adapter:
537536
status_function_cap = capability
538537
status_function_name = cap_status_fn_name
@@ -544,7 +543,6 @@ def get_schema_and_functions_from_capability_implementations(
544543
function_map.update(cap_function_map)
545544
events.update(cap_events)
546545
event_map.update(cap_event_map)
547-
548546

549547
asyncapi_spec = {
550548
'asyncapi': ASYNCAPI_VERSION,
@@ -576,7 +574,7 @@ def get_schema_and_functions_from_capability_implementations(
576574
},
577575
}
578576

579-
if capability_type_docs != "":
577+
if capability_type_docs != '':
580578
asyncapi_spec['info']['description'] = capability_type_docs # type: ignore[index]
581579

582580
if status_function_schema:
@@ -591,4 +589,11 @@ def get_schema_and_functions_from_capability_implementations(
591589
},
592590
"""
593591

594-
return asyncapi_spec, function_map, event_map, status_function_cap, status_function_name, status_function_adapter
592+
return (
593+
asyncapi_spec,
594+
function_map,
595+
event_map,
596+
status_function_cap,
597+
status_function_name,
598+
status_function_adapter,
599+
)

src/intersect_sdk/capability/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def __init__(self) -> None:
2626
2727
NOTE: If you write your own constructor, you MUST call super.__init__() inside of it. The Service will throw an error if you don't.
2828
"""
29-
30-
self._capability_name : str = "InvalidCapability"
29+
self._capability_name: str = 'InvalidCapability'
3130
"""
3231
The advertised name for the capability, as opposed to the implementation class name
3332
"""
@@ -49,14 +48,14 @@ def __init_subclass__(cls) -> None:
4948
):
5049
msg = f"{cls.__name__}: Cannot override functions '_intersect_sdk_register_observer' or 'intersect_sdk_emit_event'"
5150
raise RuntimeError(msg)
52-
51+
5352
@property
5453
def capability_name(self) -> str:
55-
"""The advertised name for the capability provided by this implementation"""
54+
"""The advertised name for the capability provided by this implementation."""
5655
return self._capability_name
57-
56+
5857
@capability_name.setter
59-
def capability_name(self, cname : str) -> str:
58+
def capability_name(self, cname: str) -> None:
6059
self._capability_name = cname
6160

6261
@final

0 commit comments

Comments
 (0)