Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/black.yml

This file was deleted.

8 changes: 1 addition & 7 deletions .github/workflows/pythonpackage-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest tox tox-gh-actions
pip install pytest tox tox-gh-actions
If (Test-Path .\requirements.txt) { pip install -r .\requirements.txt }
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
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
run: |
tox
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,8 @@ jobs:
sudo apt-get update
sudo apt-get install -y graphviz libenchant-2-2 gcc libcups2-dev python3-dev xindy
python -m pip install --upgrade pip
pip install flake8 pytest tox tox-gh-actions
pip install pytest tox tox-gh-actions
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Check sorting of imports
uses: isort/isort-action@master
with:
requirementsFiles: "requirements.txt doc/requirements.txt"
sortPaths: "./doc ./src ./examples ./test ./setup.py"
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
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
run: |
tox
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Style

on: [push, pull_request]

jobs:
style:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Ruff
uses: astral-sh/ruff-action@v3
- name: Ruff check
run: ruff check --fix --output-format=github
- name: Ruff format
run: ruff format
1 change: 1 addition & 0 deletions examples/barcodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example for printing barcodes."""

from escpos.printer import Usb

# Adapt to your needs
Expand Down
1 change: 0 additions & 1 deletion examples/codepage_tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Prints code page tables."""


import sys

from escpos import printer
Expand Down
2 changes: 1 addition & 1 deletion examples/docker-flask/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Example for a flask application."""
from flask import Flask

from escpos.printer import CupsPrinter
from flask import Flask

# Initialize Flask app
app = Flask(__name__)
Expand Down
1 change: 1 addition & 0 deletions examples/qr_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Print example QR codes."""

import sys

from escpos.printer import Usb
Expand Down
1 change: 1 addition & 0 deletions examples/software_barcode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example file for software barcodes."""

from escpos.printer import Usb

# Adapt to your needs
Expand Down
2 changes: 1 addition & 1 deletion examples/software_columns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Example for software_columns: Print text arranged into columns."""
"""Example for software_columns: Print text arranged into columns."""

from escpos import printer

Expand Down
1 change: 0 additions & 1 deletion examples/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Check out his github: https://github.com/AdamWhitcroft/climacons
"""


import calendar
import json
import os
Expand Down
38 changes: 32 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[tool.black]
extend-exclude = 'capabilities-data'

[tool.isort]
profile = "black"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--doctest-modules --cov escpos --cov-report=xml"
Expand All @@ -25,3 +19,35 @@ module = ["pytest",
"win32print"
]
ignore_missing_imports = true


[tool.ruff]
extend-exclude = [
".github",
"__pycache__",
"doc/conf.py",
"build",
"capabilities-data",
"test",
"src/escpos/constants.py",
]
line-length = 120
show-fixes = true
src = ["."]
target-version = "py38"


[tool.ruff.format]
line-ending = "lf"


[tool.ruff.lint]
select = ["E", "F", "W", "D", "I"]


[tool.ruff.lint.pydocstyle]
convention = "pep257"


[tool.ruff.lint.mccabe]
max-complexity = 10
7 changes: 1 addition & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ tests_require =
scripttest
mock
hypothesis>=6.83
flake8
sphinxcontrib-spelling>=8.0.0
ruff

[options.extras_require]
usb =
Expand All @@ -74,8 +74,3 @@ all =
pyserial
pycups; platform_system!='Windows'
pywin32; platform_system=='Windows'

[flake8]
exclude = .git,.venv,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py
max-line-length = 120
extend-ignore = E203, W503
7 changes: 3 additions & 4 deletions src/escpos/capabilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Handler for capabilities data."""

import atexit
import logging
import pickle
Expand Down Expand Up @@ -74,9 +75,7 @@
},
}
print(
"Created a minimal backup profile, "
"many functionalities of the library will not work:\n"
f"{CAPABILITIES}"
f"Created a minimal backup profile, many functionalities of the library will not work:\n{CAPABILITIES}"
)
pickle.dump(CAPABILITIES, pp, protocol=2)

