Skip to content

Commit 2b9f578

Browse files
committed
feat!: replace generate_report with generate_report_string
Instead of writing directly the report to a file, we now return the full string. This leaves more flexibility, for example to write the report directly on a remote file system (like hdfs or s3).
1 parent 15f5628 commit 2b9f578

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ inside the HTML file, and write the result as a new HTML page at the specified l
112112

113113
## Changelog
114114

115+
### v0.2.0
116+
117+
Breaking Changes:
118+
- replaced method `generate_report` with `generate_report_string`: instead of writing directly the report to a file,
119+
we now return the full string. This leaves more flexibility, for example to write the report directly on a remote
120+
file system (like hdfs or s3).
121+
115122
### v0.1.3
116123

117124
- Fixed incorrect packaging from v0.1.1 and v0.1.2

data_diff_viewer/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
__version__ = "0.1.3"
22

33
from data_diff_viewer.diff_summary import DiffSummary
4-
from data_diff_viewer.package import generate_report
4+
from data_diff_viewer.package import generate_report_string
55
from data_diff_viewer.utils import _ref
66

77
PROJECT_NAME = "data-diff-viewer"
88
PACKAGE_NAME = "data_diff_viewer"
99

1010
_ref(DiffSummary)
11-
_ref(generate_report)
11+
_ref(generate_report_string)

data_diff_viewer/package.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ def _write_duck_db(temp_dir: Path, data_diff_path: Path) -> None:
8181
conn.close()
8282

8383

84-
def generate_report(
84+
def generate_report_string(
8585
report_title: str,
8686
diff_summary: DiffSummary,
8787
temp_dir: Path,
8888
data_diff_path: Path,
89-
output_path: Path,
90-
encoding: str,
91-
) -> None:
92-
"""Generate a standalone HTML report to visualize a data-diff.
89+
) -> str:
90+
"""Generate a string containing a standalone HTML report to visualize a data-diff.
91+
92+
This string must be written to a file to be used.
9393
9494
The HTML report is self-contained: it can be opened as local files with a browser,
9595
and works even without any internet connection
@@ -133,14 +133,13 @@ def generate_report(
133133
diff_summary: A DiffSummary object containing all the metadata of the data-diff
134134
temp_dir: The Path to a temporary directory
135135
data_diff_path: The Path to a json file containing the data-diff results.
136-
output_path: The Path of the HTML file to generate
137-
encoding: The encoding to use to write the HTML file. UTF-8 is recommended.
136+
137+
Returns:
138+
a string containing the HTML report. This string must be written to a file to be used.
138139
"""
139140
_write_report_files(report_title, diff_summary, temp_dir)
140141
_write_duck_db(temp_dir, data_diff_path)
141142
base64_report = encode_file_to_base64_string(_get_db_path(temp_dir))
142-
143-
with output_path.open("w", encoding=encoding) as output:
144-
report_template = read_resource("templates/diff_report.html")
145-
report = report_template.replace("{{db_base64}}", base64_report)
146-
output.write(report)
143+
report_template = read_resource("templates/diff_report.html")
144+
report = report_template.replace("{{db_base64}}", base64_report)
145+
return report

0 commit comments

Comments
 (0)