draftwright 0.1.0__tar.gz → 0.1.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: draftwright
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Automated technical-drawing generation for build123d
5
5
  Project-URL: Homepage, https://github.com/pzfreo/draftwright
6
6
  Project-URL: Repository, https://github.com/pzfreo/draftwright
@@ -683,6 +683,8 @@ Requires-Python: >=3.10
683
683
  Requires-Dist: build123d-drafting-helpers>=0.10.0
684
684
  Requires-Dist: build123d>=0.9.0
685
685
  Requires-Dist: kiwisolver<2,>=1.4
686
+ Provides-Extra: pdf
687
+ Requires-Dist: cairosvg>=2.7; extra == 'pdf'
686
688
  Description-Content-Type: text/markdown
687
689
 
688
690
  # draftwright
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "draftwright"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Automated technical-drawing generation for build123d"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -28,6 +28,9 @@ classifiers = [
28
28
  "Programming Language :: Python :: 3.12",
29
29
  ]
30
30
 
31
+ [project.optional-dependencies]
32
+ pdf = ["cairosvg>=2.7"]
33
+
31
34
  [project.scripts]
32
35
  draftwright = "draftwright.make_drawing:_cli"
33
36
 
@@ -1142,6 +1142,27 @@ class Drawing:
1142
1142
  self.dxf_path = dxf_path
1143
1143
  return svg_path, dxf_path
1144
1144
 
1145
+ def export_pdf(self, out=None) -> str:
1146
+ """Write a PDF rendered from the SVG. Requires ``cairosvg`` (install with
1147
+ ``pip install draftwright[pdf]``). Calls :meth:`export` first if the SVG
1148
+ hasn't been written yet. Returns the PDF path."""
1149
+ try:
1150
+ import cairosvg
1151
+ except ImportError as exc:
1152
+ raise ImportError(
1153
+ "PDF export requires cairosvg. Install it with: pip install draftwright[pdf]"
1154
+ ) from exc
1155
+
1156
+ svg_path: str
1157
+ if not hasattr(self, "svg_path") or self.svg_path is None:
1158
+ svg_path, _ = self.export(out=out)
1159
+ else:
1160
+ svg_path = self.svg_path
1161
+ pdf_path = svg_path[:-4] + ".pdf" if svg_path.endswith(".svg") else svg_path + ".pdf"
1162
+ cairosvg.svg2pdf(url=svg_path, write_to=pdf_path)
1163
+ _log.info("PDF → %s", pdf_path)
1164
+ return pdf_path
1165
+
1145
1166
  def _add_shapes(self, exporter):
1146
1167
  """Add every view layer and annotation to *exporter* with error context."""
1147
1168
  for name, (vis, hid) in self.views.items():
@@ -2960,7 +2981,6 @@ def generate_script(
2960
2981
 
2961
2982
 
2962
2983
  def _cli():
2963
- logging.basicConfig(level=logging.INFO, format="%(message)s")
2964
2984
  ap = argparse.ArgumentParser(
2965
2985
  description="Zero-AI STEP → technical drawing (SVG + DXF, or editable .py script)",
2966
2986
  formatter_class=argparse.ArgumentDefaultsHelpFormatter,
@@ -2997,13 +3017,29 @@ def _cli():
2997
3017
  "'annotate' — add PMI-derived dimensions to the drawing"
2998
3018
  ),
2999
3019
  )
3020
+ ap.add_argument(
3021
+ "--pdf",
3022
+ action="store_true",
3023
+ help="Also write a PDF (requires draftwright[pdf] / cairosvg)",
3024
+ )
3025
+ ap.add_argument(
3026
+ "-v",
3027
+ "--verbose",
3028
+ action="store_true",
3029
+ help="Show detailed progress (default: warnings and errors only)",
3030
+ )
3000
3031
  args = ap.parse_args()
3001
3032
 
3033
+ logging.basicConfig(
3034
+ level=logging.INFO if args.verbose else logging.WARNING,
3035
+ format="%(message)s",
3036
+ )
3037
+
3002
3038
  if args.script and (args.scale is not None or args.page is not None):
3003
3039
  ap.error("--scale/--page only apply to direct output; edit the generated script instead")
3004
3040
 
3005
3041
  if args.script:
3006
- generate_script(
3042
+ py_path = generate_script(
3007
3043
  step_file=args.step_file,
3008
3044
  out=args.out,
3009
3045
  title=args.title,
@@ -3012,8 +3048,9 @@ def _cli():
3012
3048
  drawn_by=args.drawn_by,
3013
3049
  pmi=args.pmi,
3014
3050
  )
3051
+ print(py_path)
3015
3052
  else:
3016
- make_drawing(
3053
+ dwg = build_drawing(
3017
3054
  step_file=args.step_file,
3018
3055
  out=args.out,
3019
3056
  title=args.title,
@@ -3024,6 +3061,11 @@ def _cli():
3024
3061
  page=args.page,
3025
3062
  pmi=args.pmi,
3026
3063
  )
3064
+ svg_path, dxf_path = dwg.export()
3065
+ print(svg_path)
3066
+ print(dxf_path)
3067
+ if args.pdf:
3068
+ print(dwg.export_pdf())
3027
3069
 
3028
3070
 
3029
3071
  if __name__ == "__main__":
File without changes
File without changes
File without changes
File without changes
File without changes