tableau-inspector 0.1.0__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.
Files changed (81) hide show
  1. tableau_inspector-0.1.0/.gitignore +12 -0
  2. tableau_inspector-0.1.0/LICENSE +21 -0
  3. tableau_inspector-0.1.0/PKG-INFO +89 -0
  4. tableau_inspector-0.1.0/README.md +43 -0
  5. tableau_inspector-0.1.0/pyproject.toml +44 -0
  6. tableau_inspector-0.1.0/reports/.gitkeep +0 -0
  7. tableau_inspector-0.1.0/src/tableau_inspector/__init__.py +1 -0
  8. tableau_inspector-0.1.0/src/tableau_inspector/analyzer.py +55 -0
  9. tableau_inspector-0.1.0/src/tableau_inspector/cli.py +267 -0
  10. tableau_inspector-0.1.0/src/tableau_inspector/compare/__init__.py +36 -0
  11. tableau_inspector-0.1.0/src/tableau_inspector/compare/build_compare.py +325 -0
  12. tableau_inspector-0.1.0/src/tableau_inspector/compare/diff.py +101 -0
  13. tableau_inspector-0.1.0/src/tableau_inspector/docs/__init__.py +26 -0
  14. tableau_inspector-0.1.0/src/tableau_inspector/docs/build_documentation.py +264 -0
  15. tableau_inspector-0.1.0/src/tableau_inspector/lineage/__init__.py +30 -0
  16. tableau_inspector-0.1.0/src/tableau_inspector/lineage/build_lineage.py +116 -0
  17. tableau_inspector-0.1.0/src/tableau_inspector/lineage/graph.py +165 -0
  18. tableau_inspector-0.1.0/src/tableau_inspector/lineage/node_ids.py +29 -0
  19. tableau_inspector-0.1.0/src/tableau_inspector/lineage/query.py +92 -0
  20. tableau_inspector-0.1.0/src/tableau_inspector/models/__init__.py +99 -0
  21. tableau_inspector-0.1.0/src/tableau_inspector/models/analysis_result.py +35 -0
  22. tableau_inspector-0.1.0/src/tableau_inspector/models/calculation.py +11 -0
  23. tableau_inspector-0.1.0/src/tableau_inspector/models/compare.py +39 -0
  24. tableau_inspector-0.1.0/src/tableau_inspector/models/connection.py +13 -0
  25. tableau_inspector-0.1.0/src/tableau_inspector/models/dashboard.py +11 -0
  26. tableau_inspector-0.1.0/src/tableau_inspector/models/datasource.py +19 -0
  27. tableau_inspector-0.1.0/src/tableau_inspector/models/documentation.py +151 -0
  28. tableau_inspector-0.1.0/src/tableau_inspector/models/field.py +23 -0
  29. tableau_inspector-0.1.0/src/tableau_inspector/models/filter.py +15 -0
  30. tableau_inspector-0.1.0/src/tableau_inspector/models/lineage.py +75 -0
  31. tableau_inspector-0.1.0/src/tableau_inspector/models/parameter.py +21 -0
  32. tableau_inspector-0.1.0/src/tableau_inspector/models/rule_result.py +17 -0
  33. tableau_inspector-0.1.0/src/tableau_inspector/models/search.py +28 -0
  34. tableau_inspector-0.1.0/src/tableau_inspector/models/serialization.py +49 -0
  35. tableau_inspector-0.1.0/src/tableau_inspector/models/workbook.py +25 -0
  36. tableau_inspector-0.1.0/src/tableau_inspector/models/worksheet.py +14 -0
  37. tableau_inspector-0.1.0/src/tableau_inspector/parser/__init__.py +0 -0
  38. tableau_inspector-0.1.0/src/tableau_inspector/parser/calculation_parser.py +21 -0
  39. tableau_inspector-0.1.0/src/tableau_inspector/parser/dashboard_parser.py +49 -0
  40. tableau_inspector-0.1.0/src/tableau_inspector/parser/datasource_parser.py +138 -0
  41. tableau_inspector-0.1.0/src/tableau_inspector/parser/filter_parser.py +28 -0
  42. tableau_inspector-0.1.0/src/tableau_inspector/parser/parameter_parser.py +44 -0
  43. tableau_inspector-0.1.0/src/tableau_inspector/parser/workbook_loader.py +81 -0
  44. tableau_inspector-0.1.0/src/tableau_inspector/parser/workbook_parser.py +69 -0
  45. tableau_inspector-0.1.0/src/tableau_inspector/parser/worksheet_parser.py +49 -0
  46. tableau_inspector-0.1.0/src/tableau_inspector/report/__init__.py +0 -0
  47. tableau_inspector-0.1.0/src/tableau_inspector/report/compare_grouping.py +27 -0
  48. tableau_inspector-0.1.0/src/tableau_inspector/report/console_compare_reporter.py +68 -0
  49. tableau_inspector-0.1.0/src/tableau_inspector/report/console_lineage_reporter.py +89 -0
  50. tableau_inspector-0.1.0/src/tableau_inspector/report/console_reporter.py +56 -0
  51. tableau_inspector-0.1.0/src/tableau_inspector/report/console_search_reporter.py +46 -0
  52. tableau_inspector-0.1.0/src/tableau_inspector/report/html_compare_reporter.py +137 -0
  53. tableau_inspector-0.1.0/src/tableau_inspector/report/html_doc_reporter.py +352 -0
  54. tableau_inspector-0.1.0/src/tableau_inspector/report/html_escape.py +11 -0
  55. tableau_inspector-0.1.0/src/tableau_inspector/report/html_reporter.py +157 -0
  56. tableau_inspector-0.1.0/src/tableau_inspector/report/interfaces.py +36 -0
  57. tableau_inspector-0.1.0/src/tableau_inspector/report/markdown_doc_reporter.py +338 -0
  58. tableau_inspector-0.1.0/src/tableau_inspector/report/markdown_escape.py +20 -0
  59. tableau_inspector-0.1.0/src/tableau_inspector/report/tree_lines.py +8 -0
  60. tableau_inspector-0.1.0/src/tableau_inspector/rules/__init__.py +24 -0
  61. tableau_inspector-0.1.0/src/tableau_inspector/rules/blank_dashboard_titles.py +32 -0
  62. tableau_inspector-0.1.0/src/tableau_inspector/rules/default_filter_applied.py +39 -0
  63. tableau_inspector-0.1.0/src/tableau_inspector/rules/dev_database_connection.py +44 -0
  64. tableau_inspector-0.1.0/src/tableau_inspector/rules/duplicate_calculations.py +52 -0
  65. tableau_inspector-0.1.0/src/tableau_inspector/rules/duplicate_field_aliases.py +45 -0
  66. tableau_inspector-0.1.0/src/tableau_inspector/rules/hidden_worksheets.py +38 -0
  67. tableau_inspector-0.1.0/src/tableau_inspector/rules/missing_captions.py +51 -0
  68. tableau_inspector-0.1.0/src/tableau_inspector/rules/rule.py +13 -0
  69. tableau_inspector-0.1.0/src/tableau_inspector/rules/unused_calculations.py +40 -0
  70. tableau_inspector-0.1.0/src/tableau_inspector/rules/unused_parameters.py +40 -0
  71. tableau_inspector-0.1.0/src/tableau_inspector/search/__init__.py +30 -0
  72. tableau_inspector-0.1.0/src/tableau_inspector/search/build_search.py +69 -0
  73. tableau_inspector-0.1.0/src/tableau_inspector/search/matcher.py +5 -0
  74. tableau_inspector-0.1.0/src/tableau_inspector/utils/__init__.py +0 -0
  75. tableau_inspector-0.1.0/src/tableau_inspector/utils/ansi.py +35 -0
  76. tableau_inspector-0.1.0/src/tableau_inspector/utils/errors.py +37 -0
  77. tableau_inspector-0.1.0/src/tableau_inspector/utils/field_reference_scanner.py +20 -0
  78. tableau_inspector-0.1.0/src/tableau_inspector/utils/reference_index.py +70 -0
  79. tableau_inspector-0.1.0/src/tableau_inspector/utils/timestamps.py +17 -0
  80. tableau_inspector-0.1.0/src/tableau_inspector/utils/version.py +7 -0
  81. tableau_inspector-0.1.0/src/tableau_inspector/utils/xml_utils.py +55 -0
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .pytest_cache/
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+ reports/*.html
10
+ !reports/.gitkeep
11
+ *.log
12
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joshua Bowen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: tableau-inspector
3
+ Version: 0.1.0
4
+ Summary: Analyze Tableau workbooks (.twb, .twbx) for common issues before publishing.
5
+ Author: Joshua Bowen
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Joshua Bowen
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Keywords: linter,static-analysis,tableau,twb,twbx
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Environment :: Console
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: Topic :: Software Development :: Quality Assurance
40
+ Requires-Python: >=3.10
41
+ Provides-Extra: dev
42
+ Requires-Dist: build; extra == 'dev'
43
+ Requires-Dist: pytest>=8; extra == 'dev'
44
+ Requires-Dist: twine; extra == 'dev'
45
+ Description-Content-Type: text/markdown
46
+
47
+ # tableau-inspector (Python)
48
+
49
+ Local-first CLI that statically analyzes Tableau workbooks (`.twb` / `.twbx`) for common issues —
50
+ dev-only DB connections, hidden worksheets, unused calculations/parameters, duplicate calculations,
51
+ default filters, blank dashboard titles, missing captions, duplicate field aliases — before you
52
+ publish. Everything is parsed from the workbook's embedded XML; no network calls are made.
53
+
54
+ This is a Python port of the Node.js `tableau-inspector` CLI, with the same functionality and
55
+ zero runtime dependencies (stdlib only).
56
+
57
+ ## Install
58
+
59
+ ```bash
60
+ pip install -e .
61
+ ```
62
+
63
+ ## Quick start
64
+
65
+ ```bash
66
+ # Lint a workbook for common publishing issues
67
+ tableau-inspector analyze workbook.twbx
68
+
69
+ # Trace what a field/calculation depends on and what depends on it
70
+ tableau-inspector lineage workbook.twbx --field "Customer Segment"
71
+
72
+ # Search calculated fields by name or formula text
73
+ tableau-inspector search workbook.twbx "profit"
74
+
75
+ # Diff two versions of a workbook
76
+ tableau-inspector compare old.twbx new.twbx
77
+ ```
78
+
79
+ Every command also supports `--json` for machine-readable output, and `analyze`/`compare` support
80
+ `--html` for a shareable, self-contained HTML report.
81
+
82
+ ## Documentation
83
+
84
+ Run `tableau-inspector --help` or `tableau-inspector <command> --help` for the full option
85
+ reference and the complete list of rules `analyze` checks.
86
+
87
+ ## License
88
+
89
+ MIT © Joshua Bowen
@@ -0,0 +1,43 @@
1
+ # tableau-inspector (Python)
2
+
3
+ Local-first CLI that statically analyzes Tableau workbooks (`.twb` / `.twbx`) for common issues —
4
+ dev-only DB connections, hidden worksheets, unused calculations/parameters, duplicate calculations,
5
+ default filters, blank dashboard titles, missing captions, duplicate field aliases — before you
6
+ publish. Everything is parsed from the workbook's embedded XML; no network calls are made.
7
+
8
+ This is a Python port of the Node.js `tableau-inspector` CLI, with the same functionality and
9
+ zero runtime dependencies (stdlib only).
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install -e .
15
+ ```
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ # Lint a workbook for common publishing issues
21
+ tableau-inspector analyze workbook.twbx
22
+
23
+ # Trace what a field/calculation depends on and what depends on it
24
+ tableau-inspector lineage workbook.twbx --field "Customer Segment"
25
+
26
+ # Search calculated fields by name or formula text
27
+ tableau-inspector search workbook.twbx "profit"
28
+
29
+ # Diff two versions of a workbook
30
+ tableau-inspector compare old.twbx new.twbx
31
+ ```
32
+
33
+ Every command also supports `--json` for machine-readable output, and `analyze`/`compare` support
34
+ `--html` for a shareable, self-contained HTML report.
35
+
36
+ ## Documentation
37
+
38
+ Run `tableau-inspector --help` or `tableau-inspector <command> --help` for the full option
39
+ reference and the complete list of rules `analyze` checks.
40
+
41
+ ## License
42
+
43
+ MIT © Joshua Bowen
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tableau-inspector"
7
+ dynamic = ["version"]
8
+ description = "Analyze Tableau workbooks (.twb, .twbx) for common issues before publishing."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "Joshua Bowen" }]
13
+ keywords = ["tableau", "linter", "static-analysis", "twb", "twbx"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Software Development :: Quality Assurance",
26
+ ]
27
+
28
+ [project.scripts]
29
+ tableau-inspector = "tableau_inspector.cli:main"
30
+
31
+ [project.optional-dependencies]
32
+ dev = ["pytest>=8", "build", "twine"]
33
+
34
+ [tool.hatch.version]
35
+ path = "src/tableau_inspector/__init__.py"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/tableau_inspector"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ exclude = ["/examples", "/tests", "/reports"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
File without changes
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from tableau_inspector.models import AnalysisResult, Workbook, WorkbookInventory, WorkbookSummary
6
+ from tableau_inspector.parser.workbook_loader import WorkbookLoader
7
+ from tableau_inspector.parser.workbook_parser import WorkbookParser
8
+ from tableau_inspector.rules import RULES
9
+ from tableau_inspector.utils.timestamps import iso_timestamp
10
+ from tableau_inspector.utils.version import read_tool_version
11
+
12
+
13
+ def _compute_summary(workbook: Workbook) -> WorkbookSummary:
14
+ return WorkbookSummary(
15
+ dashboards=len(workbook.dashboards),
16
+ worksheets=len(workbook.worksheets),
17
+ calculations=len(workbook.calculations),
18
+ parameters=len(workbook.parameters),
19
+ filters=len(workbook.filters),
20
+ datasources=len(workbook.datasources),
21
+ )
22
+
23
+
24
+ def _compute_inventory(workbook: Workbook) -> WorkbookInventory:
25
+ return WorkbookInventory(
26
+ dashboards=[d.name for d in workbook.dashboards],
27
+ worksheets=[w.name for w in workbook.worksheets],
28
+ calculations=[c.caption for c in workbook.calculations],
29
+ parameters=[p.caption for p in workbook.parameters],
30
+ connections=[
31
+ f"{c.class_}: {c.server if c.server is not None else (c.dbname if c.dbname is not None else 'n/a')}"
32
+ for c in workbook.connections
33
+ ],
34
+ )
35
+
36
+
37
+ def analyze(file_path: str) -> AnalysisResult:
38
+ loader = WorkbookLoader()
39
+ loader.load(file_path)
40
+ xml = loader.get_xml()
41
+
42
+ workbook_name = os.path.splitext(os.path.basename(file_path))[0]
43
+ workbook = WorkbookParser().parse(xml, workbook_name)
44
+
45
+ issues = [issue for rule in RULES for issue in rule.run(workbook)]
46
+
47
+ return AnalysisResult(
48
+ workbook_name=workbook.name,
49
+ file_path=file_path,
50
+ analyzed_at=iso_timestamp(),
51
+ tool_version=read_tool_version(),
52
+ summary=_compute_summary(workbook),
53
+ inventory=_compute_inventory(workbook),
54
+ issues=issues,
55
+ )
@@ -0,0 +1,267 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import re
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ from tableau_inspector import __version__
10
+ from tableau_inspector.analyzer import analyze
11
+ from tableau_inspector.compare import compare_workbooks
12
+ from tableau_inspector.docs import generate_documentation
13
+ from tableau_inspector.lineage import generate_lineage
14
+ from tableau_inspector.models.serialization import to_json_value
15
+ from tableau_inspector.report.console_compare_reporter import ConsoleCompareReporter
16
+ from tableau_inspector.report.console_lineage_reporter import ConsoleLineageReporter
17
+ from tableau_inspector.report.console_reporter import ConsoleReporter
18
+ from tableau_inspector.report.console_search_reporter import ConsoleSearchReporter
19
+ from tableau_inspector.search import generate_search
20
+ from tableau_inspector.utils.errors import InvalidLineageOptionsError, TableauInspectorError
21
+ from tableau_inspector.utils.timestamps import iso_timestamp
22
+
23
+
24
+ def _default_report_path(workbook_name: str) -> str:
25
+ timestamp = re.sub(r"[:.]", "-", iso_timestamp())
26
+ safe_name = re.sub(r"[^a-zA-Z0-9_-]+", "_", workbook_name)
27
+ return str(Path("reports") / f"{safe_name}-{timestamp}.html")
28
+
29
+
30
+ def _default_docs_path(workbook_name: str, ext: str) -> str:
31
+ safe_name = re.sub(r"[^a-zA-Z0-9_-]+", "_", workbook_name)
32
+ return str(Path("docs") / f"{safe_name}.{ext}")
33
+
34
+
35
+ def _print_error(error: Exception, verbose: bool) -> None:
36
+ if isinstance(error, TableauInspectorError):
37
+ print(f"Error: {error}", file=sys.stderr)
38
+ else:
39
+ print(f"Unexpected error: {error}", file=sys.stderr)
40
+ if verbose:
41
+ import traceback
42
+
43
+ traceback.print_exc()
44
+
45
+
46
+ def _cmd_analyze(args: argparse.Namespace) -> int:
47
+ try:
48
+ result = analyze(args.file)
49
+
50
+ if args.json:
51
+ print(json.dumps(to_json_value(result), indent=2))
52
+ else:
53
+ ConsoleReporter().report(result)
54
+
55
+ if args.html or args.output:
56
+ from tableau_inspector.report.html_reporter import HtmlReporter
57
+
58
+ output_path = args.output or _default_report_path(result.workbook_name)
59
+ HtmlReporter(output_path).report(result)
60
+ print(f"\nHTML report written to {output_path}")
61
+
62
+ has_critical = any(issue.severity == "critical" for issue in result.issues)
63
+ return 1 if has_critical else 0
64
+ except Exception as error: # noqa: BLE001
65
+ _print_error(error, args.verbose)
66
+ return 2
67
+
68
+
69
+ def _cmd_lineage(args: argparse.Namespace) -> int:
70
+ try:
71
+ if args.field and args.calculation:
72
+ raise InvalidLineageOptionsError("Pass either --field or --calculation, not both.")
73
+
74
+ result = generate_lineage(args.file, args.field or args.calculation)
75
+
76
+ if args.json:
77
+ print(json.dumps(to_json_value(result), indent=2))
78
+ else:
79
+ ConsoleLineageReporter().report(result)
80
+
81
+ return 0
82
+ except Exception as error: # noqa: BLE001
83
+ _print_error(error, args.verbose)
84
+ return 2
85
+
86
+
87
+ def _cmd_search(args: argparse.Namespace) -> int:
88
+ try:
89
+ result = generate_search(args.file, args.query, formula_only=args.formula)
90
+
91
+ if args.json:
92
+ print(json.dumps(to_json_value(result), indent=2))
93
+ else:
94
+ ConsoleSearchReporter().report(result)
95
+
96
+ return 0
97
+ except Exception as error: # noqa: BLE001
98
+ _print_error(error, args.verbose)
99
+ return 2
100
+
101
+
102
+ def _cmd_compare(args: argparse.Namespace) -> int:
103
+ try:
104
+ result = compare_workbooks(args.old_file, args.new_file)
105
+
106
+ if args.json:
107
+ print(json.dumps(to_json_value(result), indent=2))
108
+ else:
109
+ ConsoleCompareReporter().report(result)
110
+
111
+ if args.html or args.output:
112
+ from tableau_inspector.report.html_compare_reporter import HtmlCompareReporter
113
+
114
+ output_path = args.output or _default_report_path(result.workbook_name)
115
+ HtmlCompareReporter(output_path).report(result)
116
+ print(f"\nHTML report written to {output_path}")
117
+
118
+ return 0
119
+ except Exception as error: # noqa: BLE001
120
+ _print_error(error, args.verbose)
121
+ return 2
122
+
123
+
124
+ def _cmd_docs(args: argparse.Namespace) -> int:
125
+ try:
126
+ documentation = generate_documentation(args.file)
127
+
128
+ if args.json:
129
+ print(json.dumps(to_json_value(documentation), indent=2))
130
+ return 0
131
+
132
+ fmt = "html" if args.html else "md"
133
+ output_path = args.output or _default_docs_path(documentation.workbook.name, fmt)
134
+ if fmt == "html":
135
+ from tableau_inspector.report.html_doc_reporter import HtmlDocReporter
136
+
137
+ HtmlDocReporter(output_path).report(documentation)
138
+ else:
139
+ from tableau_inspector.report.markdown_doc_reporter import MarkdownDocReporter
140
+
141
+ MarkdownDocReporter(output_path).report(documentation)
142
+ print(f"Documentation written to {output_path}")
143
+ return 0
144
+ except Exception as error: # noqa: BLE001
145
+ _print_error(error, args.verbose)
146
+ return 2
147
+
148
+
149
+ def build_parser() -> argparse.ArgumentParser:
150
+ parser = argparse.ArgumentParser(
151
+ prog="tableau-inspector",
152
+ description="Analyze Tableau workbooks (.twb, .twbx) for common issues before publishing.",
153
+ )
154
+ parser.add_argument("-V", "--version", action="version", version=__version__)
155
+
156
+ subparsers = parser.add_subparsers(dest="command", required=True)
157
+
158
+ analyze_parser = subparsers.add_parser(
159
+ "analyze", help="Analyze a Tableau workbook and report issues"
160
+ )
161
+ analyze_parser.add_argument("file", help="Path to a .twb or .twbx workbook")
162
+ analyze_parser.add_argument("--html", action="store_true", help="Generate an HTML report")
163
+ analyze_parser.add_argument(
164
+ "--output", help="Output path for the HTML report (implies --html)"
165
+ )
166
+ analyze_parser.add_argument(
167
+ "--json",
168
+ action="store_true",
169
+ help="Print the analysis result as JSON instead of formatted console output",
170
+ )
171
+ analyze_parser.add_argument(
172
+ "--verbose", action="store_true", help="Print full error details on failure"
173
+ )
174
+ analyze_parser.set_defaults(func=_cmd_analyze)
175
+
176
+ docs_parser = subparsers.add_parser(
177
+ "docs", help="Generate structured Markdown or HTML documentation for a Tableau workbook"
178
+ )
179
+ docs_parser.add_argument("file", help="Path to a .twb or .twbx workbook")
180
+ docs_parser.add_argument(
181
+ "--html", action="store_true", help="Write HTML documentation instead of Markdown"
182
+ )
183
+ docs_parser.add_argument(
184
+ "--output", help="Output path for the generated documentation file"
185
+ )
186
+ docs_parser.add_argument(
187
+ "--json",
188
+ action="store_true",
189
+ help="Print the raw documentation JSON to stdout instead of writing a file",
190
+ )
191
+ docs_parser.add_argument(
192
+ "--verbose", action="store_true", help="Print full error details on failure"
193
+ )
194
+ docs_parser.set_defaults(func=_cmd_docs)
195
+
196
+ lineage_parser = subparsers.add_parser(
197
+ "lineage", help="Show upstream dependencies and downstream usage for a field or calculation"
198
+ )
199
+ lineage_parser.add_argument("file", help="Path to a .twb or .twbx workbook")
200
+ lineage_parser.add_argument(
201
+ "--field", help="Show lineage for a specific field or calculation"
202
+ )
203
+ lineage_parser.add_argument(
204
+ "--calculation", help="Show lineage for a specific field or calculation"
205
+ )
206
+ lineage_parser.add_argument(
207
+ "--json",
208
+ action="store_true",
209
+ help="Print the lineage result as JSON instead of formatted console output",
210
+ )
211
+ lineage_parser.add_argument(
212
+ "--verbose", action="store_true", help="Print full error details on failure"
213
+ )
214
+ lineage_parser.set_defaults(func=_cmd_lineage)
215
+
216
+ search_parser = subparsers.add_parser(
217
+ "search",
218
+ help="Search calculated fields by name and/or formula text (case-insensitive substring match)",
219
+ )
220
+ search_parser.add_argument("file", help="Path to a .twb or .twbx workbook")
221
+ search_parser.add_argument("query", help="Substring to search for")
222
+ search_parser.add_argument(
223
+ "--formula",
224
+ action="store_true",
225
+ help="Restrict matching to formula text only (excludes calculation-name matches)",
226
+ )
227
+ search_parser.add_argument(
228
+ "--json",
229
+ action="store_true",
230
+ help="Print the search result as JSON instead of formatted console output",
231
+ )
232
+ search_parser.add_argument(
233
+ "--verbose", action="store_true", help="Print full error details on failure"
234
+ )
235
+ search_parser.set_defaults(func=_cmd_search)
236
+
237
+ compare_parser = subparsers.add_parser(
238
+ "compare",
239
+ help="Compare two Tableau workbooks and report added, removed, and modified entities",
240
+ )
241
+ compare_parser.add_argument("old_file", help="Path to the baseline .twb or .twbx workbook")
242
+ compare_parser.add_argument("new_file", help="Path to the updated .twb or .twbx workbook")
243
+ compare_parser.add_argument("--html", action="store_true", help="Generate an HTML report")
244
+ compare_parser.add_argument(
245
+ "--output", help="Output path for the HTML report (implies --html)"
246
+ )
247
+ compare_parser.add_argument(
248
+ "--json",
249
+ action="store_true",
250
+ help="Print the comparison result as JSON instead of formatted console output",
251
+ )
252
+ compare_parser.add_argument(
253
+ "--verbose", action="store_true", help="Print full error details on failure"
254
+ )
255
+ compare_parser.set_defaults(func=_cmd_compare)
256
+
257
+ return parser
258
+
259
+
260
+ def main(argv: list[str] | None = None) -> int:
261
+ parser = build_parser()
262
+ args = parser.parse_args(argv)
263
+ return args.func(args)
264
+
265
+
266
+ if __name__ == "__main__":
267
+ sys.exit(main())
@@ -0,0 +1,36 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from tableau_inspector.models import CompareResult, Workbook
6
+ from tableau_inspector.parser.workbook_loader import WorkbookLoader
7
+ from tableau_inspector.parser.workbook_parser import WorkbookParser
8
+ from tableau_inspector.utils.timestamps import iso_timestamp
9
+ from tableau_inspector.utils.version import read_tool_version
10
+ from .build_compare import CompareMeta, build_compare_result
11
+
12
+ __all__ = ["compare_workbooks", "build_compare_result", "CompareMeta"]
13
+
14
+
15
+ def _load_workbook(file_path: str) -> Workbook:
16
+ loader = WorkbookLoader()
17
+ loader.load(file_path)
18
+ xml = loader.get_xml()
19
+ workbook_name = os.path.splitext(os.path.basename(file_path))[0]
20
+ return WorkbookParser().parse(xml, workbook_name)
21
+
22
+
23
+ def compare_workbooks(old_file_path: str, new_file_path: str) -> CompareResult:
24
+ old_workbook = _load_workbook(old_file_path)
25
+ new_workbook = _load_workbook(new_file_path)
26
+
27
+ return build_compare_result(
28
+ old_workbook,
29
+ new_workbook,
30
+ CompareMeta(
31
+ old_file_path=old_file_path,
32
+ new_file_path=new_file_path,
33
+ generated_at=iso_timestamp(),
34
+ tool_version=read_tool_version(),
35
+ ),
36
+ )