Skip to content

Commit e95bd45

Browse files
committed
remove test, fix ruff
1 parent 76f8145 commit e95bd45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+367
-4565
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ repos:
1212
- id: debug-statements
1313
- id: mixed-line-ending
1414

15+
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.12.8
18+
hooks:
19+
- id: ruff
20+
args: [--fix]
21+
- id: ruff-format
22+
1523
- repo: https://github.com/pre-commit/mirrors-mypy
1624
rev: v1.17.1
1725
hooks:
File renamed without changes.
File renamed without changes.

WORKFLOW.md

Whitespace-only changes.

pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dws-add-windsurf-rule = "scripts.add_windsurf_rule:main"
7272

7373
[tool.ruff]
7474
target-version = "py310"
75-
line-length = 100
75+
7676

7777
[tool.ruff.lint]
7878
select = [
@@ -90,10 +90,21 @@ select = [
9090
"RUF", # Ruff-specific rules
9191
]
9292
ignore = [
93+
"E501", # Line too long
94+
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
9395
"D100", # Missing docstring in public module
96+
"D101", # Missing docstring in public class
97+
"D103", # Missing docstring in public function
9498
"D104", # Missing docstring in public package
9599
"D107", # Missing docstring in __init__
100+
"D205", # 1 blank line required between summary line and description
101+
"UP007", # Use `X | Y` for type annotations
96102
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` - not supported in Python 3.10 runtime
103+
"UP045", # Use `X | None` for type annotations
104+
"N802", # Function name should be lowercase
105+
"N803", # Argument name should be lowercase
106+
"N815", # Variable in class scope should not be mixedCase
107+
"N811", # Constant imported as non-constant
97108
]
98109

99110
[tool.ruff.lint.pydocstyle]

src/nutrient_dws/builder/builder.py

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from __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

87
from nutrient_dws.builder.base_builder import BaseBuilder
98
from nutrient_dws.builder.constant import ActionWithFileInput, BuildOutputs
@@ -21,36 +20,44 @@
2120
WorkflowWithPartsStage,
2221
)
2322
from 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+
)
2528
from 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-
)
4335
from 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

5663
class 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

Comments
 (0)