Skip to content

Commit fbabd8e

Browse files
authored
Drop Py37, improve typing and docstrings (#544)
Drops Py3.7, improves typing and adds a mypy config, improves the docstrings and isorts the imports. * configure isort * sort with isort * add github action * enable flake8-docstrings * fix docstrings * add mypy env * no implicit optional * add type for raw * add some type hints
1 parent 2b62c8e commit fbabd8e

45 files changed

Lines changed: 461 additions & 341 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pythonpackage.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
python -m pip install --upgrade pip
3131
pip install flake8 pytest tox tox-gh-actions
3232
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
- name: Check sorting of imports
34+
uses: isort/isort-action@master
35+
with:
36+
requirementsFiles: "requirements.txt doc/requirements.txt"
37+
sortPaths: "./doc ./src ./examples ./test ./setup.py"
3338
- name: Lint with flake8
3439
run: |
3540
# stop the build if there are Python syntax errors or undefined names
@@ -50,4 +55,4 @@ jobs:
5055
files: ./coverage.xml,!./cache
5156
flags: unittests
5257
name: coverage-tox-${{ matrix.python-version }}
53-
verbose: true
58+
verbose: true

doc/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys
1615
import os
17-
16+
import sys
1817
from importlib.metadata import version as imp_version
1918

2019
on_rtd = os.getenv("READTHEDOCS") == "True"

examples/barcodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
"""Example for printing barcodes."""
12
from escpos.printer import Usb
23

3-
44
# Adapt to your needs
55
p = Usb(0x0416, 0x5011, profile="TM-T88II")
66

examples/codepage_tables.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
"""Prints code page tables.
2-
"""
1+
"""Prints code page tables."""
32

43

5-
import six
64
import sys
75

6+
import six
7+
88
from escpos import printer
99
from escpos.constants import (
1010
CODEPAGE_CHANGE,
11-
ESC,
12-
CTL_LF,
13-
CTL_FF,
1411
CTL_CR,
12+
CTL_FF,
1513
CTL_HT,
14+
CTL_LF,
1615
CTL_VT,
16+
ESC,
1717
)
1818

1919

2020
def main():
21+
"""Init printer and print codepage tables."""
2122
dummy = printer.Dummy()
2223

2324
dummy.hw("init")
@@ -34,6 +35,7 @@ def main():
3435

3536

3637
def print_codepage(printer, codepage):
38+
"""Print a codepage."""
3739
if codepage.isdigit():
3840
codepage = int(codepage)
3941
printer._raw(CODEPAGE_CHANGE + six.int2byte(codepage))

examples/docker-flask/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
from escpos.printer import CupsPrinter
1+
"""Example for a flask application."""
22
from flask import Flask
33

4+
from escpos.printer import CupsPrinter
5+
46
# Initialize Flask app
57
app = Flask(__name__)
68

79

810
@app.route("/", methods=["GET"])
911
def do_print():
12+
"""Print."""
1013
# p = Usb(0x04b8, 0x0e28, 0)
1114
p = CupsPrinter(host="localhost", port=631, printer_name="TM-T20III")
1215
p.text("Hello World\n")

examples/docker-flask/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ argcomplete==3.0.8
33
blinker==1.6.2
44
click==8.1.3
55
Flask==2.3.2
6-
future==0.18.3
76
itsdangerous==2.1.2
87
Jinja2==3.1.2
98
MarkupSafe==2.1.2

examples/qr_code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
"""Print example QR codes."""
12
import sys
23

34
from escpos.printer import Usb
45

56

67
def usage():
8+
"""Print information on usage."""
79
print("usage: qr_code.py <content>")
810

911

examples/software_barcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
"""Example file for software barcodes."""
12
from escpos.printer import Usb
23

3-
44
# Adapt to your needs
55
p = Usb(0x0416, 0x5011, profile="POS-5890")
66

examples/weather.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
#!/usr/bin/python
2+
"""Weather forecast example.
23
4+
Adapted script from Adafruit
5+
Weather forecast for Raspberry Pi w/Adafruit Mini Thermal Printer.
6+
Retrieves data from DarkSky.net's API, prints current conditions and
7+
forecasts for next two days.
8+
Weather example using nice bitmaps.
9+
Written by Adafruit Industries. MIT license.
10+
Adapted and enhanced for escpos library by MrWunderbar666
311
4-
# Adapted script from Adafruit
5-
# Weather forecast for Raspberry Pi w/Adafruit Mini Thermal Printer.
6-
# Retrieves data from DarkSky.net's API, prints current conditions and
7-
# forecasts for next two days.
8-
# Weather example using nice bitmaps.
9-
# Written by Adafruit Industries. MIT license.
10-
# Adapted and enhanced for escpos library by MrWunderbar666
12+
Icons taken from https://adamwhitcroft.com/climacons/
13+
Check out his github: https://github.com/AdamWhitcroft/climacons
14+
"""
1115

12-
# Icons taken from https://adamwhitcroft.com/climacons/
13-
# Check out his github: https://github.com/AdamWhitcroft/climacons
1416

15-
16-
from datetime import datetime
1717
import calendar
18-
import urllib
1918
import json
20-
import time
2119
import os
20+
import time
21+
import urllib
22+
from datetime import datetime
2223

2324
from escpos.printer import Usb
2425

25-
""" Setting up the main pathing """
26+
"""Set up the main pathing."""
2627
this_dir, this_filename = os.path.split(__file__)
2728
GRAPHICS_PATH = os.path.join(this_dir, "graphics/climacons/")
2829

@@ -38,13 +39,14 @@
3839

3940

4041
def forecast_icon(idx):
42+
"""Get right icon for forecast."""
4143
icon = data["daily"]["data"][idx]["icon"]
4244
image = GRAPHICS_PATH + icon + ".png"
4345
return image
4446

4547

46-
# Dumps one forecast line to the printer
4748
def forecast(idx):
49+
"""Dump one forecast line to the printer."""
4850
date = datetime.fromtimestamp(int(data["daily"]["data"][idx]["time"]))
4951
day = calendar.day_name[date.weekday()]
5052
lo = data["daily"]["data"][idx]["temperatureMin"]
@@ -73,6 +75,7 @@ def forecast(idx):
7375

7476

7577
def icon():
78+
"""Get icon."""
7679
icon = data["currently"]["icon"]
7780
image = GRAPHICS_PATH + icon + ".png"
7881
return image

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
[tool.black]
22
extend-exclude = 'capabilities-data'
33

4+
[tool.isort]
5+
profile = "black"
6+
7+
[tool.pytest.ini_options]
8+
minversion = "6.0"
9+
addopts = "--doctest-modules --cov escpos --cov-report=xml"
10+
testpaths = [
11+
"test",
12+
"src",
13+
"src/escpos",
14+
"escpos",
15+
]

0 commit comments

Comments
 (0)