From f44ae6d85f1da675ab4f88de7f9979d8bfd629c7 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 25 Sep 2015 11:30:56 +1000 Subject: [PATCH 1/2] Add support for use when frozen Use appropriate path to find resource when frozen (using py2exe etc.) --- weasyprint/html.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weasyprint/html.py b/weasyprint/html.py index 2d67fccf9..0913848e6 100644 --- a/weasyprint/html.py +++ b/weasyprint/html.py @@ -19,6 +19,7 @@ from __future__ import division, unicode_literals import os.path import logging +import sys import re from .css import get_child_text @@ -33,8 +34,8 @@ level = LOGGER.level LOGGER.setLevel(logging.ERROR) -HTML5_UA_STYLESHEET = CSS( - filename=os.path.join(os.path.dirname(__file__), 'css', 'html5_ua.css')) +root = os.path.dirname(sys.executable) if hasattr(sys, "frozen") else os.path.dirname(__file__) +HTML5_UA_STYLESHEET = CSS(filename= os.path.join(root, 'css', 'html5_ua.css')) LOGGER.setLevel(level) From a145bd12f66bd5711e8b11e63e52674f55a4366b Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Mon, 28 Sep 2015 14:08:41 +1000 Subject: [PATCH 2/2] Fix formatting to satisfy flake8 --- weasyprint/html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/weasyprint/html.py b/weasyprint/html.py index 0913848e6..617eedb91 100644 --- a/weasyprint/html.py +++ b/weasyprint/html.py @@ -34,8 +34,11 @@ level = LOGGER.level LOGGER.setLevel(logging.ERROR) -root = os.path.dirname(sys.executable) if hasattr(sys, "frozen") else os.path.dirname(__file__) -HTML5_UA_STYLESHEET = CSS(filename= os.path.join(root, 'css', 'html5_ua.css')) +if hasattr(sys, "frozen"): + root = os.path.dirname(sys.executable) +else: + root = os.path.dirname(__file__) +HTML5_UA_STYLESHEET = CSS(filename=os.path.join(root, 'css', 'html5_ua.css')) LOGGER.setLevel(level)