1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-09-17 15:37:34 +03:00

Use pkgutil instead of manual ROOT to load data

It avoids useless code and should work with all the packagers.
This commit is contained in:
Guillaume Ayoub 2021-04-27 22:11:27 +02:00
parent 6069fcd61a
commit c76e1a3ba6
2 changed files with 5 additions and 17 deletions

View File

@ -10,26 +10,12 @@
"""
import contextlib
import os
import sys
from pathlib import Path
import cssselect2
import html5lib
import tinycss2
if hasattr(sys, 'frozen'): # pragma: no cover
if hasattr(sys, '_MEIPASS'):
# Frozen with PyInstaller
# See https://github.com/Kozea/WeasyPrint/pull/540
ROOT = Path(sys._MEIPASS) / 'weasyprint'
else:
# Frozen with something else (py2exe, etc.)
# See https://github.com/Kozea/WeasyPrint/pull/269
ROOT = Path(os.path.dirname(sys.executable))
else:
ROOT = Path(os.path.dirname(__file__))
VERSION = __version__ = '53.0b1'
__all__ = [

View File

@ -12,11 +12,12 @@
"""
import logging
import pkgutil
import re
from urllib.parse import urljoin
from xml.etree.ElementTree import tostring
from . import CSS, ROOT
from . import CSS
from .css import get_child_text
from .css.counters import CounterStyle
from .formatting_structure import boxes
@ -29,9 +30,10 @@ LOGGER.setLevel(logging.ERROR)
HTML5_UA_COUNTER_STYLE = CounterStyle()
HTML5_UA_STYLESHEET = CSS(
filename=(ROOT / 'css' / 'html5_ua.css'),
string=pkgutil.get_data('weasyprint', 'css/html5_ua.css').decode('utf-8'),
counter_style=HTML5_UA_COUNTER_STYLE)
HTML5_PH_STYLESHEET = CSS(filename=(ROOT / 'css' / 'html5_ph.css'))
HTML5_PH_STYLESHEET = CSS(
string=pkgutil.get_data('weasyprint', 'css/html5_ph.css').decode('utf-8'))
LOGGER.setLevel(level)