Skip to content

Commit

Permalink
Fixes for Python < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Jan 3, 2024
1 parent d53bfcd commit 0a41b27
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
9 changes: 9 additions & 0 deletions docs/release_notes/v2.0.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _v2.0.0:

2.0.0
=====

* Renamed default branch to ``main``
* Switched to a ``pyproject.toml`` based project
* Removed ``pydicom`` module
* Supported Python versions are 3.8, 3.9, 3.10, 3.11 and 3.12
50 changes: 29 additions & 21 deletions pylibjpeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,18 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:
if not decoder_type:
decoders = {}
for entry_point in DECODER_ENTRY_POINTS.values():
print(entry_point in ep)
if entry_point in ep:
decoders.update({val.name: val.load() for val in ep[entry_point]})

return decoders

if decoder_type in ep:
return {val.name: val.load() for val in ep[decoder_type]}

return {}
try:
return {
val.name: val.load()
for val in ep[DECODER_ENTRY_POINTS[decoder_type]]
}
except KeyError:
return {}

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

return decoders

if decoder_type in DECODER_ENTRY_POINTS:
try:
result = metadata.entry_points(group=DECODER_ENTRY_POINTS[decoder_type])
return {val.name: val.load() for val in result}

return {}
except KeyError:
return {}


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

return {}

return {
val.name: val.load()
for val in metadata.entry_points(group="pylibjpeg.pixel_data_decoders")
}
try:
return {
val.name: val.load()
for val in metadata.entry_points(group="pylibjpeg.pixel_data_decoders")
}
except KeyError:
return {}


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

return encoders

if encoder_type in ENCODER_ENTRY_POINTS:
result = metadata.entry_points().select(group=ENCODER_ENTRY_POINTS[encoder_type])
try:
result = metadata.entry_points(group=ENCODER_ENTRY_POINTS[encoder_type])
return {val.name: val.load() for val in result}

return {}
except KeyError:
return {}


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

return {}

return {
val.name: val.load()
for val in metadata.entry_points(group="pylibjpeg.pixel_data_encoders")
}
try:
return {
val.name: val.load()
for val in metadata.entry_points(group="pylibjpeg.pixel_data_encoders")
}
except KeyError:
return {}

0 comments on commit 0a41b27

Please sign in to comment.