Skip to content

Commit

Permalink
Merge pull request #216 from LedgerHQ/fix/unneeded_physical_imports
Browse files Browse the repository at this point in the history
Avoid import error on tesseract when using Ragger with Speculos only
  • Loading branch information
lpascal-ledger authored Feb 6, 2025
2 parents 66706e8 + 41194ca commit cc8c4ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.26.0] - 2025-??-??
## [1.26.0] - 2025-02-06

### Added

Expand All @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `_actionhint` element location (covered previously by the snapshot image)
- Physical backend -specific imports (`PIL`, `tesseract`) are postponed to avoid raising when using
Speculos only

## [1.25.0] - 2024-12-20

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ ledgercomm = [
"ledgercomm[hid]>=1.2.1",
"pyqt5",
"pytesseract",
"pillow",
]
ledgerwallet = [
"ledgerwallet>=0.4.0",
"pyqt5",
"pytesseract",
"pillow",
]
all_backends = [
"ragger[speculos]",
Expand Down
12 changes: 10 additions & 2 deletions src/ragger/backend/physical_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
limitations under the License.
"""
from pathlib import Path
from PIL import Image, ImageOps
from pytesseract import image_to_data, Output
from types import TracebackType
from typing import List, Optional, Type

Expand Down Expand Up @@ -104,6 +102,16 @@ def compare_screen_with_snapshot(self,
return False

def compare_screen_with_text(self, text: str) -> bool:
# Only this method needs these dependencies, which needs at least one physical backend to
# be installed. By postponing the imports, we avoid an import error when using only Speculos
try:
from PIL import Image, ImageOps
from pytesseract import image_to_data, Output
except ImportError as error:
raise ImportError(
"This feature needs at least one physical backend. "
"Please install ragger[ledgercomm] or ragger[ledgerwallet]") from error

if self._ui is None:
return True
self.init_gui()
Expand Down

0 comments on commit cc8c4ae

Please sign in to comment.