Fixes from ci (#533)

* break line

* remove unused imports

* remove unused os import

* make flake8 more strict

* configure flake for black

* fix action

* use importlib_resources

* rename deprecated methods
This commit is contained in:
Patrick Kanzler 2023-07-21 23:03:46 +02:00 committed by GitHub
parent cb3f4e856b
commit e9e8b10582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 15 deletions

View File

@ -33,7 +33,7 @@ jobs:
- name: Lint with flake8 - name: Lint with flake8
run: | run: |
# stop the build if there are Python syntax errors or undefined names # 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 # 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 flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with tox - name: Test with tox

View File

@ -9,3 +9,4 @@ docutils>=0.12
sphinxcontrib-spelling>=7.2.0 sphinxcontrib-spelling>=7.2.0
python-barcode>=0.11.0,<1 python-barcode>=0.11.0,<1
importlib-metadata importlib-metadata
importlib_resources

View File

@ -1,8 +1,5 @@
import escpos from escpos.printer import CupsPrinter
from escpos.printer import * from flask import Flask
from flask import Flask, jsonify, request, redirect, session, url_for
import sys
from io import BytesIO
# Initialize Flask app # Initialize Flask app
app = Flask(__name__) app = Flask(__name__)

View File

@ -48,6 +48,7 @@ install_requires =
argparse argparse
argcomplete argcomplete
future future
importlib_resources
setup_requires = setuptools_scm setup_requires = setuptools_scm
tests_require = tests_require =
jaconv jaconv
@ -69,4 +70,5 @@ with-doctest=1
[flake8] [flake8]
exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py
max-line-length = 120 max-line-length = 120
extend-ignore = E203, W503
# future-imports = absolute_import, division, print_function, unicode_literals # we are not there yet # future-imports = absolute_import, division, print_function, unicode_literals # we are not there yet

View File

@ -1,13 +1,15 @@
import re import re
from os import environ, path from os import environ, path
import pkg_resources import atexit
import pickle import pickle
import logging import logging
import time import time
import importlib_resources
import six import six
import yaml import yaml
from contextlib import ExitStack
from tempfile import mkdtemp from tempfile import mkdtemp
import platform import platform
@ -20,10 +22,13 @@ pickle_dir = environ.get("ESCPOS_CAPABILITIES_PICKLE_DIR", mkdtemp())
pickle_path = path.join( pickle_path = path.join(
pickle_dir, "{v}.capabilities.pickle".format(v=platform.python_version()) 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( capabilities_path = environ.get(
"ESCPOS_CAPABILITIES_FILE", "ESCPOS_CAPABILITIES_FILE",
pkg_resources.resource_filename(__name__, "capabilities.json"), file_manager.enter_context(importlib_resources.as_file(ref)),
) )
# Load external printer database # Load external printer database

View File

@ -20,8 +20,6 @@ from re import match as re_match
import barcode import barcode
from barcode.writer import ImageWriter from barcode.writer import ImageWriter
import os
from .constants import ( from .constants import (
ESC, ESC,
GS, GS,
@ -84,7 +82,7 @@ from .magicencode import MagicEncode
from abc import ABCMeta, abstractmethod # abstract base class support from abc import ABCMeta, abstractmethod # abstract base class support
from escpos.image import EscposImage 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, # Remove special characters and whitespaces of the supported barcode names,
@ -510,7 +508,8 @@ class Escpos(object):
.. note:: .. note::
Get all supported formats at: Get all supported formats at:
- Hardware: :py:const:`~escpos.constants.BARCODE_FORMATS` - Hardware: :py:const:`~escpos.constants.BARCODE_FORMATS`
- Software: `Python barcode documentation <https://python-barcode.readthedocs.io/en/stable/supported-formats.html>`_ - Software:
`Python barcode documentation <https://python-barcode.readthedocs.io/en/stable/supported-formats.html>`_
""" """
hw_modes = ["barcodeA", "barcodeB"] hw_modes = ["barcodeA", "barcodeB"]
sw_modes = ["graphics", "bitImageColumn", "bitImageRaster"] sw_modes = ["graphics", "bitImageColumn", "bitImageRaster"]

View File

@ -40,7 +40,7 @@ class TestCLI:
"""Remove config file""" """Remove config file"""
os.remove(CONFIGFILE) os.remove(CONFIGFILE)
def setup(self): def setup_method(self):
"""Create a file to print to and set up env""" """Create a file to print to and set up env"""
self.env = None self.env = None
self.default_args = None self.default_args = None
@ -62,7 +62,7 @@ class TestCLI:
finally: finally:
fhandle.close() fhandle.close()
def teardown(self): def teardown_method(self):
"""Destroy printer file and env""" """Destroy printer file and env"""
os.remove(DEVFILE) os.remove(DEVFILE)
self.env.clear() self.env.clear()