22
33from __future__ import annotations
44
5- from collections .abc import Callable
6- from typing import Literal , TypeGuard , cast
5+ from typing import TYPE_CHECKING , Literal , TypeGuard , cast
76
87from nutrient_dws .builder .base_builder import BaseBuilder
98from nutrient_dws .builder .constant import ActionWithFileInput , BuildOutputs
2120 WorkflowWithPartsStage ,
2221)
2322from nutrient_dws .errors import ValidationError
24- from nutrient_dws .http import AnalyzeBuildRequestData , BuildRequestData , NutrientClientOptions
23+ from nutrient_dws .http import (
24+ AnalyzeBuildRequestData ,
25+ BuildRequestData ,
26+ NutrientClientOptions ,
27+ )
2528from nutrient_dws .inputs import (
2629 FileInput ,
2730 NormalizedFileData ,
2831 is_remote_file_input ,
2932 process_file_input ,
3033 validate_file_input ,
3134)
32- from nutrient_dws .types .build_actions import BuildAction
33- from nutrient_dws .types .build_instruction import BuildInstructions
34- from nutrient_dws .types .build_output import (
35- BuildOutput ,
36- ImageOutputOptions ,
37- JSONContentOutputOptions ,
38- PDFAOutputOptions ,
39- PDFOutput ,
40- PDFOutputOptions ,
41- PDFUAOutputOptions ,
42- )
4335from nutrient_dws .types .file_handle import FileHandle , RemoteFileHandle
44- from nutrient_dws .types .input_parts import (
45- DocumentPart ,
46- DocumentPartOptions ,
47- FilePart ,
48- FilePartOptions ,
49- HTMLPart ,
50- HTMLPartOptions ,
51- NewPagePart ,
52- NewPagePartOptions ,
53- )
36+
37+ if TYPE_CHECKING :
38+ from collections .abc import Callable
39+
40+ from nutrient_dws .types .build_actions import BuildAction
41+ from nutrient_dws .types .build_instruction import BuildInstructions
42+ from nutrient_dws .types .build_output import (
43+ BuildOutput ,
44+ ImageOutputOptions ,
45+ JSONContentOutputOptions ,
46+ PDFAOutputOptions ,
47+ PDFOutput ,
48+ PDFOutputOptions ,
49+ PDFUAOutputOptions ,
50+ )
51+ from nutrient_dws .types .input_parts import (
52+ DocumentPart ,
53+ DocumentPartOptions ,
54+ FilePart ,
55+ FilePartOptions ,
56+ HTMLPart ,
57+ HTMLPartOptions ,
58+ NewPagePart ,
59+ NewPagePartOptions ,
60+ )
5461
5562
5663class StagedWorkflowBuilder (
@@ -85,7 +92,9 @@ def _register_asset(self, asset: FileInput) -> str:
8592 The asset key that can be used in BuildActions
8693 """
8794 if not validate_file_input (asset ):
88- raise ValidationError ("Invalid file input provided to workflow" , {"asset" : asset })
95+ raise ValidationError (
96+ "Invalid file input provided to workflow" , {"asset" : asset }
97+ )
8998
9099 if is_remote_file_input (asset ):
91100 raise ValidationError (
@@ -256,7 +265,9 @@ def add_html_part(
256265 assets_field = []
257266 for asset in assets :
258267 if is_remote_file_input (asset ):
259- raise ValidationError ("Assets file input cannot be a URL" , {"input" : asset })
268+ raise ValidationError (
269+ "Assets file input cannot be a URL" , {"input" : asset }
270+ )
260271 asset_key = self ._register_asset (asset )
261272 assets_field .append (asset_key )
262273
@@ -369,7 +380,9 @@ def add_document_part(
369380
370381 # Action methods (WorkflowWithPartsStage)
371382
372- def apply_actions (self , actions : list [ApplicableAction ]) -> WorkflowWithActionsStage :
383+ def apply_actions (
384+ self , actions : list [ApplicableAction ]
385+ ) -> WorkflowWithActionsStage :
373386 """Apply multiple actions to the workflow.
374387
375388 Args:
@@ -503,13 +516,17 @@ async def execute(
503516 # Step 1: Validate
504517 self .current_step = 1
505518 if options and options .get ("onProgress" ):
506- cast ("Callable[[int, int], None]" , options ["onProgress" ])(self .current_step , 3 )
519+ cast ("Callable[[int, int], None]" , options ["onProgress" ])(
520+ self .current_step , 3
521+ )
507522 self ._validate ()
508523
509524 # Step 2: Prepare files
510525 self .current_step = 2
511526 if options and options .get ("onProgress" ):
512- cast ("Callable[[int, int], None]" , options ["onProgress" ])(self .current_step , 3 )
527+ cast ("Callable[[int, int], None]" , options ["onProgress" ])(
528+ self .current_step , 3
529+ )
513530
514531 output_config = self .build_instructions .get ("output" )
515532 if not output_config :
@@ -526,7 +543,9 @@ async def execute(
526543 # Step 3: Process response
527544 self .current_step = 3
528545 if options and options .get ("onProgress" ):
529- cast ("Callable[[int, int], None]" , options ["onProgress" ])(self .current_step , 3 )
546+ cast ("Callable[[int, int], None]" , options ["onProgress" ])(
547+ self .current_step , 3
548+ )
530549
531550 if output_config ["type" ] == "json-content" :
532551 result ["success" ] = True
@@ -554,7 +573,9 @@ async def execute(
554573
555574 workflow_error : WorkflowError = {
556575 "step" : self .current_step ,
557- "error" : error if isinstance (error , Exception ) else Exception (str (error )),
576+ "error" : error
577+ if isinstance (error , Exception )
578+ else Exception (str (error )),
558579 }
559580 cast ("list[WorkflowError]" , result ["errors" ]).append (workflow_error )
560581
@@ -582,7 +603,8 @@ async def dry_run(self) -> WorkflowDryRunResult:
582603 self ._validate ()
583604
584605 response = await self ._send_request (
585- "/analyze_build" , AnalyzeBuildRequestData (instructions = self .build_instructions )
606+ "/analyze_build" ,
607+ AnalyzeBuildRequestData (instructions = self .build_instructions ),
586608 )
587609
588610 result ["success" ] = True
@@ -594,7 +616,9 @@ async def dry_run(self) -> WorkflowDryRunResult:
594616
595617 workflow_error : WorkflowError = {
596618 "step" : 0 ,
597- "error" : error if isinstance (error , Exception ) else Exception (str (error )),
619+ "error" : error
620+ if isinstance (error , Exception )
621+ else Exception (str (error )),
598622 }
599623 cast ("list[WorkflowError]" , result ["errors" ]).append (workflow_error )
600624
0 commit comments