Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update weasyprint to 55.0 #802

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM ubuntu:focal
# deadsnakes has Python3.6 for focal but not jammy
FROM ubuntu:latest
LABEL maintainer="Kesara Rathnayake <kesara@staff.ietf.org>"

ENV DEBIAN_FRONTEND noninteractive
Expand All @@ -10,41 +9,43 @@ RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update --fix-missing

# Install dependencies
RUN apt-get install -y \
libcairo2 \
libcairo2-dev \
RUN apt-get install -y --fix-missing \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libssl-dev \
fontconfig \
libharfbuzz0b \
libpangoft2-1.0-0 \
pkg-config \
libxml2-utils \
groff \
wget \
unzip \
locales

# Set locale
RUN locale-gen en_US.UTF-8

# Install Pythons
# From the OS - Python 3.8
# From the OS - Python 3.10
RUN apt-get install -y \
python3 \
python3-dev \
python3-pip
python3.10 \
python3.10-dev \
python3-pip \
python3.10-distutils

# From deadsnakes
RUN apt-get install -y \
python3.7 \
python3.7-dev \
python3.7-distutils \
python3.8 \
python3.8-dev \
python3.8-distutils \
python3.9 \
python3.9-dev \
python3.9-distutils \
python3.10 \
python3.10-dev \
python3.10-distutils
python3.9-distutils

# Update pip
RUN pip install --upgrade pip

# Instal tox
RUN pip3 install tox
Expand All @@ -70,11 +71,10 @@ COPY requirements.txt .

# build xml2rfc
RUN pip3 install -r requirements.txt \
"weasyprint==52.5" \
"pycairo<1.20" \
"weasyprint>=53.0" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be >=55 now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why >= 55? weasyprint is actually at 56 now upstream, but there's no good reason to increase the version if you don't actually need the newer version.

Put another way: please do not gratuitously increase the minimum version needed. if 53.0 works as well, there's no reason to have the elevated version requirements.

If there is a specific reason that 55 is necessary, then of course make it required, but otherwise, you do the ecosystem a favor by indicating the flexibility explicitly.

Copy link
Member Author

@kesara kesara Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any specific reason for using 55 or 56 at this point.
So I'm happy to keep weasyprint>=53.0 for wider compatibility.
But services like author tools will start using the latest available version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that sounds entirely reasonable. the specified version ranges are constraints, but of course any specific instance will choose whatever version of the package it wants as long as it's within the constraints.

decorator \
"dict2xml==1.6" \
"pypdf2<1.27.0"
dict2xml \
"pypdf2>=2.6.0"
RUN make install

# cleanup
Expand Down
2 changes: 0 additions & 2 deletions configtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import sys
import warnings

warnings.filterwarnings("ignore", message='There are known rendering problems and missing features with cairo < 1.15.4')

errors = 0

sys.stderr.write("Checking installation of test and development packages:\n")
for (pname, mname) in [
('decorator', 'decorator'),
('dict2xml', 'dict2xml'),
('pycairo', 'cairo'),
('PyPDF2', 'PyPDF2'),
]:
try:
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def norm(t):
self.assertIn(t, text)

def test_included_fonts(self):
if xml2rfc.HAVE_WEASYPRINT and xml2rfc.HAVE_PYCAIRO and xml2rfc.HAVE_CAIRO and xml2rfc.HAVE_PANGO:
if xml2rfc.HAVE_WEASYPRINT and xml2rfc.HAVE_PANGO:
font_families = set([ f.text for f in self.pdfxml.xpath('.//FontFamily') ])
for script in self.root.get('scripts').split(','):
family = xml2rfc.util.fonts.get_noto_serif_family_for_script(script)
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ allowlist_externals =
deps =
-rrequirements.txt
decorator
dict2xml==1.7
pycairo<1.20
pypdf2<1.27.0
weasyprint<53
dict2xml
pypdf2>=2.6.0
weasyprint>=53.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another place for >=55.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, i recommend keeping the minimum at 53 (where there is no cairo) unless you have a clear reason to believe that it requires 55.

