Skip to content

Commit ef4e505

Browse files
committed
Refactor import statements for consistency and clarity across multiple modules
1 parent 88d39a5 commit ef4e505

21 files changed

+83
-69
lines changed

src/iop/_async_request.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
2-
from . import _iris
32
from typing import Any, Optional, Union
4-
from iop._dispatch import dispatch_deserializer, dispatch_serializer
5-
from iop._message import _Message as Message
3+
4+
from . import _iris
5+
from ._dispatch import dispatch_deserializer, dispatch_serializer
6+
from ._message import _Message as Message
67

78
class AsyncRequest(asyncio.Future):
89
_message_header_id: int = 0
@@ -19,6 +20,8 @@ def __init__(self, target: str, request: Union[Message, Any],
1920
self.timeout = timeout
2021
self.description = description
2122
self.host = host
23+
if host is None:
24+
raise ValueError("host parameter cannot be None")
2225
self._iris_handle = host.iris_handle
2326
asyncio.create_task(self.send())
2427

src/iop/_business_host.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
from typing import Any,List, Optional, Tuple, Union
33

44
from . import _iris
5-
6-
from iop._common import _Common
7-
from iop._message import _Message as Message
8-
from iop._decorators import input_serializer_param, output_deserializer
9-
from iop._dispatch import dispatch_serializer, dispatch_deserializer
10-
from iop._async_request import AsyncRequest
5+
from ._common import _Common
6+
from ._message import _Message as Message
7+
from ._decorators import input_serializer_param, output_deserializer
8+
from ._dispatch import dispatch_serializer, dispatch_deserializer
9+
from ._async_request import AsyncRequest
1110

1211
class _BusinessHost(_Common):
1312
"""Base class for business components that defines common methods.

src/iop/_business_operation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import importlib
22
from typing import Any, List, Optional, Union, Tuple
3-
from iop._business_host import _BusinessHost
4-
from iop._decorators import input_deserializer, output_serializer, input_serializer, output_deserializer
5-
from iop._dispatch import create_dispatch, dispach_message
3+
4+
from ._business_host import _BusinessHost
5+
from ._decorators import input_deserializer, output_serializer, input_serializer, output_deserializer
6+
from ._dispatch import create_dispatch, dispach_message
67

78
class _BusinessOperation(_BusinessHost):
89
"""Business operation component that handles outbound communication.

src/iop/_business_process.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any, List, Optional, Union
2-
from iop._business_host import _BusinessHost
3-
from iop._decorators import input_deserializer, input_serializer_param, output_serializer, input_serializer, output_deserializer
4-
from iop._dispatch import create_dispatch, dispach_message
2+
3+
from ._business_host import _BusinessHost
4+
from ._decorators import input_deserializer, input_serializer_param, output_serializer, input_serializer, output_deserializer
5+
from ._dispatch import create_dispatch, dispach_message
56

67
class _BusinessProcess(_BusinessHost):
78
"""Business process component that contains routing and transformation logic.
@@ -72,23 +73,23 @@ def reply(self, response: Any) -> None:
7273
return self.iris_handle.dispatchReply(response)
7374

7475
@input_serializer_param(1,'request')
75-
def send_request_async(self, target: str, request: Any, response_required: bool=True, completion_key: Optional[str]=None, description: Optional[str]=None) -> None:
76+
def send_request_async(self, target: str, request: Any, description: Optional[str]=None, completion_key: Optional[str]=None, response_required: bool=True) -> None:
7677
"""Send the specified message to the target business process or business operation asynchronously.
7778
7879
Args:
7980
target: The name of the business process or operation to receive the request
8081
request: The message to send to the target
81-
response_required: Whether a response is required
82-
completion_key: A string that will be returned with the response if the maximum time is exceeded
8382
description: An optional description property in the message header
83+
completion_key: A string that will be returned with the response if the maximum time is exceeded
84+
response_required: Whether a response is required
8485
8586
Raises:
8687
TypeError: If request is not of type Message or IRISObject
8788
"""
8889
if response_required:
89-
response_required = 1
90+
response_required = True
9091
else:
91-
response_required = 0
92+
response_required = False
9293
return self.iris_handle.dispatchSendRequestAsync(target, request, response_required, completion_key, description)
9394

9495
def set_timer(self, timeout: Union[int, str], completion_key: Optional[str]=None) -> None:

src/iop/_business_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import importlib
2-
from iop._business_host import _BusinessHost
3-
from iop._decorators import input_deserializer, output_serializer, input_serializer, output_deserializer
2+
3+
from ._business_host import _BusinessHost
4+
from ._decorators import input_deserializer, output_serializer, input_serializer, output_deserializer
45

56
class _BusinessService(_BusinessHost):
67
""" This class is responsible for receiving the data from external system and sending it to business processes or business operations in the production.

src/iop/_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import sys
88
from typing import Optional, Callable
99
from importlib.metadata import version
10-
from iop._director import _Director
11-
from iop._utils import _Utils
10+
11+
from ._director import _Director
12+
from ._utils import _Utils
1213

1314

1415
class CommandType(Enum):

src/iop/_common.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import abc
22
import inspect
33
import traceback
4-
54
from typing import Any, ClassVar, List, Optional, Tuple
65

76
from . import _iris
8-
9-
from iop._log_manager import LogManager, logging
10-
11-
from iop._debugpy import debugpython
7+
from ._log_manager import LogManager, logging
8+
from ._debugpy import debugpython
129

1310
class _Common(metaclass=abc.ABCMeta):
1411
"""Base class that defines common methods for all component types.
@@ -21,7 +18,12 @@ class _Common(metaclass=abc.ABCMeta):
2118
ICON_URL: ClassVar[str]
2219
iris_handle: Any = None
2320
_log_to_console: bool = False
24-
_logger: logging.Logger = None
21+
_logger: Optional[logging.Logger] = None
22+
23+
@staticmethod
24+
def get_adapter_type() -> Optional[str]:
25+
"""Get the adapter type for this component. Override in subclasses."""
26+
return None
2527

2628
@property
2729
def logger(self) -> logging.Logger:
@@ -104,7 +106,7 @@ def _get_info(cls) -> List[str]:
104106
super_class = classname[1:-1]
105107
adapter = cls.get_adapter_type()
106108
if adapter is None:
107-
adapter = cls.getAdapterType()
109+
adapter = cls.getAdapterType() # For backwards compatibility
108110
break
109111
elif classname in ["'iop.BusinessProcess'","'iop.DuplexProcess'","'iop.InboundAdapter'","'iop.OutboundAdapter'",
110112
"'grongier.pex.BusinessProcess'","'grongier.pex.DuplexProcess'","'grongier.pex.InboundAdapter'","'grongier.pex.OutboundAdapter'"] :
@@ -113,7 +115,7 @@ def _get_info(cls) -> List[str]:
113115
break
114116

115117
if ""==super_class:
116-
return ""
118+
return []
117119
ret.append(super_class)
118120

119121
# Get the class documentation, if any

src/iop/_debugpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def wait_for_debugpy_connected(timeout: float = 30, port: int = 0) -> bool:
8383

8484
def timeout_handler():
8585
time.sleep(timeout)
86-
debugpy.wait_for_client.cancel()
86+
debugpy.wait_for_client.cancel() # type: ignore
8787

8888
threading.Thread(target=timeout_handler, daemon=True).start()
8989

src/iop/_decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import wraps
22
from typing import Any, Callable
3-
from iop._dispatch import dispatch_deserializer, dispatch_serializer
3+
4+
from ._dispatch import dispatch_deserializer, dispatch_serializer
45

56
def input_serializer(fonction: Callable) -> Callable:
67
"""Decorator that serializes all input arguments."""

src/iop/_director.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import asyncio
22
import datetime
33
import functools
4-
from . import _iris
54
import signal
65
from dataclasses import dataclass
76

8-
from iop._dispatch import dispatch_deserializer, dispatch_serializer
9-
from iop._utils import _Utils
7+
from . import _iris
8+
from ._dispatch import dispatch_deserializer, dispatch_serializer
9+
from ._utils import _Utils
10+
11+
@dataclass
12+
class SigintHandler():
13+
14+
sigint: bool = False
15+
sigint_log: bool = False
16+
log_only: bool = False
17+
18+
def signal_handler(self, signal, frame):
19+
if self.sigint or self.log_only:
20+
self.sigint_log = True
21+
self.sigint = True
1022

1123
class _Director():
1224
""" The Directorclass is used for nonpolling business services, that is, business services which are not automatically
@@ -89,7 +101,7 @@ def start_production_with_log(production_name=None):
89101
loop.close()
90102

91103
@staticmethod
92-
async def _start_production_async(production_name=None, handler=None):
104+
async def _start_production_async(production_name:str, handler: SigintHandler):
93105
_Director.start_production(production_name)
94106
while True:
95107
if handler.sigint:
@@ -286,15 +298,3 @@ def test_component(target,message=None,classname=None,body=None):
286298
deserialized_response = f'{response.classname} : {_Utils.stream_to_string(response.jstr)}'
287299
return deserialized_response
288300

289-
290-
@dataclass
291-
class SigintHandler():
292-
293-
sigint: bool = False
294-
sigint_log: bool = False
295-
log_only: bool = False
296-
297-
def signal_handler(self, signal, frame):
298-
if self.sigint or self.log_only:
299-
self.sigint_log = True
300-
self.sigint = True

0 commit comments

Comments
 (0)