fjagepy 2.1.2__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {fjagepy-2.1.2 → fjagepy-2.2.0}/PKG-INFO +4 -4
  2. {fjagepy-2.1.2 → fjagepy-2.2.0}/README.md +3 -3
  3. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/AgentID.py +1 -1
  4. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Gateway.py +27 -9
  5. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/JSONMessage.py +6 -0
  6. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy.egg-info/PKG-INFO +4 -4
  7. {fjagepy-2.1.2 → fjagepy-2.2.0}/pyproject.toml +1 -1
  8. {fjagepy-2.1.2 → fjagepy-2.2.0}/test/test_gateway.py +19 -3
  9. {fjagepy-2.1.2 → fjagepy-2.2.0}/LICENSE +0 -0
  10. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Connector.py +0 -0
  11. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Message.py +0 -0
  12. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Performative.py +0 -0
  13. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Services.py +0 -0
  14. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/TCPConnector.py +0 -0
  15. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/Utils.py +0 -0
  16. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/__init__.py +0 -0
  17. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy/py.typed +0 -0
  18. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy.egg-info/SOURCES.txt +0 -0
  19. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy.egg-info/dependency_links.txt +0 -0
  20. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy.egg-info/requires.txt +0 -0
  21. {fjagepy-2.1.2 → fjagepy-2.2.0}/fjagepy.egg-info/top_level.txt +0 -0
  22. {fjagepy-2.1.2 → fjagepy-2.2.0}/setup.cfg +0 -0
  23. {fjagepy-2.1.2 → fjagepy-2.2.0}/test/test_agentid.py +0 -0
  24. {fjagepy-2.1.2 → fjagepy-2.2.0}/test/test_jsonmessage.py +0 -0
  25. {fjagepy-2.1.2 → fjagepy-2.2.0}/test/test_message.py +0 -0
  26. {fjagepy-2.1.2 → fjagepy-2.2.0}/test/test_shellreqs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fjagepy
3
- Version: 2.1.2
3
+ Version: 2.2.0
4
4
  Summary: fjage Gateway in Python
5
5
  Author-email: Chinmay Pendharkar <chinmay@subnero.com>
6
6
  License: BSD-3-Clause
@@ -277,9 +277,9 @@ To build the documentation locally:
277
277
  # Install documentation dependencies
278
278
  pip install -e ".[docs]"
279
279
  # Build docs
280
- sphinx-build -b html docs/ ../../docs/pydocs/
280
+ sphinx-build -b html docs/ ../../build/docs/pydocs/
281
281
  # View in browser
282
- open ../../docs/pydocs/index.html
282
+ open ../../build/docs/pydocs/index.html
283
283
  ```
284
284
 
285
285
  ## Compatibility
@@ -306,7 +306,7 @@ This project is licensed under the BSD 3-Clause License. See the [LICENSE](../..
306
306
 
307
307
  ## Support
308
308
 
309
- - **Documentation**: [fjåge Documentation](https://fjage.readthedocs.io/)
309
+ - **Documentation**: [fjåge Documentation](https://org-arl.github.io/fjage/)
310
310
  - **Issues**: [GitHub Issues](https://github.com/org-arl/fjage/issues)
311
311
  - **Discussions**: [GitHub Discussions](https://github.com/org-arl/fjage/discussions)
312
312
 
@@ -254,9 +254,9 @@ To build the documentation locally:
254
254
  # Install documentation dependencies
255
255
  pip install -e ".[docs]"
256
256
  # Build docs
257
- sphinx-build -b html docs/ ../../docs/pydocs/
257
+ sphinx-build -b html docs/ ../../build/docs/pydocs/
258
258
  # View in browser
259
- open ../../docs/pydocs/index.html
259
+ open ../../build/docs/pydocs/index.html
260
260
  ```
261
261
 
262
262
  ## Compatibility
