sapiopycommons 2025.9.8a728__py3-none-any.whl → 2025.9.8a731__py3-none-any.whl

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.

Potentially problematic release.


This version of sapiopycommons might be problematic. Click here for more details.

@@ -1,4 +1,7 @@
1
+ from __future__ import annotations
2
+
1
3
  import asyncio
4
+ from argparse import ArgumentParser
2
5
  from typing import Any
3
6
 
4
7
  import grpc
@@ -16,12 +19,30 @@ class SapioGrpcServer:
16
19
  """
17
20
  port: int
18
21
  options: list[tuple[str, Any]]
22
+ debug_mode: bool
19
23
  _converter_services: list[ConverterServiceServicer]
20
24
  _script_services: list[ScriptServiceServicer]
21
25
  _tool_services: list[ToolServiceServicer]
22
26
 
23
- def __init__(self, port: int = 50051, message_mb_size: int = 1024, options: list[tuple[str, Any]] | None = None) \
24
- -> None:
27
+ @staticmethod
28
+ def args_parser() -> ArgumentParser:
29
+ """
30
+ Create an argument parser for the gRPC server.
31
+
32
+ :return: The argument parser.
33
+ """
34
+ parser = ArgumentParser()
35
+ parser.add_argument("--debug_mode", "-d", action="store_true")
36
+ parser.add_argument("--port", "-p", default=50051, type=int)
37
+ parser.add_argument("--message_mb_size", "-s", default=1024, type=int)
38
+ return parser
39
+
40
+ @staticmethod
41
+ def from_args(options: list[tuple[str, Any]] | None = None) -> SapioGrpcServer:
42
+ return SapioGrpcServer(options=options, **vars(SapioGrpcServer.args_parser().parse_args()))
43
+
44
+ def __init__(self, port: int = 50051, message_mb_size: int = 1024, debug_mode: bool = False,
45
+ options: list[tuple[str, Any]] | None = None) -> None:
25
46
  """
26
47
  Initialize the gRPC server with the specified port and message size.
27
48
 
@@ -29,6 +50,7 @@ class SapioGrpcServer:
29
50
  :param message_mb_size: The maximum size of a message in megabytes.
30
51
  :param options: Additional gRPC server options to set. This should be a list of tuples where the first item is
31
52
  the option name and the second item is the option value.
53
+ :param debug_mode: Sets the debug mode for services.
32
54
  """
33
55
  if isinstance(port, str):
34
56
  port = int(port)
@@ -39,6 +61,9 @@ class SapioGrpcServer:
39
61
  ]
40
62
  if options:
41
63
  self.options.extend(options)
64
+ self.debug_mode = debug_mode
65
+ if debug_mode:
66
+ print("Debug mode is enabled.")
42
67
  self._converter_services = []
43
68
  self._script_services = []
44
69
  self._tool_services = []
@@ -65,6 +90,7 @@ class SapioGrpcServer:
65
90
 
66
91
  :param service: The tool service to register with the server.
67
92
  """
93
+ service.debug_mode = self.debug_mode
68
94
  self._tool_services.append(service)
69
95
 
70
96
  def start(self) -> None:
@@ -217,6 +217,8 @@ class ToolServiceBase(ToolServiceServicer, ABC):
217
217
  A base class for implementing a tool service. Subclasses should implement the register_tools method to register
218
218
  their tools with the service.
219
219
  """
220
+ debug_mode: bool = False
221
+
220
222
  def GetToolDetails(self, request: ToolDetailsRequestPbo, context: ServicerContext) -> ToolDetailsResponsePbo:
221
223
  try:
222
224
  # Get the tool details from the registered tools.
@@ -327,7 +329,7 @@ class ToolServiceBase(ToolServiceServicer, ABC):
327
329
  tool: ToolBase = registered_tools[find_tool]()
328
330
  try:
329
331
  # Setup the tool with details from the request.
330
- tool.setup(user, request, context)
332
+ tool.setup(user, request, context, self.debug_mode)
331
333
  # Validate that the provided inputs match the tool's expected inputs.
332
334
  if len(request.input) != len(tool.input_configs):
333
335
  msg: str = (f"Expected {len(tool.input_configs)} inputs for this tool, but got {len(request.input)} "
@@ -350,8 +352,16 @@ class ToolServiceBase(ToolServiceServicer, ABC):
350
352
  tool.log_exception("Exception occurred during tool execution.", e)
351
353
  return False, str(e), [], tool.logs
352
354
  finally:
353
- # Clean up any temporary files created by the tool.
354
- tool.temp_data.cleanup()
355
+ # Clean up any temporary files created by the tool. If in debug mode, then log the files instead
356
+ # so that they can be manually inspected.
357
+ if self.debug_mode:
358
+ print("Temporary files/directories created during tool execution:")
359
+ for directory in tool.temp_data.directories:
360
+ print(f"\tDirectory: {directory}")
361
+ for file in tool.temp_data.files:
362
+ print(f"\tFile: {file}")
363
+ else:
364
+ tool.temp_data.cleanup()
355
365
 
356
366
 
357
367
  class ToolBase(ABC):
@@ -370,6 +380,7 @@ class ToolBase(ABC):
370
380
  logs: list[str]
371
381
  logger: Logger
372
382
  verbose_logging: bool
383
+ debug_mode: bool
373
384
 
374
385
  temp_data: TempFileHandler
375
386
 
@@ -415,7 +426,7 @@ class ToolBase(ABC):
415
426
  self.logger = logging.getLogger(f"ToolBase.{self._name}")
416
427
  ensure_logger_initialized(self.logger)
417
428
 
418
- def setup(self, user: SapioUser, request: ProcessStepRequestPbo, context: ServicerContext) -> None:
429
+ def setup(self, user: SapioUser, request: ProcessStepRequestPbo, context: ServicerContext, debug_mode: bool) -> None:
419
430
  """
