Skip to content

Commit 35d6765

Browse files
authored
Fixes for Python < 3.10 (#76)
1 parent d53bfcd commit 35d6765

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

docs/release_notes/v2.0.0.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. _v2.0.0:
2+
3+
2.0.0
4+
=====
5+
6+
* Renamed default branch to ``main``
7+
* Switched to a ``pyproject.toml`` based project
8+
* Removed ``pydicom`` module
9+
* Supported Python versions are 3.8, 3.9, 3.10, 3.11 and 3.12

pylibjpeg/utils.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,18 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:
132132
if not decoder_type:
133133
decoders = {}
134134
for entry_point in DECODER_ENTRY_POINTS.values():
135-
print(entry_point in ep)
136135
if entry_point in ep:
137136
decoders.update({val.name: val.load() for val in ep[entry_point]})
138137

139138
return decoders
140139

141-
if decoder_type in ep:
142-
return {val.name: val.load() for val in ep[decoder_type]}
143-
144-
return {}
140+
try:
141+
return {
142+
val.name: val.load()
143+
for val in ep[DECODER_ENTRY_POINTS[decoder_type]]
144+
}
145+
except KeyError:
146+
return {}
145147

146148
if not decoder_type:
147149
decoders = {}
@@ -151,11 +153,11 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:
151153

152154
return decoders
153155

154-
if decoder_type in DECODER_ENTRY_POINTS:
156+
try:
155157
result = metadata.entry_points(group=DECODER_ENTRY_POINTS[decoder_type])
156158
return {val.name: val.load() for val in result}
157-
158-
return {}
159+
except KeyError:
160+
return {}
159161

160162

161163
def get_pixel_data_decoders() -> Dict[str, Decoder]:
@@ -171,10 +173,13 @@ def get_pixel_data_decoders() -> Dict[str, Decoder]:
171173

172174
return {}
173175

174-
return {
175-
val.name: val.load()
176-
for val in metadata.entry_points(group="pylibjpeg.pixel_data_decoders")
177-
}
176+
try:
177+
return {
178+
val.name: val.load()
179+
for val in metadata.entry_points(group="pylibjpeg.pixel_data_decoders")
180+
}
181+
except KeyError:
182+
return {}
178183

179184

180185
def _encode(arr: np.ndarray, encoder: str = "", **kwargs: Any) -> Union[bytes, bytearray]:
@@ -268,16 +273,16 @@ def get_encoders(encoder_type: str = "") -> Dict[str, Encoder]:
268273
if not encoder_type:
269274
encoders = {}
270275
for entry_point in ENCODER_ENTRY_POINTS.values():
271-
result = metadata.entry_points().select(group=entry_point)
276+
result = metadata.entry_points(group=entry_point)
272277
encoders.update({val.name: val.load() for val in result})
273278

274279
return encoders
275280

276-
if encoder_type in ENCODER_ENTRY_POINTS:
277-
result = metadata.entry_points().select(group=ENCODER_ENTRY_POINTS[encoder_type])
281+
try:
282+
result = metadata.entry_points(group=ENCODER_ENTRY_POINTS[encoder_type])
278283
return {val.name: val.load() for val in result}
279-
280-
return {}
284+
except KeyError:
285+
return {}
281286

282287

283288
def get_pixel_data_encoders() -> Dict[str, Encoder]:
@@ -296,7 +301,10 @@ def get_pixel_data_encoders() -> Dict[str, Encoder]:
296301

297302
return {}
298303

299-
return {
300-
val.name: val.load()
301-
for val in metadata.entry_points(group="pylibjpeg.pixel_data_encoders")
302-
}
304+
try:
305+
return {
306+
val.name: val.load()
307+
for val in metadata.entry_points(group="pylibjpeg.pixel_data_encoders")
308+
}
309+
except KeyError:
310+
return {}

0 commit comments

Comments
 (0)