Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Python < 3.10 #76

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
Loading