Skip to content

Commit 4d1d6a0

Browse files
selah-aweandreverence[bot]selah-aweandreverence[bot]
andauthored
deps: make xhtml2pdf optional (#5)
Co-authored-by: selah-aweandreverence[bot] <2972811+selah-aweandreverence[bot]@users.noreply.github.com>
1 parent 255296b commit 4d1d6a0

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ requests>=2.32.4,<3
1515
rollbar>=0.15.1,<2
1616
stripe>=12.3.0,<13
1717
user-agents==2.2.0
18-
xhtml2pdf==0.2.17

utils/pdf_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,17 @@ def render_to_pdf_response_pisa(template_name, context_dict):
119119
https://github.com/xhtml2pdf/xhtml2pdf/issues/44
120120
121121
PyPI: https://pypi.python.org/pypi/pisa/
122+
123+
Note: xhtml2pdf is treated as an optional dependency because most HTK
124+
consumers do not use this legacy code path.
122125
"""
123126
from six.moves import cStringIO as StringIO
124-
from xhtml2pdf import pisa
127+
try:
128+
from xhtml2pdf import pisa
129+
except ImportError as exc:
130+
raise RuntimeError(
131+
'xhtml2pdf is not installed. Install it to use render_to_pdf_response_pisa().'
132+
) from exc
125133
html = generate_html_from_template(template_name, context_dict)
126134
result = StringIO()
127135
pdf = pisa.pisaDocument(StringIO(html.encode('utf-8')), result)

0 commit comments

Comments
 (0)