Expand Down Expand Up @@ -111,7 +110,7 @@ def get_font(self, font) -> int:
Makes sure that the requested `font` is valid.
"""
font = {"a": 0, "b": 1}.get(font, font)
if not str(font) in self.fonts:
if str(font) not in self.fonts:
raise NotSupported(f'"{font}" is not a valid font in the current profile')
return font

Expand Down
43 changes: 11 additions & 32 deletions src/escpos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
pass # noqa
import sys

from . import config, escpos
from . import config, escpos, version
from . import printer as escpos_printer_module
from . import version


# Must be defined before it's used in DEMO_FUNCTIONS
Expand Down Expand Up @@ -490,32 +489,16 @@ def str_to_bool(string: str) -> bool:
def print_extended_information() -> None:
"""Print diagnostic information for bug reports."""
print(f"* python-escpos version: `{version.version}`")
print(
f"* python version: `{platform.python_implementation()} v{platform.python_version()}`"
)
print(f"* python version: `{platform.python_implementation()} v{platform.python_version()}`")
print(f"* platform: `{platform.platform()}`")
print(
f"* printer driver `USB` is usable: `{escpos_printer_module.Usb.is_usable()}`"
)
print(
f"* printer driver `File` is usable: `{escpos_printer_module.File.is_usable()}`"
)
print(
f"* printer driver `Network` is usable: `{escpos_printer_module.Network.is_usable()}`"
)
print(
f"* printer driver `Serial` is usable: `{escpos_printer_module.Serial.is_usable()}`"
)
print(f"* printer driver `USB` is usable: `{escpos_printer_module.Usb.is_usable()}`")
print(f"* printer driver `File` is usable: `{escpos_printer_module.File.is_usable()}`")
print(f"* printer driver `Network` is usable: `{escpos_printer_module.Network.is_usable()}`")
print(f"* printer driver `Serial` is usable: `{escpos_printer_module.Serial.is_usable()}`")
print(f"* printer driver `LP` is usable: `{escpos_printer_module.LP.is_usable()}`")
print(
f"* printer driver `Dummy` is usable: `{escpos_printer_module.Dummy.is_usable()}`"
)
print(
f"* printer driver `CupsPrinter` is usable: `{escpos_printer_module.CupsPrinter.is_usable()}`"
)
print(
f"* printer driver `Win32Raw` is usable: `{escpos_printer_module.Win32Raw.is_usable()}`"
)
print(f"* printer driver `Dummy` is usable: `{escpos_printer_module.Dummy.is_usable()}`")
print(f"* printer driver `CupsPrinter` is usable: `{escpos_printer_module.CupsPrinter.is_usable()}`")
print(f"* printer driver `Win32Raw` is usable: `{escpos_printer_module.Win32Raw.is_usable()}`")


def generate_parser() -> argparse.ArgumentParser:
Expand Down Expand Up @@ -553,9 +536,7 @@ def generate_parser() -> argparse.ArgumentParser:
parser_command.add_argument(*option_strings, **argument)

# Build any custom arguments
parser_command_demo = command_subparsers.add_parser(
"demo", help="Demonstrates various functions"
)
parser_command_demo = command_subparsers.add_parser("demo", help="Demonstrates various functions")
parser_command_demo.set_defaults(func="demo")
demo_group = parser_command_demo.add_mutually_exclusive_group()
demo_group.add_argument(
Expand Down Expand Up @@ -662,9 +643,7 @@ def demo(printer: escpos.Escpos, **kwargs) -> None:
for demo_choice in kwargs.keys():
command = getattr(
printer,
demo_choice.replace("barcodes_a", "barcode").replace(
"barcodes_b", "barcode"
),
demo_choice.replace("barcodes_a", "barcode").replace("barcodes_b", "barcode"),
)
for params in DEMO_FUNCTIONS[demo_choice]:
command(**params)
Expand Down
1 change: 1 addition & 0 deletions src/escpos/codepages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper module for code page handling."""

from .capabilities import CAPABILITIES


Expand Down
13 changes: 4 additions & 9 deletions src/escpos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This module contains the implementations of abstract base class :py:class:`Config`.
"""

import os
import pathlib

Expand Down Expand Up @@ -54,9 +55,7 @@ def load(self, config_path=None):
self._reset_config()

if not config_path:
config_path = os.path.join(
platformdirs.user_config_dir(self._app_name), self._config_file
)
config_path = os.path.join(platformdirs.user_config_dir(self._app_name), self._config_file)
if isinstance(config_path, pathlib.Path):
# store string if posixpath
config_path = config_path.as_posix()
Expand All @@ -68,9 +67,7 @@ def load(self, config_path=None):
with open(config_path, "rb") as config_file:
config = yaml.safe_load(config_file)
except EnvironmentError:
raise exceptions.ConfigNotFoundError(
f"Couldn't read config at {config_path}"
)
raise exceptions.ConfigNotFoundError(f"Couldn't read config at {config_path}")
except yaml.YAMLError:
raise exceptions.ConfigSyntaxError("Error parsing YAML")

Expand All @@ -90,9 +87,7 @@ def load(self, config_path=None):
self._printer_name = class_names.get(printer_name.lower(), printer_name)

if not self._printer_name or not hasattr(printer, self._printer_name):
raise exceptions.ConfigSyntaxError(
f'Printer type "{self._printer_name}" is invalid'
)
raise exceptions.ConfigSyntaxError(f'Printer type "{self._printer_name}" is invalid')

self._has_loaded = True

Expand Down
Loading
Loading