Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/draftwright/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2634,13 +2634,15 @@ def export(
formats,
dpi: int = 150,
reproducible: bool | None = None,
lint: bool = True,
) -> dict[str, str]:
return export_drawing(
self,
out,
formats=formats,
dpi=dpi,
reproducible=reproducible,
lint=lint,
supported_formats=self._EXPORT_FORMATS,
lint_and_log=self._lint_and_log,
write_svg=self._write_svg,
Expand Down
10 changes: 8 additions & 2 deletions src/draftwright/drawing_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ def export_drawing(
formats,
dpi: int = 150,
reproducible: bool | None = None,
lint: bool = True,
supported_formats,
lint_and_log,
write_svg,
write_dxf,
pdf_text_runs,
) -> dict[str, str]:
"""Lint, then write the requested output *formats*; return ``{format: path}``.
"""By default, lint before writing *formats*; return ``{format: path}``.

*formats* is a format name or an iterable from ``("svg", "dxf", "pdf", "png")``. PDF
renders from the SVG and PNG from the PDF, so the SVG/PDF are written as intermediates
Expand All @@ -111,6 +112,10 @@ def export_drawing(
part (+2.0% of a whole CTC-01 job). The cost grows with part count, so a
part-heavy sheet may want ``False`` — see :func:`draftwright.export._elements`.
Passing the keyword here overrides the drawing's default for this call only.

``lint=False`` skips the export-time critique and log for disposable previews.
It does not validate the drawing: call ``drawing.lint()`` or export with the
default before treating an output as a final technical drawing.
"""
drawing.finalize() # #426: drain any recorded intents before export (no-op if none)
# An explicit keyword wins; otherwise the drawing's own default (build_drawing's).
Expand All @@ -129,7 +134,8 @@ def export_drawing(
raise ValueError(f"png export needs dpi > 0, got {dpi}")

# Validate before lint: declared-drawing critique may build recognition evidence.
lint_and_log()
if lint:
lint_and_log()

want_set = set(want)
paths: dict[str, str] = {}
Expand Down
16 changes: 16 additions & 0 deletions tests/test_export_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,19 @@ def test_make_drawing_keeps_its_tuple_output(self, tmp_path):
svg, dxf = make_drawing(Box(30, 20, 10), out=str(tmp_path / "mk"))
assert Path(svg).exists() and svg.endswith(".svg")
assert Path(dxf).exists() and dxf.endswith(".dxf")


def test_preview_export_skips_lint_but_normal_export_keeps_it_issue_2209(tmp_path, monkeypatch):
drawing = build_drawing(Box(20, 10, 5), page="A4", scale=1)

def fail_if_linted():
raise RuntimeError("export lint ran")

monkeypatch.setattr(drawing, "_lint_and_log", fail_if_linted)
paths = drawing.export(str(tmp_path / "preview"), formats=("svg",), lint=False)
assert paths["svg"] == str(tmp_path / "preview.svg")
assert (tmp_path / "preview.svg").is_file()

with pytest.raises(RuntimeError, match="export lint ran"):
drawing.export(str(tmp_path / "final"), formats=("svg",))
assert not (tmp_path / "final.svg").exists()
Loading