17 changes: 2 additions & 15 deletions xml2rfc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,7 @@
weasyprint = False
HAVE_WEASYPRINT = False
try:
import cairo
HAVE_PYCAIRO = True
except (ImportError, OSError):
cairo = False
HAVE_PYCAIRO = False
try:
from weasyprint.text import cairo
HAVE_CAIRO = True
CAIRO_VERSION = cairo.cairo_version()
except (ImportError, OSError):
HAVE_CAIRO = False
CAIRO_VERSION = None
try:
from weasyprint.text import pango
from weasyprint.text.ffi import pango
HAVE_PANGO = True
PANGO_VERSION = pango.pango_version
except (ImportError, OSError, AttributeError):
Expand All @@ -59,7 +46,7 @@
def get_versions():
import sys
versions = []
extras = set(['pycairo', 'weasyprint'])
extras = set(['weasyprint'])
try:
import pkg_resources
this = pkg_resources.working_set.by_key[NAME]
Expand Down
29 changes: 5 additions & 24 deletions xml2rfc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def get_missing_pdf_libs():
missing = ""
if not xml2rfc.HAVE_WEASYPRINT:
missing += "\nCould not import weasyprint"
if not xml2rfc.HAVE_PYCAIRO:
missing += "\nCould not import pycairo"
if not xml2rfc.HAVE_CAIRO:
missing += "\nCould not find the cairo lib"
if not xml2rfc.HAVE_PANGO:
missing += "\nCould not find the pango lib"
return missing
Expand Down Expand Up @@ -84,29 +80,14 @@ def get_pdf_help(missing_libs=""):
In order to generate PDFs, xml2rfc uses the WeasyPrint library, which
depends on external libaries that must be installed as native packages.

1. First, install the Cairo, Pango, and GDK-PixBuf library files on your
1. First, install the Pango, and other required libraries on your
system. See installation instructions on the WeasyPrint Docs:

https://weasyprint.readthedocs.io/en/stable/install.html
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html

(Python 3 is not needed if your system Python is 2.7, though).
2. Next, install weasyprint python modules using pip.


2. Next, install the pycairo and weasyprint python modules using pip.
Depending on your system, you may need to use 'sudo' or install in
kesara marked this conversation as resolved.
Show resolved Hide resolved
user-specific directories, using the --user switch. On OS X in
particular, you may also need to install a newer version of setuptools
using --user before weasyprint can be installed. If you install with
the --user switch, you may need to also set PYTHONPATH, e.g.,

PYTHONPATH=/Users/username/Library/Python/2.7/lib/python/site-packages

for Python 2.7.

The basic pip commands (modify as needed according to the text above)
are:

pip install 'pycairo>=1.18' 'weasyprint<=0.42.3'
pip install 'weasyprint>=53.0'


3. Finally, install the full Noto Font and Roboto Mono packages:
Expand Down Expand Up @@ -212,7 +193,7 @@ def main():
help='outputs formatted HTML to file')
formatgroup.add_argument('--nroff', action='store_true',
help='outputs formatted nroff to file (only v2 input)')
if xml2rfc.HAVE_CAIRO and xml2rfc.HAVE_PANGO:
if xml2rfc.HAVE_PANGO:
formatgroup.add_argument('--pdf', action='store_true',
help='outputs formatted PDF to file')
else:
Expand Down
13 changes: 11 additions & 2 deletions xml2rfc/writers/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import warnings

warnings.filterwarnings("ignore", message='There are known rendering problems with Cairo <= 1.14.0')
warnings.filterwarnings("ignore", message='There are known rendering problems and missing features with cairo < 1.15.4')
warnings.filterwarnings("ignore", message='@font-face support needs Pango >= 1.38')

try:
Expand Down Expand Up @@ -44,6 +42,8 @@ def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
return

logging.basicConfig(level=logging.INFO)

# Weasyprint logger
wplogger = logging.getLogger('weasyprint')
if self.options.quiet:
wplogger.setLevel(logging.CRITICAL)
Expand All @@ -52,6 +52,15 @@ def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
else:
wplogger.setLevel(logging.ERROR)

# fontTools logger
ftlogger = logging.getLogger('fontTools')
if self.options.quiet:
ftlogger.setLevel(logging.CRITICAL)
elif self.options.verbose:
ftlogger.setLevel(logging.WARNING)
else:
ftlogger.setLevel(logging.ERROR)

def pdf(self):
if not weasyprint:
return None
Expand Down