chalkcompute 2.1.0__tar.gz → 2.1.2__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 (126) hide show
  1. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/PKG-INFO +2 -2
  2. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_cls.py +83 -67
  3. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_function.py +431 -75
  4. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_remote_call_client.py +29 -32
  5. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_tracing.py +3 -0
  6. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/pyproject.toml +2 -2
  7. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/README.md +0 -0
  8. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/__init__.py +0 -0
  9. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/__init__.pyi +0 -0
  10. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_arrow_schema.py +0 -0
  11. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_auth_config.py +0 -0
  12. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_concurrency.py +0 -0
  13. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_connect.py +0 -0
  14. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_container.py +0 -0
  15. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/__init__.py +0 -0
  16. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/buf/__init__.py +0 -0
  17. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/buf/validate/__init__.py +0 -0
  18. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/buf/validate/validate_pb2.py +0 -0
  19. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/buf/validate/validate_pb2.pyi +0 -0
  20. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/__init__.py +0 -0
  21. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/__init__.py +0 -0
  22. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/v1/__init__.py +0 -0
  23. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/v1/arrow_pb2.py +0 -0
  24. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/v1/arrow_pb2.pyi +0 -0
  25. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/v1/arrow_pb2_grpc.py +0 -0
  26. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/arrow/v1/arrow_pb2_grpc.pyi +0 -0
  27. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/__init__.py +0 -0
  28. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/__init__.py +0 -0
  29. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/agent_pb2.py +0 -0
  30. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/agent_pb2.pyi +0 -0
  31. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/agent_pb2_grpc.py +0 -0
  32. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/agent_pb2_grpc.pyi +0 -0
  33. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/audit_pb2.py +0 -0
  34. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/audit_pb2.pyi +0 -0
  35. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/audit_pb2_grpc.py +0 -0
  36. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/audit_pb2_grpc.pyi +0 -0
  37. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/displayagent_pb2.py +0 -0
  38. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/displayagent_pb2.pyi +0 -0
  39. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/displayagent_pb2_grpc.py +0 -0
  40. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/displayagent_pb2_grpc.pyi +0 -0
  41. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/featurepermission_pb2.py +0 -0
  42. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/featurepermission_pb2.pyi +0 -0
  43. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/featurepermission_pb2_grpc.py +0 -0
  44. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/featurepermission_pb2_grpc.pyi +0 -0
  45. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/permissions_pb2.py +0 -0
  46. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/permissions_pb2.pyi +0 -0
  47. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/permissions_pb2_grpc.py +0 -0
  48. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/auth/v1/permissions_pb2_grpc.pyi +0 -0
  49. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/common/__init__.py +0 -0
  50. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/common/v1/__init__.py +0 -0
  51. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/common/v1/chalk_error_pb2.py +0 -0
  52. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/common/v1/chalk_error_pb2.pyi +0 -0
  53. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/__init__.py +0 -0
  54. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/v1/__init__.py +0 -0
  55. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/v1/service_pb2.py +0 -0
  56. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/v1/service_pb2.pyi +0 -0
  57. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/v1/service_pb2_grpc.py +0 -0
  58. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/container/v1/service_pb2_grpc.pyi +0 -0
  59. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/__init__.py +0 -0
  60. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/v1/__init__.py +0 -0
  61. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/v1/service_pb2.py +0 -0
  62. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/v1/service_pb2.pyi +0 -0
  63. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/v1/service_pb2_grpc.py +0 -0
  64. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/externalfunctioncatalog/v1/service_pb2_grpc.pyi +0 -0
  65. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/runtime/__init__.py +0 -0
  66. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/runtime/v1/__init__.py +0 -0
  67. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/runtime/v1/remote_python_call_pb2.py +0 -0
  68. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/runtime/v1/remote_python_call_pb2.pyi +0 -0
  69. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/__init__.py +0 -0
  70. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/v1/__init__.py +0 -0
  71. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/v1/service_pb2.py +0 -0
  72. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/v1/service_pb2.pyi +0 -0
  73. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/v1/service_pb2_grpc.py +0 -0
  74. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/sandbox/v1/service_pb2_grpc.pyi +0 -0
  75. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/__init__.py +0 -0
  76. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/v1/__init__.py +0 -0
  77. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/v1/service_pb2.py +0 -0
  78. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/v1/service_pb2.pyi +0 -0
  79. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/v1/service_pb2_grpc.py +0 -0
  80. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/scalinggroup/v1/service_pb2_grpc.pyi +0 -0
  81. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/__init__.py +0 -0
  82. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/__init__.py +0 -0
  83. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/encoding_pb2.py +0 -0
  84. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/encoding_pb2.pyi +0 -0
  85. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/encoding_pb2_grpc.py +0 -0
  86. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/encoding_pb2_grpc.pyi +0 -0
  87. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/field_change_pb2.py +0 -0
  88. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/field_change_pb2.pyi +0 -0
  89. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/field_change_pb2_grpc.py +0 -0
  90. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/field_change_pb2_grpc.pyi +0 -0
  91. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/sensitive_pb2.py +0 -0
  92. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/sensitive_pb2.pyi +0 -0
  93. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/sensitive_pb2_grpc.py +0 -0
  94. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/utils/v1/sensitive_pb2_grpc.pyi +0 -0
  95. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/__init__.py +0 -0
  96. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v1/__init__.py +0 -0
  97. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v1/volume_pb2.py +0 -0
  98. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v1/volume_pb2.pyi +0 -0
  99. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v1/volume_pb2_grpc.py +0 -0
  100. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v1/volume_pb2_grpc.pyi +0 -0
  101. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v2/__init__.py +0 -0
  102. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v2/volume_pb2.py +0 -0
  103. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v2/volume_pb2.pyi +0 -0
  104. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v2/volume_pb2_grpc.py +0 -0
  105. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_gen/chalk/volume/v2/volume_pb2_grpc.pyi +0 -0
  106. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_ignore.py +0 -0
  107. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_image.py +0 -0
  108. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_logging.py +0 -0
  109. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_model.py +0 -0
  110. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_naming.py +0 -0
  111. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_progress.py +0 -0
  112. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_proto_pool.py +0 -0
  113. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_quota.py +0 -0
  114. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_rate_limit.py +0 -0
  115. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_remote_call_native.pyi +0 -0
  116. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_remote_function_tracing.py +0 -0
  117. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_retry.py +0 -0
  118. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_sandbox.py +0 -0
  119. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_scaling_group.py +0 -0
  120. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_secret.py +0 -0
  121. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_volume.py +0 -0
  122. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/_vvolume.py +0 -0
  123. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/chalkcompute/py.typed +0 -0
  124. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/rust/chalkcompute_remote_client/Cargo.lock +0 -0
  125. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/rust/chalkcompute_remote_client/Cargo.toml +0 -0
  126. {chalkcompute-2.1.0 → chalkcompute-2.1.2}/rust/chalkcompute_remote_client/src/lib.rs +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chalkcompute
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Requires-Dist: grpcio>=1.60.0
5
5
  Requires-Dist: protobuf>=4.25.0
