exstruct 0.2.70__tar.gz → 0.2.71__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.3
2
2
  Name: exstruct
3
- Version: 0.2.70
3
+ Version: 0.2.71
4
4
  Summary: Excel to structured JSON (tables, shapes, charts) for LLM/RAG pipelines
5
5
  Keywords: excel,structure,data,exstruct
6
6
  Author: harumiWeb
@@ -67,7 +67,7 @@ ExStruct reads Excel workbooks and outputs structured data (cells, table candida
67
67
 
68
68
  - **Excel → Structured JSON**: cells, shapes, charts, table candidates, print areas/views, and auto page-break areas per sheet.
69
69
  - **Output modes**: `light` (cells + table candidates + print areas; no COM, shapes/charts empty), `standard` (texted shapes + arrows, charts, print areas), `verbose` (all shapes with width/height, charts with size, print areas). Verbose also emits cell hyperlinks. Size output is flag-controlled.
70
- - **Auto page-break export (COM only)**: capture Excel-computed auto page breaks and write per-area JSON/YAML/TOON when requested.
70
+ - **Auto page-break export (COM only)**: capture Excel-computed auto page breaks and write per-area JSON/YAML/TOON when requested (CLI option appears only when COM is available).
71
71
  - **Formats**: JSON (compact by default, `--pretty` available), YAML, TOON (optional dependencies).
72
72
  - **Table detection tuning**: adjust heuristics at runtime via API.
73
73
  - **CLI rendering** (Excel required): optional PDF and per-sheet PNGs.
@@ -99,11 +99,12 @@ exstruct input.xlsx --format yaml # YAML (needs pyyaml)
99
99
  exstruct input.xlsx --format toon # TOON (needs python-toon)
100
100
  exstruct input.xlsx --sheets-dir sheets/ # split per sheet in chosen format
101
101
  exstruct input.xlsx --print-areas-dir areas/ # split per print area (if any)
102
+ exstruct input.xlsx --auto-page-breaks-dir auto_areas/ # COM only; option appears when available
102
103
  exstruct input.xlsx --mode light # cells + table candidates only
103
104
  exstruct input.xlsx --pdf --image # PDF and PNGs (Excel required)
104
105
  ```
105
106
 
106
- Auto page-break exports are API-only (Excel/COM): set `DestinationOptions.auto_page_breaks_dir` or call `export_auto_page_breaks(...)`.
107
+ Auto page-break exports are available via API and CLI when Excel/COM is available; the CLI exposes `--auto-page-breaks-dir` only in COM-capable environments.
107
108
 
108
109
  ## Quick Start (Python)
109
110
 
@@ -409,7 +410,7 @@ In short, **exstruct = “an engine that converts Excel into a format AI can und
409
410
  - `SheetData.print_areas` holds print areas (cell coordinates) in light/standard/verbose.
410
411
  - `SheetData.auto_print_areas` holds Excel COM-computed auto page-break areas when auto page-break extraction is enabled (COM only).
411
412
  - Use `export_print_areas_as(...)` or CLI `--print-areas-dir` to write one file per print area (nothing is written if none exist).
412
- - Use `DestinationOptions.auto_page_breaks_dir` (preferred) or `export_auto_page_breaks(...)` to write per-auto-page-break files; the API raises `ValueError` if no auto page breaks exist.
413
+ - Use CLI `--auto-page-breaks-dir` (COM only), `DestinationOptions.auto_page_breaks_dir` (preferred), or `export_auto_page_breaks(...)` to write per-auto-page-break files; the API raises `ValueError` if no auto page breaks exist.
413
414
  - `PrintAreaView` includes rows and table candidates inside the area, plus shapes/charts that overlap the area (size-less shapes are treated as points). `normalize=True` rebases row/col indices to the area origin.
414
415
 
415
416
  ## License
@@ -12,7 +12,7 @@ ExStruct reads Excel workbooks and outputs structured data (cells, table candida
12
12
 
13
13
  - **Excel → Structured JSON**: cells, shapes, charts, table candidates, print areas/views, and auto page-break areas per sheet.
14
14
  - **Output modes**: `light` (cells + table candidates + print areas; no COM, shapes/charts empty), `standard` (texted shapes + arrows, charts, print areas), `verbose` (all shapes with width/height, charts with size, print areas). Verbose also emits cell hyperlinks. Size output is flag-controlled.
15
- - **Auto page-break export (COM only)**: capture Excel-computed auto page breaks and write per-area JSON/YAML/TOON when requested.
15
+ - **Auto page-break export (COM only)**: capture Excel-computed auto page breaks and write per-area JSON/YAML/TOON when requested (CLI option appears only when COM is available).
16
16
  - **Formats**: JSON (compact by default, `--pretty` available), YAML, TOON (optional dependencies).
17
17
  - **Table detection tuning**: adjust heuristics at runtime via API.
18
18
  - **CLI rendering** (Excel required): optional PDF and per-sheet PNGs.
@@ -44,11 +44,12 @@ exstruct input.xlsx --format yaml # YAML (needs pyyaml)
44
44
  exstruct input.xlsx --format toon # TOON (needs python-toon)
45
45
  exstruct input.xlsx --sheets-dir sheets/ # split per sheet in chosen format
46
46
  exstruct input.xlsx --print-areas-dir areas/ # split per print area (if any)
47
+ exstruct input.xlsx --auto-page-breaks-dir auto_areas/ # COM only; option appears when available
47
48
  exstruct input.xlsx --mode light # cells + table candidates only
48
49
  exstruct input.xlsx --pdf --image # PDF and PNGs (Excel required)
49
50
  ```
50
51
 
51
- Auto page-break exports are API-only (Excel/COM): set `DestinationOptions.auto_page_breaks_dir` or call `export_auto_page_breaks(...)`.
52
+ Auto page-break exports are available via API and CLI when Excel/COM is available; the CLI exposes `--auto-page-breaks-dir` only in COM-capable environments.
52
53
 
53
54
  ## Quick Start (Python)
54
55
 
@@ -354,7 +355,7 @@ In short, **exstruct = “an engine that converts Excel into a format AI can und
354
355
  - `SheetData.print_areas` holds print areas (cell coordinates) in light/standard/verbose.
355
356
  - `SheetData.auto_print_areas` holds Excel COM-computed auto page-break areas when auto page-break extraction is enabled (COM only).
356
357
  - Use `export_print_areas_as(...)` or CLI `--print-areas-dir` to write one file per print area (nothing is written if none exist).
357
- - Use `DestinationOptions.auto_page_breaks_dir` (preferred) or `export_auto_page_breaks(...)` to write per-auto-page-break files; the API raises `ValueError` if no auto page breaks exist.
358
+ - Use CLI `--auto-page-breaks-dir` (COM only), `DestinationOptions.auto_page_breaks_dir` (preferred), or `export_auto_page_breaks(...)` to write per-auto-page-break files; the API raises `ValueError` if no auto page breaks exist.
358
359
  - `PrintAreaView` includes rows and table candidates inside the area, plus shapes/charts that overlap the area (size-less shapes are treated as points). `normalize=True` rebases row/col indices to the area origin.
359
360
 
360
361
  ## License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "exstruct"
3
- version = "0.2.70"
3
+ version = "0.2.71"
4
4
  description = "Excel to structured JSON (tables, shapes, charts) for LLM/RAG pipelines"
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import os
5
+ import sys
6
+
7
+ from pydantic import BaseModel, Field
8
+ import xlwings as xw
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ class ComAvailability(BaseModel):
14
+ """Availability information for Excel COM-dependent features."""
15
+
16
+ available: bool = Field(
17
+ ..., description="True when Excel COM can be used from this environment."
18
+ )
19
+ reason: str | None = Field(
20
+ default=None, description="Reason COM features are unavailable."
21
+ )
22
+
23
+
24
+ def get_com_availability() -> ComAvailability:
25
+ """Detect whether Excel COM is available for CLI features.
26
+
27
+ Returns:
28
+ ComAvailability describing whether COM features can be used.
29
+ """
30
+ if os.getenv("SKIP_COM_TESTS"):
31
+ return ComAvailability(available=False, reason="SKIP_COM_TESTS is set.")
32
+
33
+ if sys.platform != "win32":
34
+ return ComAvailability(available=False, reason="Non-Windows platform.")
35
+
36
+ try:
37
+ app = xw.App(add_book=False, visible=False)
38
+ except Exception as exc:
39
+ return ComAvailability(
40
+ available=False,
41
+ reason=f"Excel COM is unavailable ({exc.__class__.__name__}).",
42
+ )
43
+
44
+ try:
45
+ app.quit()
46
+ except Exception:
47
+ logger.warning("Failed to quit Excel during COM availability check.")
48
+
49
+ return ComAvailability(available=True, reason=None)
@@ -4,9 +4,33 @@ import argparse
4
4
  from pathlib import Path
5
5
 
6
6
  from exstruct import process_excel
7
+ from exstruct.cli.availability import ComAvailability, get_com_availability
7
8
 
8
9
 
9
- def build_parser() -> argparse.ArgumentParser:
10
+ def _add_auto_page_breaks_argument(
11
+ parser: argparse.ArgumentParser, availability: ComAvailability
12
+ ) -> None:
13
+ """Add auto page-break export option when COM is available."""
14
+ if not availability.available:
15
+ return
16
+ parser.add_argument(
17
+ "--auto-page-breaks-dir",
18
+ type=Path,
19
+ help="Optional directory to write one file per auto page-break area (COM only).",
20
+ )
21
+
22
+
23
+ def build_parser(
24
+ availability: ComAvailability | None = None,
25
+ ) -> argparse.ArgumentParser:
26
+ """Build the CLI argument parser.
27
+
28
+ Args:
29
+ availability: Optional COM availability for tests or overrides.
30
+
31
+ Returns:
32
+ Configured argument parser.
33
+ """
10
34
  parser = argparse.ArgumentParser(
11
35
  description="Dev-only CLI stub for ExStruct extraction."
12
36
  )
@@ -62,10 +86,22 @@ def build_parser() -> argparse.ArgumentParser:
62
86
  type=Path,
63
87
  help="Optional directory to write one file per print area (format follows --format).",
64
88
  )
89
+ resolved_availability = (
90
+ availability if availability is not None else get_com_availability()
91
+ )
92
+ _add_auto_page_breaks_argument(parser, resolved_availability)
65
93
  return parser
66
94
 
67
95
 
68
96
  def main(argv: list[str] | None = None) -> int:
97
+ """Run the CLI entrypoint.
98
+
99
+ Args:
100
+ argv: Optional argument list for testing.
101
+
102
+ Returns:
103
+ Exit code (0 for success, 1 for failure).
104
+ """
69
105
  parser = build_parser()
70
106
  args = parser.parse_args(argv)
71
107
 
@@ -86,6 +122,7 @@ def main(argv: list[str] | None = None) -> int:
86
122
  pretty=args.pretty,
87
123
  sheets_dir=args.sheets_dir,
88
124
  print_areas_dir=args.print_areas_dir,
125
+ auto_page_breaks_dir=getattr(args, "auto_page_breaks_dir", None),
89
126
  )
90
127
  return 0
91
128
  except Exception as e:
File without changes