Skip to content

Commit 5cfb904

Browse files
committed
Add debug logging for type conversions
1 parent f512615 commit 5cfb904

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/scyjava/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,15 @@ def __getattr__(name):
174174

175175

176176
def _initialize_converters():
177+
_logger.debug("Initializing type converters")
178+
177179
for converter in _stock_java_converters():
178180
add_java_converter(converter)
181+
_logger.debug("Java converters:{'\n-'.join(java_converters)}")
182+
179183
for converter in _stock_py_converters():
180184
add_py_converter(converter)
185+
_logger.debug("Python converters:{'\n-'.join(py_converters)}")
181186

182187

183188
when_jvm_starts(_initialize_converters)

src/scyjava/_convert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import collections
66
import inspect
7+
import logging
78
import math
89
from bisect import insort
910
from pathlib import Path
@@ -24,6 +25,8 @@
2425
start_jvm,
2526
)
2627

28+
_logger = logging.getLogger(__name__)
29+
2730

2831
# NB: We cannot use org.scijava.priority.Priority or other Java-side class
2932
# here because we don't want to impose Java-side dependencies, and we don't
@@ -92,9 +95,14 @@ def _convert(obj: Any, converters: List[Converter], **hints: Dict) -> Any:
9295
# meaning lower-priority items appear earlier than higher-priority ones.
9396
# But we want to try the higher priority converters first, so we
9497
# need to iterate the given converters list starting at the end.
98+
debug = hints.get("debug", False)
99+
log = _logger.info if debug else _logger.debug
100+
log(f"Converting object of type {type(obj)} with hints {hints}")
95101
for converter in reversed(converters):
96102
if converter.supports(obj, **hints):
103+
log(f"- {converter} supports")
97104
return converter.convert(obj, **hints)
105+
log(f"- {converter} does not support")
98106

99107

100108
# -- Python to Java --

0 commit comments

Comments
 (0)