420
431
  Setup the tool with the user, request, and context. This method can be overridden by subclasses to perform
421
432
  additional setup.
@@ -424,11 +435,14 @@ class ToolBase(ABC):
424
435
  system.
425
436
  :param request: The request object containing the input data.
426
437
  :param context: The gRPC context.
438
+ :param debug_mode: If true, the tool should run in debug mode, providing additional logging and not cleaning
439
+ up temporary files.
427
440
  """
428
441
  self.user = user
429
442
  self.request = request
430
443
  self.context = context
431
444
  self.verbose_logging = request.verbose_logging
445
+ self.debug_mode = debug_mode
432
446
 
433
447
  def add_input(self, container_type: ContainerType, content_type: str, display_name: str, description: str,
434
448
  structure_example: str | bytes | None = None, validation: str | None = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.9.8a728
3
+ Version: 2025.9.8a731
4
4
  Summary: Official Sapio Python API Utilities Package
5
5
  Project-URL: Homepage, https://github.com/sapiosciences
6
6
  Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
@@ -2,9 +2,9 @@ sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  sapiopycommons/ai/converter_service_base.py,sha256=TMSyEekbbqMk9dRuAtLlSJ1sA1H8KpyCDlSOeqGFMWI,5115
4
4
  sapiopycommons/ai/protobuf_utils.py,sha256=cBjbxoFAwU02kNUxEce95WnMU2CMuDD-qFaeWgvQJMQ,24599
5
- sapiopycommons/ai/server.py,sha256=jvmAcs4y8qp0d483wCAUgPlSBSoUUQvCjv_OvQXEGUs,4274
5
+ sapiopycommons/ai/server.py,sha256=jy81xjtt7uCY3sHG9iL_-0dy8st5J4fWSZ5Pwq3L1_s,5262
6
6
  sapiopycommons/ai/test_client.py,sha256=iPhn7cvKNLmDAXrjpmIkZpW2pDWlUhJZHDLHJbEoWsg,15673
7
- sapiopycommons/ai/tool_service_base.py,sha256=AVW6Yf0l_l4x__dosIZyAJun4UmZAZaBJRYzNru_fD4,45806
7
+ sapiopycommons/ai/tool_service_base.py,sha256=s6NJaOLUN3Ewkn1yoByKqHn7jn40yopD0ohySnKaOB0,46526
8
8
  sapiopycommons/ai/protoapi/fielddefinitions/fields_pb2.py,sha256=8tKXwLXcqFGdQHHSEBSi6Fd7dcaCFoOqmhjzqhenb_M,2372
9
9
  sapiopycommons/ai/protoapi/fielddefinitions/fields_pb2.pyi,sha256=FwtXmNAf7iYGEFm4kbqb04v77jNHbZg18ZmEDhle_bU,1444
10
10
  sapiopycommons/ai/protoapi/fielddefinitions/fields_pb2_grpc.py,sha256=uO25bcnfGqXpP4ggUur54Nr73Wj-DGWftExzLNcxdHI,931
@@ -99,7 +99,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
99
99
  sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
100
100
  sapiopycommons/webhook/webhook_handlers.py,sha256=7o_wXOruhT9auNh8OfhJAh4WhhiPKij67FMBSpGPICc,39939
101
101
  sapiopycommons/webhook/webservice_handlers.py,sha256=cvW6Mk_110BzYqkbk63Kg7jWrltBCDALOlkJRu8h4VQ,14300
102
- sapiopycommons-2025.9.8a728.dist-info/METADATA,sha256=6IMqQ6KDSTEcXMpbfbwpBSC_eGnhn-336JCdZkvNmR0,3142
103
- sapiopycommons-2025.9.8a728.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
104
- sapiopycommons-2025.9.8a728.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
105
- sapiopycommons-2025.9.8a728.dist-info/RECORD,,
102
+ sapiopycommons-2025.9.8a731.dist-info/METADATA,sha256=pe2sML9LAOWEXV-Hd8RtSS9VgCoorYA-aVG7_a9_f1Y,3142
103
+ sapiopycommons-2025.9.8a731.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
104
+ sapiopycommons-2025.9.8a731.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
105
+ sapiopycommons-2025.9.8a731.dist-info/RECORD,,