Skip to content

Commit e836a47

Browse files
committed
Make Labelle compatible with python-barcode v0.16
In python-barcode [1] v0.16.0, the API of the BaseWriter constructor was narrowed [2] so two of its callbacks can no longer be None (see issue #123 [3].) Given we override the implementation that would use those callbacks anyway, pass dummy callbacks. This ensures compatibility with both pre-v0.16 and newer versions of python-barcode. Additionally, loosen one of the assertions where the upstream wording of an error message slightly changed. Fixes #123. [1]: https://pypi.org/project/python-barcode/ [2]: WhyNotHugo/python-barcode@v0.15.1...v0.16.0#diff-01c9de34453d29913aa28bb39e4c847e2ecf95cf81b1264c2759090f870152c9 [3]: #123 Reported-by: @blaisegarant
1 parent c66b2ce commit e836a47

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)