Skip to content

Commit

Permalink
hooks: add hook for z3c.rml
Browse files Browse the repository at this point in the history
Add a hook for `z3c.rml` that collects the required subset of TTF
fonts bundled with `reportlab` package. The latter might be used
without its bundled fonts, and some of them have restrictive
license (e.g., DarkGarden), so instead of having a hook for
`reportlab` that collects all fonts fron `reportlab.fonts`,
we collect the required subset (Bitstream Vera fonts) in the
`z3c.rml` hook.
  • Loading branch information
rokm committed Dec 20, 2023
1 parent 937ca15 commit 7916492
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/674.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a hook for ``z3c.rml`` that collects the required subset of Bitstream
Vera TTF fonts from the ``reportlab`` package.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ gmsh==4.11.1
sspilib==0.1.0
rlp==4.0.0
eth-rlp==1.0.0
z3c.rml==4.4.0

# ------------------- Platform (OS) specifics

Expand Down
25 changes: 25 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-z3c.rml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_data_files

# `z3c.rml` uses Bitstream Vera TTF fonts from the `reportlab` package. As that package can be used without the bundled
# fonts and as some of the bundled fonts have restrictive license (e.g., DarkGarden), we collect the required subset
# of fonts here, instead of collecting them all in a hook for `reportlab`.
datas = collect_data_files(
"reportlab",
includes=[
"fonts/00readme.txt",
"fonts/bitstream-vera-license.txt",
"fonts/Vera*.ttf",
],
)
28 changes: 28 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,3 +1917,31 @@ def test_eth_rlp(pyi_builder):
pyi_builder.test_source("""
import eth_rlp
""")


@importorskip('z3c.rml')
def test_z3c_rml_rml2pdf(pyi_builder):
pyi_builder.test_source("""
from z3c.rml import rml2pdf
rml = '''
<!DOCTYPE document SYSTEM "rml.dtd" >
<document filename="test.pdf">
<template showBoundary="1">
<!--Debugging is now turned on, frame outlines -->
<!--will appear on the page -->
<pageTemplate id="main">
<!-- two frames are defined here: -->
<frame id="first" x1="100" y1="400" width="150" height="200" />
<frame id="second" x1="300" y1="400" width="150" height="200" />
</pageTemplate>
</template>
<stylesheet><!-- still empty...--></stylesheet>
<story>
<para>Welcome to RML.</para>
</story>
</document>
'''
pdf_bytes = rml2pdf.parseString(rml)
""")

0 comments on commit 7916492

Please sign in to comment.