Skip to content

Commit 444ad8a

Browse files
authored
Only add pydicom handler if not present (#50)
1 parent 8a2855f commit 444ad8a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.github/workflows/pytest-builds.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [ master ]
66
pull_request:
7-
branches: [ master ]
87

98
jobs:
109
ubuntu:
@@ -29,12 +28,17 @@ jobs:
2928
python -m pip install .
3029
python -m pip uninstall -y pylibjpeg-openjpeg
3130
python -m pip install git+https://github.com/pydicom/pylibjpeg-data
32-
python -m pip install pytest coverage pytest-cov pydicom
31+
python -m pip install pytest coverage pytest-cov
3332
3433
- name: Run pytest with no plugins
3534
run: |
3635
pytest --cov=pylibjpeg --cov-append
3736
37+
- name: Rerun pytest with pydicom and no plugins
38+
run: |
39+
pip install pydicom
40+
pytest --cov=pylibjpeg --cov-append
41+
3842
- name: Rerun pytest with -lj plugin
3943
run: |
4044

pylibjpeg/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ def debug_logger():
2727

2828
try:
2929
import pydicom
30-
add_handler()
3130
_logger.debug('pydicom module loaded')
3231
from pylibjpeg.pydicom.utils import generate_frames
32+
33+
# We only add a handler if pydicom doesn't already have one
34+
try:
35+
import pydicom.pixel_data_handlers.pylibjpeg_handler
36+
except ImportError:
37+
add_handler()
38+
3339
except ImportError:
3440
pass

pylibjpeg/tests/test_pydicom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_get_pixeldata_no_lj_syntax(self):
7272
handler.get_pixeldata(ds)
7373

7474

75+
@pytest.mark.skipif(not HAS_PYDICOM, reason="No pydicom")
7576
class TestPlugins(object):
7677
"""Test interaction with plugins."""
7778
@pytest.mark.skipif(not RUN_JPEG, reason="No JPEG plugin")

0 commit comments

Comments
 (0)