Skip to content

Commit 4055453

Browse files
Fix linting issues: isort import sorting and add to pyproject.toml packages
- Fixed import sorting in worker.py, starter.py, workflows.py, test_imports.py - Added multiline_logging to pyproject.toml packages list for proper build inclusion - All black formatting already applied in previous commit Co-Authored-By: deepika awasthi <deepika.awasthi@temporal.io>
1 parent 1011682 commit 4055453

8 files changed

Lines changed: 44 additions & 36 deletions

File tree

multiline_logging/activities.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ async def failing_activity(should_fail: bool) -> str:
1616
@activity.defn
1717
async def complex_failing_activity() -> str:
1818
"""Activity that creates a complex multiline traceback"""
19+
1920
def nested_function():
2021
def deeply_nested():
2122
raise Exception("Deep exception with\nvery long\nmultiline\nerror message")
23+
2224
deeply_nested()
23-
25+
2426
nested_function()
2527
return "This won't be reached"

multiline_logging/interceptor.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ async def execute_activity(self, input: ExecuteActivityInput) -> Any:
2424
exception_data = {
2525
"message": str(e),
2626
"type": type(e).__name__,
27-
"traceback": traceback.format_exc().replace("\n", " | ")
27+
"traceback": traceback.format_exc().replace("\n", " | "),
2828
}
29-
29+
3030
logger.error(f"Activity exception: {json.dumps(exception_data)}")
31-
31+
3232
raise e
3333

3434

@@ -40,13 +40,13 @@ async def execute_workflow(self, input: ExecuteWorkflowInput) -> Any:
4040
exception_data = {
4141
"message": str(e),
4242
"type": type(e).__name__,
43-
"traceback": traceback.format_exc().replace("\n", " | ")
43+
"traceback": traceback.format_exc().replace("\n", " | "),
4444
}
45-
45+
4646
if not workflow.unsafe.is_replaying():
4747
with workflow.unsafe.sandbox_unrestricted():
4848
logger.error(f"Workflow exception: {json.dumps(exception_data)}")
49-
49+
5050
raise e
5151

5252

@@ -56,7 +56,9 @@ class MultilineLoggingInterceptor(Interceptor):
5656
def intercept_activity(
5757
self, next: ActivityInboundInterceptor
5858
) -> ActivityInboundInterceptor:
59-
return _MultilineLoggingActivityInboundInterceptor(super().intercept_activity(next))
59+
return _MultilineLoggingActivityInboundInterceptor(
60+
super().intercept_activity(next)
61+
)
6062

6163
def workflow_interceptor_class(
6264
self, input: WorkflowInterceptorClassInput

multiline_logging/starter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
23
from temporalio.client import Client
4+
35
from multiline_logging.workflows import MultilineLoggingWorkflow
46

57

@@ -8,8 +10,8 @@ async def main():
810

911
test_cases = [
1012
"activity_exception",
11-
"complex_activity_exception",
12-
"workflow_exception"
13+
"complex_activity_exception",
14+
"workflow_exception",
1315
]
1416

1517
for test_case in test_cases:
@@ -19,7 +21,7 @@ async def main():
1921
MultilineLoggingWorkflow.run,
2022
test_case,
2123
id=f"multiline-logging-{test_case}",
22-
task_queue="multiline-logging-task-queue"
24+
task_queue="multiline-logging-task-queue",
2325
)
2426
print(f"Result: {result}")
2527
except Exception as e:

multiline_logging/test_imports.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
try:
77
from interceptor import MultilineLoggingInterceptor
8-
print('✅ Interceptor imports successfully')
9-
10-
from activities import failing_activity, complex_failing_activity
11-
print('✅ Activities import successfully')
12-
8+
9+
print("✅ Interceptor imports successfully")
10+
11+
from activities import complex_failing_activity, failing_activity
12+
13+
print("✅ Activities import successfully")
14+
1315
from workflows import MultilineLoggingWorkflow
14-
print('✅ Workflows import successfully')
15-
16-
print('✅ All imports work correctly!')
17-
16+
17+
print("✅ Workflows import successfully")
18+
19+
print("✅ All imports work correctly!")
20+
1821
except ImportError as e:
19-
print(f'❌ Import error: {e}')
22+
print(f"❌ Import error: {e}")
2023
exit(1)

multiline_logging/test_interceptor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def test_multiline_formatting():
1919
exception_data = {
2020
"message": str(e),
2121
"type": type(e).__name__,
22-
"traceback": traceback.format_exc().replace("\n", " | ")
22+
"traceback": traceback.format_exc().replace("\n", " | "),
2323
}
24-
24+
2525
json_output = json.dumps(exception_data)
26-
26+
2727
print("Original exception message:")
2828
print(repr(str(e)))
2929
print("\nFormatted JSON output:")
@@ -32,7 +32,7 @@ def test_multiline_formatting():
3232
print(f"- Contains newlines in JSON: {'\\n' in json_output}")
3333
print(f"- JSON is valid: {json.loads(json_output) is not None}")
3434
print(f"- Single line: {json_output.count('\\n') == 0}")
35-
35+
3636
return json_output
3737

3838

multiline_logging/worker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import asyncio
22
import logging
3+
34
from temporalio.client import Client
45
from temporalio.worker import Worker
56

6-
from multiline_logging.activities import failing_activity, complex_failing_activity
7+
from multiline_logging.activities import complex_failing_activity, failing_activity
78
from multiline_logging.interceptor import MultilineLoggingInterceptor
89
from multiline_logging.workflows import MultilineLoggingWorkflow
910

1011
logging.basicConfig(level=logging.INFO)
1112

13+
1214
async def main():
1315
client = await Client.connect("localhost:7233")
1416

multiline_logging/workflows.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from datetime import timedelta
2+
23
from temporalio import workflow
34

45
with workflow.unsafe.imports_passed_through():
5-
from .activities import failing_activity, complex_failing_activity
6+
from .activities import complex_failing_activity, failing_activity
67

78

89
@workflow.defn
@@ -11,18 +12,13 @@ class MultilineLoggingWorkflow:
1112
async def run(self, test_type: str) -> str:
1213
if test_type == "activity_exception":
1314
return await workflow.execute_activity(
14-
failing_activity,
15-
True,
16-
schedule_to_close_timeout=timedelta(seconds=5)
15+
failing_activity, True, schedule_to_close_timeout=timedelta(seconds=5)
1716
)
1817
elif test_type == "complex_activity_exception":
1918
return await workflow.execute_activity(
20-
complex_failing_activity,
21-
schedule_to_close_timeout=timedelta(seconds=5)
19+
complex_failing_activity, schedule_to_close_timeout=timedelta(seconds=5)
2220
)
2321
elif test_type == "workflow_exception":
24-
raise RuntimeError(
25-
"Workflow exception with\nmultiple lines\nof error text"
26-
)
22+
raise RuntimeError("Workflow exception with\nmultiple lines\nof error text")
2723
else:
2824
return "No exception test"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ packages = [
9191
"hello",
9292
"langchain",
9393
"message_passing",
94+
"multiline_logging",
9495
"nexus",
9596
"open_telemetry",
9697
"patching",
@@ -143,4 +144,4 @@ ignore_errors = true
143144

144145
[[tool.mypy.overrides]]
145146
module = "opentelemetry.*"
146-
ignore_errors = true
147+
ignore_errors = true

0 commit comments

Comments
 (0)