@@ -283,7 +283,7 @@ This project is licensed under the BSD 3-Clause License. See the [LICENSE](../..
283
283
 
284
284
  ## Support
285
285
 
286
- - **Documentation**: [fjåge Documentation](https://fjage.readthedocs.io/)
286
+ - **Documentation**: [fjåge Documentation](https://org-arl.github.io/fjage/)
287
287
  - **Issues**: [GitHub Issues](https://github.com/org-arl/fjage/issues)
288
288
  - **Discussions**: [GitHub Discussions](https://github.com/org-arl/fjage/discussions)
289
289
 
@@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
11
11
  logger.addHandler(logging.NullHandler())
12
12
 
13
13
  # Default timeout for non-owned AgentIDs (in milliseconds)
14
- DEFAULT_TIMEOUT = 10000
14
+ DEFAULT_TIMEOUT = 1000
15
15
 
16
16
  # - Accessing unknown attributes performs a remote parameter GET; returns `None` if not found.
17
17
  # - Assigning unknown attributes performs a remote parameter SET.
@@ -17,6 +17,8 @@ from .Message import Message
17
17
  from .Utils import UUID7
18
18
 
19
19
  DEFAULT_MAX_QUEUE_SIZE = 512
20
+ DEFAULT_REQUEST_TIMEOUT = 1000
21
+ DEFAULT_DIRECTORY_TIMEOUT = 6000
20
22
 
21
23
  logger = logging.getLogger(__name__)
22
24
  logger.addHandler(logging.NullHandler())
@@ -41,7 +43,7 @@ class Gateway:
41
43
  NON_BLOCKING = 0
42
44
  BLOCKING = -1
43
45
 
44
- def __init__(self, hostname: str = 'localhost', port: int = 1100, connector: Type[Connector] = TCPConnector, reconnect: bool = True, timeout: int = 10000) -> None:
46
+ def __init__(self, hostname: str = 'localhost', port: int = 1100, connector: Type[Connector] = TCPConnector, reconnect: bool = True, timeout: int = DEFAULT_REQUEST_TIMEOUT, directory_timeout: int = DEFAULT_DIRECTORY_TIMEOUT) -> None:
45
47
  """Creates a new Gateway instance.
46
48
 
47
49
  Args:
@@ -49,7 +51,8 @@ class Gateway:
49
51
  port : port of the fjage container. Defaults to 1100.
50
52
  connector : Connector class to use. Defaults to TCPConnector.
51
53
  reconnect : whether to keep the connection alive. Defaults to True.
52
- timeout : default timeout in milliseconds for requests. Defaults to 10000.
54
+ timeout : default timeout in milliseconds for request(). Defaults to 1000.
55
+ directory_timeout : default timeout in milliseconds for directory queries. Defaults to 6000.
53
56
  """
54
57
  if not isinstance(hostname, str) or not hostname:
55
58
  raise ValueError("hostname must be a non-empty string")
@@ -61,12 +64,15 @@ class Gateway:
61
64
  raise ValueError("reconnect must be a boolean")
62
65
  if not isinstance(timeout, int) or timeout <= 0:
63
66
  raise ValueError("timeout must be a positive integer")
67
+ if not isinstance(directory_timeout, int) or directory_timeout <= 0:
68
+ raise ValueError("directory_timeout must be a positive integer")
64
69
 
65
70
  self._pending_actions = ThreadSafeDict()
66
71
  self._pending_requests = ThreadSafeDict()
67
72
  self._queue = ThreadSafeDeque(maxlen=DEFAULT_MAX_QUEUE_SIZE)
68
73
  self._subscriptions:dict[AgentID, bool] = dict()
69
74
  self._timeout = timeout
75
+ self._directory_timeout = directory_timeout
70
76
  self.aid = AgentID("gateway-" + str(uuid.uuid4()), owner=self)
71
77
  self.connector = connector(host=hostname, port=port, reconnect_delay=5 if reconnect else -1)
72
78
  self.connector.set_receive_callback(self._msg_rx)
@@ -90,19 +96,20 @@ class Gateway:
90
96
  json_msg = JSONMessage.createSend(msg=msg, relay=True)
91
97
  self._msg_tx(json_msg)
92
98
 
93
- def receive(self, msg_filter: Union[Callable, Type[Message], Message, None]=None, timeout: Optional[int] = None, **kwargs) -> Any:
99
+ def receive(self, msg_filter: Union[Callable, Type[Message], Message, None]=None, timeout: int = NON_BLOCKING, **kwargs) -> Any:
94
100
  """Receives a message from the fjage container.
95
101
 
96
102
  Args:
97
103
  msg_filter : a filter to apply to incoming messages
98
- timeout : timeout in milliseconds. Defaults to None, which uses the gateway's default timeout.
104
+ timeout : timeout in milliseconds. Defaults to NON_BLOCKING (0 ms).
99
105
 
100
106
  Returns:
101
107
  Message or None: received message or None if timeout
102
108
  """
103
109
 
104
110
  if timeout is None:
105
- timeout = self._timeout
111
+ timeout = self.NON_BLOCKING
112
+
106
113
  if not isinstance(timeout, int):
107
114
  raise ValueError("timeout must be an integer")
108
115
 
@@ -196,7 +203,7 @@ class Gateway:
196
203
  def agents(self, timeout: Optional[int] = None) -> list[AgentID]:
197
204
  """Gets the list of all agents connected to the fjage container"""
198
205
  if timeout is None:
199
- timeout = self._timeout
206
+ timeout = self._directory_timeout
200
207
  json_msg = JSONMessage.createAgents()
201
208
  rsp = self._msg_tx_rx(json_msg, timeout)
202
209
  if rsp is not None and hasattr(rsp, 'agentIDs') and isinstance(rsp.agentIDs, list):
@@ -204,6 +211,17 @@ class Gateway:
204
211
  logger.debug("Response to agents() request does not contain agentIDs")
205
212
  return []
206
213
 
214
+ def services(self, timeout: Optional[int] = None) -> list[str]:
215
+ """Gets the list of all services provided by agents connected to the fjage container"""
216
+ if timeout is None:
217
+ timeout = self._directory_timeout
218
+ json_msg = JSONMessage.createServices()
219
+ rsp = self._msg_tx_rx(json_msg, timeout)
220
+ if rsp is not None and hasattr(rsp, 'services') and isinstance(rsp.services, list):
221
+ return rsp.services
222
+ logger.debug("Response to services() request does not contain services")
223
+ return []
224
+
207
225
  def contains_agent(self, agentID: AgentID, timeout: Optional[int] = None) -> bool:
208
226
  """ A python style method name for containsAgent() """
209
227
  return self.containsAgent(agentID, timeout)
@@ -211,7 +229,7 @@ class Gateway:
211
229
  def containsAgent(self, agentID: AgentID, timeout: Optional[int] = None) -> bool:
212
230
  """Checks if the given agent is connected to the fjage container"""
213
231
  if timeout is None:
214
- timeout = self._timeout
232
+ timeout = self._directory_timeout
215
233
  json_msg = JSONMessage.createContainsAgent(agentID=agentID)
216
234
  rsp = self._msg_tx_rx(json_msg, timeout)
217
235
  if rsp is not None and hasattr(rsp, 'answer') and isinstance(rsp.answer, bool):
@@ -226,7 +244,7 @@ class Gateway:
226
244
  def agentForService(self, service: Union[str, enum.Enum], timeout: Optional[int] = None) -> Optional[AgentID]:
227
245
  """Finds an agent that provides the given service."""
228
246
  if timeout is None:
229
- timeout = self._timeout
247
+ timeout = self._directory_timeout
230
248
  if isinstance(service, enum.Enum):
231
249
  service = service.value
232
250
  json_msg = JSONMessage.createAgentForService(service=service)
@@ -243,7 +261,7 @@ class Gateway:
243
261
  def agentsForService(self, service: Union[str, enum.Enum], timeout: Optional[int] = None) -> list[AgentID]:
244
262
  """Retrieves a list of all agents that provide the given service."""
245
263
  if timeout is None:
246
- timeout = self._timeout
264
+ timeout = self._directory_timeout
247
265
  if isinstance(service, enum.Enum):
248
266
  service = service.value
249
267
  json_msg = JSONMessage.createAgentsForService(service=service)
@@ -128,6 +128,12 @@ class JSONMessage:
128
128
  jm.action = Actions.AGENTS.value
129
129
  return jm
130
130
 
131
+ @staticmethod
132
+ def createServices() -> "JSONMessage":
133
+ jm = JSONMessage()
134
+ jm.action = Actions.SERVICES.value
135
+ return jm
136
+
131
137
  @staticmethod
132
138
  def createContainsAgent(agentID: AgentID) -> "JSONMessage":
133
139
  if not isinstance(agentID, AgentID):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fjagepy
3
- Version: 2.1.2
3
+ Version: 2.2.0
4
4
  Summary: fjage Gateway in Python
5
5
  Author-email: Chinmay Pendharkar <chinmay@subnero.com>
6
6
  License: BSD-3-Clause
@@ -277,9 +277,9 @@ To build the documentation locally:
277
277
  # Install documentation dependencies
278
278
  pip install -e ".[docs]"
279
279
  # Build docs
280
- sphinx-build -b html docs/ ../../docs/pydocs/
280
+ sphinx-build -b html docs/ ../../build/docs/pydocs/
281
281
  # View in browser
282
- open ../../docs/pydocs/index.html
282
+ open ../../build/docs/pydocs/index.html
283
283
  ```
284
284
 
285
285
  ## Compatibility
@@ -306,7 +306,7 @@ This project is licensed under the BSD 3-Clause License. See the [LICENSE](../..
306
306
 
307
307
  ## Support
308
308
 
309
- - **Documentation**: [fjåge Documentation](https://fjage.readthedocs.io/)
309
+ - **Documentation**: [fjåge Documentation](https://org-arl.github.io/fjage/)
310
310
  - **Issues**: [GitHub Issues](https://github.com/org-arl/fjage/issues)
311
311
  - **Discussions**: [GitHub Discussions](https://github.com/org-arl/fjage/discussions)
312
312
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fjagepy"
7
- version = "2.1.2"
7
+ version = "2.2.0"
8
8
  description = "fjage Gateway in Python"
9
9
  readme = "README.md"
10
10
  license = {text = "BSD-3-Clause"}
@@ -32,6 +32,14 @@ def test_gateway_close(gateway):
32
32
  sleep(0.1)
33
33
  assert not gateway.connector.is_connected()
34
34
 
35
+ def test_gateway_uses_split_default_timeouts(gateway):
36
+ """Gateway should use 1s request defaults and 6s directory-query defaults."""
37
+ assert gateway._timeout == 1000
38
+ assert gateway._directory_timeout == 6000
39
+ agent = gateway.agent('test')
40
+ assert agent is not None, "Expected gateway.agent('test') to return an AgentID"
41
+ assert agent._timeout == 1000
42
+
35
43
  def test_gateway_send_message(monkeypatch, gateway):
36
44
  """Gateway should send a message over a socket."""
37
45
  shell = gateway.agent('shell')
@@ -166,11 +174,9 @@ def test_gateway_send_receive_many(gateway):
166
174
  gateway.send(smr)
167
175
 
168
176
  for type in range(1, NMSG + 1):
169
- m = gateway.receive(lambda m: isinstance(m, SendMsgRsp), timeout=2000)
177
+ m = gateway.receive(lambda m: isinstance(m, SendMsgRsp), timeout=5000)
170
178
  if m and m.type:
171
179
  rxed[m.type - 1] = True
172
- else:
173
- print(f'Error getting SendMsgRsp #{type} : {m}')
174
180
 
175
181
  assert rxed.count(False) == 0
176
182
 
@@ -224,6 +230,16 @@ def test_gateway_request_all_agents(gateway):
224
230
  assert 'test' in aids
225
231
  gateway.close()
226
232
 
233
+ def test_gateway_request_all_services(gateway):
234
+ """Gateway should be able to request for all services from the master container."""
235
+ services = gateway.services()
236
+ assert services is not None
237
+ assert isinstance(services, list)
238
+ assert len(services) > 0
239
+ assert 'server' in services
240
+ assert 'org.arl.fjage.test.Services.TEST' in services
241
+ gateway.close()
242
+
227
243
  def test_gateway_check_agent_exists(gateway):
228
244
  """Gateway should be able to check if an agent exists on the master container."""
229
245
  aid = AgentID('S', owner=gateway)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes