diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 7ab7fd8..3351f5e 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -33,7 +33,7 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --select=E,F,W --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with tox diff --git a/doc/requirements.txt b/doc/requirements.txt index 7e57f2a..d212805 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -9,3 +9,4 @@ docutils>=0.12 sphinxcontrib-spelling>=7.2.0 python-barcode>=0.11.0,<1 importlib-metadata +importlib_resources diff --git a/examples/docker-flask/app.py b/examples/docker-flask/app.py index 7febda9..dc66b3f 100644 --- a/examples/docker-flask/app.py +++ b/examples/docker-flask/app.py @@ -1,8 +1,5 @@ -import escpos -from escpos.printer import * -from flask import Flask, jsonify, request, redirect, session, url_for -import sys -from io import BytesIO +from escpos.printer import CupsPrinter +from flask import Flask # Initialize Flask app app = Flask(__name__) diff --git a/setup.cfg b/setup.cfg index 96c029c..1722cbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,6 +48,7 @@ install_requires = argparse argcomplete future + importlib_resources setup_requires = setuptools_scm tests_require = jaconv @@ -69,4 +70,5 @@ with-doctest=1 [flake8] exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py max-line-length = 120 +extend-ignore = E203, W503 # future-imports = absolute_import, division, print_function, unicode_literals # we are not there yet diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index 4b31de8..7294717 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -1,13 +1,15 @@ import re from os import environ, path -import pkg_resources +import atexit import pickle import logging import time +import importlib_resources import six import yaml +from contextlib import ExitStack from tempfile import mkdtemp import platform @@ -20,10 +22,13 @@ pickle_dir = environ.get("ESCPOS_CAPABILITIES_PICKLE_DIR", mkdtemp()) pickle_path = path.join( pickle_dir, "{v}.capabilities.pickle".format(v=platform.python_version()) ) -# get a temporary file from pkg_resources if no file is specified in env +# get a temporary file from importlib_resources if no file is specified in env +file_manager = ExitStack() +atexit.register(file_manager.close) +ref = importlib_resources.files(__name__) / "capabilities.json" capabilities_path = environ.get( "ESCPOS_CAPABILITIES_FILE", - pkg_resources.resource_filename(__name__, "capabilities.json"), + file_manager.enter_context(importlib_resources.as_file(ref)), ) # Load external printer database diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 22aef57..fbb3618 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -20,8 +20,6 @@ from re import match as re_match import barcode from barcode.writer import ImageWriter -import os - from .constants import ( ESC, GS, @@ -84,7 +82,7 @@ from .magicencode import MagicEncode from abc import ABCMeta, abstractmethod # abstract base class support from escpos.image import EscposImage -from escpos.capabilities import get_profile, BARCODE_B +from escpos.capabilities import get_profile # Remove special characters and whitespaces of the supported barcode names, @@ -510,7 +508,8 @@ class Escpos(object): .. note:: Get all supported formats at: - Hardware: :py:const:`~escpos.constants.BARCODE_FORMATS` - - Software: `Python barcode documentation `_ + - Software: + `Python barcode documentation `_ """ hw_modes = ["barcodeA", "barcodeB"] sw_modes = ["graphics", "bitImageColumn", "bitImageRaster"] diff --git a/test/test_cli.py b/test/test_cli.py index 09e7629..fc6e02e 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -40,7 +40,7 @@ class TestCLI: """Remove config file""" os.remove(CONFIGFILE) - def setup(self): + def setup_method(self): """Create a file to print to and set up env""" self.env = None self.default_args = None @@ -62,7 +62,7 @@ class TestCLI: finally: fhandle.close() - def teardown(self): + def teardown_method(self): """Destroy printer file and env""" os.remove(DEVFILE) self.env.clear()