Use Poetry instead of Pip to manage requirements #28

Merged
n07070 merged 8 commits from move-to-poetry into master 2026-05-18 23:21:18 +02:00
8 changed files with 1943 additions and 285 deletions

View File

@@ -19,35 +19,42 @@ To make this project work, you will need :
- Some electric wires. - Some electric wires.
- Some knowledge of the command line, - Some knowledge of the command line,
- Some knowledge of Python. - Some knowledge of Python.
- You will need to install [Poetry](https://python-poetry.org/) to manage the depedencies of the projet.
- 3h of your time, 5h if things need debugging. - 3h of your time, 5h if things need debugging.
- `fswebcam`, `libjpeg-dev` ,`zlib1g-dev`,`libffi-dev`,`git`, `virtualenv`,`pip` and `python` >= 3.8.6. - You will need to following packages: `fswebcam`, `libjpeg-dev` ,`zlib1g-dev`,`libffi-dev`,`git`, `virtualenv`,`pip` and `python` >= 3.8.6.
- A webcam for the webcam page to work. Will work on a smartphone. Not required. - A webcam for the webcam page to work. Will work on a smartphone. Not required.
## Context ## Context
### Testing your printer
For the EPSON TM-T20III, you can get the CUPS driver from [here](https://download.epson-biz.com/modules/pos/index.php?page=soft&scat=32). It's not specific to the printer I've been using, so you can try with other printers. For the EPSON TM-T20III, you can get the CUPS driver from [here](https://download.epson-biz.com/modules/pos/index.php?page=soft&scat=32). It's not specific to the printer I've been using, so you can try with other printers.
With that, you can try out your printer and print normal text, images or pdf documents for example. LittlePrynter itself does not require any other software than the ones installed with it, i.e the ones listed in the `requirements.txt` file. With that, you can try out your printer and print normal text, images or pdf documents for example. For the Adafruit printer, start by following the guide [here](https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi) to install the CUPS software needed to print images. If you want, you can install it via the command line, [following this guide](https://help.ubuntu.com/lts/serverguide/cups.html).
For the Adafruit printer, start by following the guide [here](https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi) to install the CUPS software needed to print images. If you want, you can install it via the command line, [following this guide](https://help.ubuntu.com/lts/serverguide/cups.html).
You can also get some information from [here](https://learn.adafruit.com/mini-thermal-receipt-printer) and [here](https://learn.adafruit.com/instant-camera-using-raspberry-pi-and-thermal-printer) if you're stuck. You can also get some information from [here](https://learn.adafruit.com/mini-thermal-receipt-printer) and [here](https://learn.adafruit.com/instant-camera-using-raspberry-pi-and-thermal-printer) if you're stuck.
### How LittlePrynter works
LittlePrynter itself does not require any other software than the ones installed with it, i.e the ones listed in the `pyproject.toml` file.
The version for the EPSON TM-T20III uses a library called `python-escpos`, which doesn't need a CUPS driver or anything else. It's included in the Python dependencies. The version for the EPSON TM-T20III uses a library called `python-escpos`, which doesn't need a CUPS driver or anything else. It's included in the Python dependencies.
The project only supports the EPSON printer, but you can try to adapt it for other printers using the `adafruit-thermal` branch, but I won't offer support for it. The project only supports the EPSON printer, but you can try to adapt it for other printers. For example, using `adafruit-thermal`, or `brother-ql`.
### Install & setup the project : ### Install & setup the project :
Theses commands will copy the software on your computer, go into the directory, then activate a virtual environnement and install all of the project's dependecies.
``` ```
$ git clone https://git.n07070.xyz/n07070/LittlePrynter $ git clone https://git.n07070.xyz/n07070/LittlePrynter
$ virtualenv LittlePrynter
$ cd LittlePrynter $ cd LittlePrynter
$ source bin/activate $ eval "$(poetry env activate)"
$ pip install -r requirements.txt $ poetry install
``` ```
> tip : when you're done, you can get out of the virtualenv either by closing your terminal, or by running `deactivate`. > tip : when you're done, you can get out of the poetry environnement either by closing your terminal, or by running `deactivate`.
### Configure LittlePrynter
You should see a folder named `configuration`. Enter it, and duplicate the file named `config.toml.sample`, and rename the copy to `config.toml`. Now, edit this file by following the comments in the file itself. You should see a folder named `configuration`. Enter it, and duplicate the file named `config.toml.sample`, and rename the copy to `config.toml`. Now, edit this file by following the comments in the file itself.
@@ -57,9 +64,11 @@ You can now start the web server with
``` ```
$ export FLASK_APP=src/main.py $ export FLASK_APP=src/main.py
$ flask run $ flask run --cert=adhoc
``` ```
The `--cert=adhoc` argument will make LittlePrinter accessible in HTTPS with a [self-signed SSL certificate](https://en.wikipedia.org/wiki/Self-signed_certificate). This provides a free and easy way to use HTTPS, but does not provide any trust value. It is, on the other hand, a good way to access the webcam in developpement mode or on a local network, because a HTTPS connexion is required by browsers to access the needed APIs.
This command should start a web server with which you can test your configuration. If you plan on exposing your printer to the Internet, and give it an IP / URL, _please, please, please_, don't run it this way. Look at Flask's documentation and read about running a production server. It's a little more work, but it will prevent your computer/server being hacked in too easily. This command should start a web server with which you can test your configuration. If you plan on exposing your printer to the Internet, and give it an IP / URL, _please, please, please_, don't run it this way. Look at Flask's documentation and read about running a production server. It's a little more work, but it will prevent your computer/server being hacked in too easily.
Voilà ! Voilà !
@@ -74,7 +83,7 @@ Please also say if you had a printer to test your code, and which printer you've
If you want to contribute code, please make sure to lint the project before commiting. This helps the code keep a general structure, and avoids some commons erros and mistakes. If you want to contribute code, please make sure to lint the project before commiting. This helps the code keep a general structure, and avoids some commons erros and mistakes.
To do so, you can run the following command : To do so, you can run the following command, which will modify your files to be in a certain coding style ;
``` ```
black src/ black src/
@@ -82,6 +91,12 @@ black src/
Beware that this command *will* re-write files, so doing `git add <file>` and then `black src/` and then `git diff` to see what the linter has done is a good idea. Beware that this command *will* re-write files, so doing `git add <file>` and then `black src/` and then `git diff` to see what the linter has done is a good idea.
Then, you can run another command, called Pylint ( [documentation](https://www.pylint.org/) ) which will rate your code. Try to get 10/10 : an excellent code works better and make you a better programmer !
```
pylint src/
```
## Screenshots ## Screenshots
![](src/static/images/homepage.png) ![](src/static/images/homepage.png)
@@ -104,6 +119,7 @@ If you liked this project, feel free to support my work !
- [Github repo with CUPS drivers for the Adafruit Thermal Printer ( zj-58 )](https://github.com/klirichek/zj-58) - [Github repo with CUPS drivers for the Adafruit Thermal Printer ( zj-58 )](https://github.com/klirichek/zj-58)
- [A link to buy one in Europe](https://rlx.sk/sk/various-boards/1829-mini-thermal-receipt-printer-adafruit-597.html) - [A link to buy one in Europe](https://rlx.sk/sk/various-boards/1829-mini-thermal-receipt-printer-adafruit-597.html)
- [Another link to buy one, direct from factory](https://www.cashinotech.com/csn-a2-58mm-mini-panel-thermal-receipt-printer_p11.html) - [Another link to buy one, direct from factory](https://www.cashinotech.com/csn-a2-58mm-mini-panel-thermal-receipt-printer_p11.html)
- [Diagnostickoeur](https://framagit.org/stickoeur/diagnostickoeur), another printer software mainly around Brother QL printers.
## Licence ## Licence

View File

@@ -6,7 +6,7 @@ After=network.target
Type=simple Type=simple
WorkingDirectory=/home/pi/littleprynter/ WorkingDirectory=/home/pi/littleprynter/
Environment=FLASK_APP=src/main.py Environment=FLASK_APP=src/main.py
ExecStart=/home/pi/littleprynter/bin/flask run --host 0.0.0.0 --debug --no-reload ExecStart=/home/pi/littleprynter/bin/flask run --host 0.0.0.0 --no-reload
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -1 +0,0 @@
{"last_check":"2018-10-10T18:33:22Z","pypi_version":"18.1"}

1856
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

55
pyproject.toml Normal file
View File

@@ -0,0 +1,55 @@
[project]
name = "littleprynter"
version = "0.1.0"
description = "A web interface and API to print on thermal printers"
authors = [
{name = "n07070",email = "contact@n07070.xyz"}
]
license = "AGPLv3"
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"flask (>=3.1.3,<4.0.0)",
"numpy (>=2.3.4)",
"toml (>=0.10.2,<0.11.0)",
"flask-socketio (>=5.6.1,<6.0.0)",
"flask-limiter (>=4.1.1,<5.0.0)",
"gpiozero (>=2.0.1)",
"cryptography (>=48.0.0,<49.0.0)",
"pyusb (>=1.3.1,<2.0.0)",
"pyserial (>=3.5,<4.0)",
"qrcode (<9.0)",
"python-barcode (>=0.16.1)",
"setuptools (==81)",
"cffi (>=2.0.0,<3.0.0)",
"configobj (>=5.0.9,<6.0.0)",
"future (>=1.0.0,<2.0.0)",
"h11 (>=0.16.0,<0.17.0)",
"idna (>=3.15,<4.0)",
"itsdangerous (>=2.2.0,<3.0.0)",
"jinja2 (>=3.1.6,<4.0.0)",
"jsonpointer (>=3.1.1,<4.0.0)",
"jsonschema (>=4.26.0,<5.0.0)",
"limits (>=5.8.0,<6.0.0)",
"markupsafe (>=3.0.3,<4.0.0)",
"pillow (>=12.2.0,<13.0.0)",
"pycryptodomex (>=3.23.0,<4.0.0)",
"python-dateutil (>=2.9.0.post0,<3.0.0)",
"python-engineio (>=4.13.1,<5.0.0)",
"python-socketio (>=5.16.1,<6.0.0)",
"pyyaml (>=6.0.3,<7.0.0)",
"requests (>=2.34.2,<3.0.0)",
"python-escpos (>=3.1,<4.0)",
"pep8 (>=1.7.1,<2.0.0)",
"pylint (>=4.0.5,<5.0.0)",
]
[tool.poetry]
package-mode = false
[tool.poetry.dependencies]
python-escpos = {allow-prereleases = true}
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

View File

@@ -1,261 +0,0 @@
appdirs==1.4.4
apt-listchanges==4.8
argcomplete==3.6.2
arrow==1.3.0
attrs==25.3.0
babel==2.17.0
bcrypt==4.2.0
bidict==0.23.1
blinker==1.9.0
certifi==2025.1.31
cffi==1.17.1
chardet==5.2.0
charset-normalizer==3.4.2
click==8.3.0
cloud-init==25.2
colorzero==2.0
configobj==5.0.9
cryptography==43.0.0
Deprecated==1.2.18
distlib==0.3.9
distro==1.9.0
escpos==2.0.0
filelock==3.18.0
Flask==3.1.2
Flask-Limiter==4.0.0
Flask-SocketIO==5.5.1
fqdn==1.5.1
future==1.0.0
gpiod==2.2.0
gpiozero==2.0.1
h11==0.16.0
idna==3.10
isoduration==20.11.0
itsdangerous==2.2.0
Jinja2==3.1.6
jsonpatch==1.32
jsonpointer==2.4
jsonschema==4.19.2
jsonschema-specifications==2023.12.1
lgpio==0.2.2.0
limits==5.6.0
linkify-it-py==2.0.3
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
numpy==2.3.4
oauthlib==3.2.2
olefile==0.47
ordered-set==4.1.0
packaging==25.0
pillow==11.1.0
platformdirs==4.3.7
ply==3.11
pycparser==2.22
pycryptodomex==3.20.0
Pygments==2.18.0
PyJWT==2.10.1
pyserial==3.5
python-apt==3.0.0
python-barcode==0.16.1
python-dateutil==2.9.0
python-engineio==4.12.3
python-socketio==5.14.1
pyusb==1.3.1
PyYAML==6.0.2
qrcode==8.2
referencing==0.36.2
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rfc3987==1.3.8
rich==13.9.4
rpds-py==0.21.0
rpi-keyboard-config==1.0
rpi-lgpio==0.6
setuptools==80.9.0
simple-websocket==1.1.0
six==1.17.0
smbus2==0.4.3
spidev==3.6
ssh-import-id==5.10
toml==0.10.2
types-aiofiles==24.1
types-antlr4-python3-runtime==4.13
types-assertpy==1.1
types-atheris==2.3
types-aws-xray-sdk==2.14
types-beautifulsoup4==4.12
types-bleach==6.2
types-boltons==24.1
types-braintree==4.31
types-cachetools==5.5
types-caldav==1.3
types-capturer==3.0
types-cffi==1.16
types-chevron==0.14
types-click-default-group==1.2
types-click-spinner==0.1
types-colorama==0.4
types-commonmark==0.9
types-console-menu==0.8
types-corus==0.10
types-croniter==5.0.1
types-dateparser==1.2
types-decorator==5.1
types-defusedxml==0.7
types-Deprecated==1.2.15
types-docker==7.1
types-dockerfile-parse==2.0
types-docutils==0.21
types-editdistance==0.8
types-entrypoints==0.4
types-ExifRead==3.0
types-fanstatic==1.4
types-first==2.0
types-flake8==7.1
types-flake8-bugbear==24.12.12
types-flake8-builtins==2.5
types-flake8-docstrings==1.7
types-flake8-rst-docstrings==0.3
types-flake8-simplify==0.21
types-flake8-typing-imports==1.16
types-Flask-Cors==5.0
types-Flask-Migrate==4.0
types-Flask-SocketIO==5.4
types-fpdf2==2.8.2
types-gdb==15.0
types-gevent==24.11
types-google-cloud-ndb==2.3
types-greenlet==3.1
types-hdbcli==2.23
types-html5lib==1.1
types-httplib2==0.22
types-humanfriendly==10.0
types-hvac==2.3
types-ibm-db==3.2.4
types-icalendar==6.1
types-influxdb-client==1.45
types-inifile==0.4
types-JACK-Client==0.5
types-Jetson.GPIO==2.1
types-jmespath==1.0
types-jsonschema==4.23
types-jwcrypto==1.5
types-keyboard==0.13
types-ldap3==2.9
types-libsass==0.23
types-lupa==2.2
types-lzstring==1.0
types-m3u8==6.0
types-Markdown==3.7
types-mock==5.1
types-mypy-extensions==1.0
types-mysqlclient==2.2
types-nanoid==2.0.0
types-netaddr==1.3
types-netifaces==0.11
types-networkx==3.4.2
types-oauthlib==3.2
types-objgraph==3.6
types-olefile==0.47
types-openpyxl==3.1.5
types-opentracing==2.4
types-paramiko==3.5
types-parsimonious==0.10
types-passlib==1.7
types-passpy==1.0
types-peewee==3.17.8
types-pep8-naming==0.14
types-pexpect==4.9
types-pika-ts==1.3
types-polib==1.2
types-portpicker==1.6
types-protobuf==5.29.1
types-psutil==6.1
types-psycopg2==2.9.10
types-pyasn1==0.6
types-pyaudio==0.2
types-PyAutoGUI==0.9
types-pycocotools==2.0
types-pycurl==7.45.4
types-pyfarmhash==0.4
types-pyflakes==3.2
types-pygit2==1.15
types-Pygments==2.18
types-pyinstaller==6.11
types-pyjks==20.0
types-PyMySQL==1.1
types-pynput==1.7.7
types-pyOpenSSL==24.1
types-pyRFC3339==2.0.1
types-PyScreeze==1.0.1
types-pyserial==3.5
types-pysftp==0.2
types-pytest-lazy-fixture==0.6
types-python-crontab==3.2
types-python-datemath==3.0.1
types-python-dateutil==2.9
types-python-http-client==3.3.7
types-python-jenkins==1.8
types-python-jose==3.3
types-python-nmap==0.7
types-python-xlib==0.33
types-pytz==2024.2
types-pywin32==308
types-pyxdg==0.28
types-PyYAML==6.0
types-qrbill==1.1
types-qrcode==8.0
types-regex==2024.11.6
types-reportlab==4.2.5
types-requests==2.32
types-requests-oauthlib==2.0
types-retry==0.9
types-RPi.GPIO==0.7
types-s2clientprotocol==5
types-seaborn==0.13.2
types-Send2Trash==1.8
types-setuptools==75.6
types-shapely==2.0
types-simplejson==3.19
types-singledispatch==4.1
types-six==1.17
types-slumber==0.7
types-str2bool==1.1
types-tabulate==0.9
types-tensorflow==2.18.0
types-TgCrypto==1.2
types-toml==0.10
types-toposort==1.10
types-tqdm==4.67
types-translationstring==1.4
types-tree-sitter-languages==1.10
types-ttkthemes==3.2
types-ujson==5.10
types-unidiff==0.7
types-untangle==1.2
types-usersettings==1.1
types-uWSGI==2.0
types-vobject==0.9.9
types-waitress==3.0.1
types-WebOb==1.8
types-whatthepatch==1.0
types-workalendar==17.0
types-WTForms==3.2.1
types-wurlitzer==3.1
types-xdgenvpy==3.0
types-xmltodict==0.14
types-zstd==1.5
types-zxcvbn==4.4
typing_extensions==4.15.0
uc-micro-py==1.0.3
uritemplate==4.1.1
urllib3==2.3.0
viivakoodi==0.8.0
virtualenv==20.31.2
webcolors==1.13
Werkzeug==3.1.3
wheel==0.46.1
wrapt==1.17.3
wsproto==1.2.0

7
run.sh
View File

@@ -1,7 +0,0 @@
virtualenv .
pip install -r requirements.txt
export FLASK_APP=src/main.py
export FLASK_ENV=development
flask run --host 192.168.0.42 --debugger --eager-loading

View File

@@ -1,5 +1,5 @@
# Importing the module to mage the connection to the printer. # Importing the module to manage the connection to the printer.
from escpos.printer import Usb, USBNotFoundError import escpos.printer as escp
from time import sleep, gmtime, strftime from time import sleep, gmtime, strftime
import os.path import os.path
from PIL import Image, ImageEnhance, ImageOps from PIL import Image, ImageEnhance, ImageOps
@@ -66,8 +66,8 @@ class Printer(object):
try: try:
# This also calls open(), which we need to close() # This also calls open(), which we need to close()
# or else the device will appear as busy. # or else the device will appear as busy.
p = Usb(self.device_id, self.vendor_id, 0, profile="TM-P80") p = escp.Usb(self.device_id, self.vendor_id, 0, profile="TM-P80")
except USBNotFoundError as e: except Exception as e:
self.app.logger.error( self.app.logger.error(
"The USB device is not plugged in, trying again : " + str(e) "The USB device is not plugged in, trying again : " + str(e)
) )