Skip to content

Commit fb21ae8

Browse files
authored
Merge pull request #137 from claui/barcode-basewriter-compat
Make Labelle compatible with python-barcode v0.16
2 parents c66b2ce + e836a47 commit fb21ae8

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies = [
1818
"platformdirs",
1919
"Pillow>=8.1.2,<11",
2020
"PyQRCode>=1.2.1,<2",
21-
"python-barcode>=0.13.1,<0.16",
21+
"python-barcode>=0.13.1",
2222
"pyusb",
2323
"PyQt6",
2424
"darkdetect",

src/labelle/lib/barcode_writer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"""A string that's been validated to contain only '0's and '1's."""
1515

1616

17+
def _noop() -> None:
18+
pass
19+
20+
1721
def _validate_string_as_binary(s: str) -> BinaryString:
1822
if not all(c in ("0", "1") for c in s):
1923
raise ValueError("Barcode can only contain 0 and 1")
@@ -26,6 +30,15 @@ class BarcodeResult(NamedTuple):
2630

2731

2832
class SimpleBarcodeWriter(BaseWriter):
33+
def __init__(self) -> None:
34+
# Pass dummy values because we re-implement the `render` method anyway
35+
super().__init__(
36+
initialize=None,
37+
paint_module=_noop,
38+
paint_text=None,
39+
finish=_noop,
40+
)
41+
2942
def render(self, code: List[str]) -> BarcodeResult:
3043
"""Extract the barcode string from the code and render it into an image."""
3144
if len(code) != 1:

src/labelle/lib/render_engines/tests/test_render_engines.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ def test_barcode_render_engine_internal_error():
130130
)
131131
with pytest.raises(BarcodeRenderError) as exc_info:
132132
render_engine.render(RENDER_CONTEXT)
133-
assert (
134-
str(exc_info.value) == "Barcode render error: IllegalCharacterError("
135-
"'EAN code can only contain numbers.')"
133+
assert str(exc_info.value).startswith(
134+
"Barcode render error: IllegalCharacterError('EAN code can only contain numbers"
136135
)
137136

138137

0 commit comments

Comments
 (0)