6
6
  Requires-Dist: httpx>=0.25.0
7
7
  Requires-Dist: blake3>=1.0.0
8
- Requires-Dist: chalk-remote-call-python>=1.4.0
8
+ Requires-Dist: chalk-remote-call-python>=1.6.3
9
9
  Requires-Dist: pyyaml>=6.0.0
10
10
  Requires-Dist: opentelemetry-api>=1.20.0
11
11
  Requires-Dist: opentelemetry-sdk>=1.20.0
@@ -47,6 +47,7 @@ import ast
47
47
  import inspect
48
48
  import logging
49
49
  import os
50
+ import textwrap
50
51
  import time
51
52
  import typing
52
53
  from dataclasses import dataclass, field
@@ -69,9 +70,11 @@ from chalkcompute._function import (
69
70
  FunctionVersionInfo,
70
71
  RemoteFunction,
71
72
  SerializationFormat,
73
+ _assert_stripped_source_self_contained,
72
74
  _build_and_upload,
73
75
  _callable_input_names,
74
76
  _cleanup_temp_files,
77
+ _entrypoint_source,
75
78
  _extract_field_names,
76
79
  _is_chalkcompute_decorator,
77
80
  _local_install_entrypoint,
@@ -508,74 +511,78 @@ def _generate_class_handler_shim(
508
511
 
509
512
  method_caller = "_instance" if method_has_self else class_name
510
513
  if batched:
511
- parts += [
512
- "",
513
- f"_is_coroutine = inspect.iscoroutinefunction({method_caller}.{method_name})",
514
- "",
515
- "",
516
- "def handler(events, contexts):",
517
- " if _is_coroutine:",
518
- " import asyncio",
519
- " async def _run_all():",
520
- " results = []",
521
- " for event in events:",
522
- " columns = {k: v.to_pylist() for k, v in event.items()}",
523
- " n = len(next(iter(columns.values())))",
524
- " per_caller = []",
525
- " for i in range(n):",
526
- " kwargs = {k: v[i] for k, v in columns.items()}",
527
- f" per_caller.append(await {method_caller}.{method_name}(**kwargs))",
528
- " results.append(per_caller)",
529
- " return results",
530
- " return asyncio.run(_run_all())",
531
- " results = []",
532
- " for event in events:",
533
- " columns = {k: v.to_pylist() for k, v in event.items()}",
534
- " n = len(next(iter(columns.values())))",
535
- " per_caller = []",
536
- " for i in range(n):",
537
- " kwargs = {k: v[i] for k, v in columns.items()}",
538
- f" per_caller.append({method_caller}.{method_name}(**kwargs))",
539
- " results.append(per_caller)",
540
- " return results",
541
- ]
514
+ parts.append(
515
+ textwrap.dedent(f"""\
516
+ _target = inspect.unwrap({method_caller}.{method_name})
517
+ _is_coroutine = inspect.iscoroutinefunction(_target)
518
+
519
+
520
+ def handler(events, contexts):
521
+ if _is_coroutine:
522
+ import asyncio
523
+ async def _run_all():
524
+ results = []
525
+ for event in events:
526
+ columns = {{k: v.to_pylist() for k, v in event.items()}}
527
+ n = len(next(iter(columns.values())))
528
+ per_caller = []
529
+ for i in range(n):
530
+ kwargs = {{k: v[i] for k, v in columns.items()}}
531
+ per_caller.append(await {method_caller}.{method_name}(**kwargs))
532
+ results.append(per_caller)
533
+ return results
534
+ return asyncio.run(_run_all())
535
+ results = []
536
+ for event in events:
537
+ columns = {{k: v.to_pylist() for k, v in event.items()}}
538
+ n = len(next(iter(columns.values())))
539
+ per_caller = []
540
+ for i in range(n):
541
+ kwargs = {{k: v[i] for k, v in columns.items()}}
542
+ per_caller.append({method_caller}.{method_name}(**kwargs))
543
+ results.append(per_caller)
544
+ return results
545
+ """).rstrip()
546
+ )
542
547
  else:
543
- parts += [
544
- "",
545
- f"_is_sync_gen = inspect.isgeneratorfunction({method_caller}.{method_name})",
546
- f"_is_async_gen = inspect.isasyncgenfunction({method_caller}.{method_name})",
547
- f"_is_coroutine = inspect.iscoroutinefunction({method_caller}.{method_name}) and not _is_async_gen",
548
- "",
549
- "",
550
- "def handler(event, context):",
551
- " n = len(next(iter(event.values())))",
552
- " if _is_sync_gen:",
553
- " def _gen():",
554
- " for i in range(n):",
555
- " kwargs = {k: v[i].as_py() for k, v in event.items()}",
556
- f" yield from {method_caller}.{method_name}(**kwargs)",
557
- " return _gen()",
558
- " elif _is_async_gen:",
559
- " async def _agen():",
560
- " for i in range(n):",
561
- " kwargs = {k: v[i].as_py() for k, v in event.items()}",
562
- f" async for item in {method_caller}.{method_name}(**kwargs):",
563
- " yield item",
564
- " return _agen()",
565
- " elif _is_coroutine:",
566
- " import asyncio",
567
- " results = []",
568
- " for i in range(n):",
569
- " kwargs = {k: v[i].as_py() for k, v in event.items()}",
570
- f" results.append(asyncio.run({method_caller}.{method_name}(**kwargs)))",
571
- " return results",
572
- " else:",
573
- " results = []",
574
- " for i in range(n):",
575
- " kwargs = {k: v[i].as_py() for k, v in event.items()}",
576
- f" results.append({method_caller}.{method_name}(**kwargs))",
577
- " return results",
578
- ]
548
+ parts.append(
549
+ textwrap.dedent(f"""\
550
+ _target = inspect.unwrap({method_caller}.{method_name})
551
+ _is_sync_gen = inspect.isgeneratorfunction(_target)
552
+ _is_async_gen = inspect.isasyncgenfunction(_target)
553
+ _is_coroutine = inspect.iscoroutinefunction(_target) and not _is_async_gen
554
+
555
+
556
+ def handler(event, context):
557
+ n = len(next(iter(event.values())))
558
+ if _is_sync_gen:
559
+ def _gen():
560
+ for i in range(n):
561
+ kwargs = {{k: v[i].as_py() for k, v in event.items()}}
562
+ yield from {method_caller}.{method_name}(**kwargs)
563
+ return _gen()
564
+ elif _is_async_gen:
565
+ async def _agen():
566
+ for i in range(n):
567
+ kwargs = {{k: v[i].as_py() for k, v in event.items()}}
568
+ async for item in {method_caller}.{method_name}(**kwargs):
569
+ yield item
570
+ return _agen()
571
+ elif _is_coroutine:
572
+ import asyncio
573
+ results = []
574
+ for i in range(n):
575
+ kwargs = {{k: v[i].as_py() for k, v in event.items()}}
576
+ results.append(asyncio.run({method_caller}.{method_name}(**kwargs)))
577
+ return results
578
+ else:
579
+ results = []
580
+ for i in range(n):
581
+ kwargs = {{k: v[i].as_py() for k, v in event.items()}}
582
+ results.append({method_caller}.{method_name}(**kwargs))
583
+ return results
584
+ """).rstrip()
585
+ )
579
586
 
580
587
  return "\n".join(parts) + "\n"
581
588
 
@@ -931,6 +938,15 @@ class RemoteClass:
931
938
  if _should_strip_source():
932
939
  source = _source_text_for_deploy(source_file)
933
940
  stripped = _strip_chalkcompute_from_class_source(source)
941
+ entrypoint_sources: list[str] = []
942
+ for method_info in self._methods.values():
943
+ entrypoint_sources.extend(_entrypoint_source(method_info.func))
944
+ _assert_stripped_source_self_contained(
945
+ source,
946
+ stripped,
947
+ label=f"Class {self._class_name!r}",
948
+ entrypoint_sources=entrypoint_sources,
949
+ )
934
950
  source_file = _write_temp(stripped)
935
951
  temp_files.append(source_file)
936
952
  elif not source_path.is_file():