From b9e38278671f04b8840b8749194af56b05cba660 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Mon, 11 May 2020 22:43:44 +0200 Subject: [PATCH] use pkg_resources This change uses if no path for e capabilities-file is supplied a temporary file created by pkg_resources, which should be more robust than directly accessing the file. (This failed sometimes, for example in zipped distributions or uncommon structures) --- doc/requirements.txt | 1 + setup.cfg | 1 + src/escpos/capabilities.py | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index 89cd833..0908f3d 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -3,6 +3,7 @@ Pillow>=2.0 qrcode>=4.0 pyserial sphinx-rtd-theme +setuptools setuptools-scm docutils>=0.12 python-barcode>=0.11.0,<1 diff --git a/setup.cfg b/setup.cfg index 10e0396..6d6ff7f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,6 +40,7 @@ install_requires = qrcode>=4.0 pyserial python-barcode>=0.9.1,<1 + setuptools six appdirs PyYAML diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index c4b6ab5..2c9c909 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -1,5 +1,6 @@ import re from os import environ, path +import pkg_resources import pickle import logging import time @@ -15,9 +16,9 @@ logger = logging.getLogger(__name__) pickle_dir = environ.get('ESCPOS_CAPABILITIES_PICKLE_DIR', gettempdir()) pickle_path = path.join(pickle_dir, '{v}.capabilities.pickle'.format(v=platform.python_version())) -capabilities_path = environ.get( - 'ESCPOS_CAPABILITIES_FILE', - path.join(path.dirname(__file__), 'capabilities.json')) +# get a temporary file from pkg_resources if no file is specified in env +capabilities_path = environ.get('ESCPOS_CAPABILITIES_FILE', + pkg_resources.resource_filename(__name__, 'capabilities.json')) # Load external printer database t0 = time.time()