Skip to content

Fix entry_points deprecation #1233

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

Merged
merged 5 commits into from
Jan 27, 2022
Merged
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
18 changes: 10 additions & 8 deletions can/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
try:
from importlib.metadata import entry_points

entry = entry_points()
if "can.interface" in entry:
BACKENDS.update(
{
interface.name: tuple(interface.value.split(":"))
for interface in entry["can.interface"]
}
)
try:
entries = entry_points(group="can.interface")
except TypeError:
# Fallback for Python <3.10
# See https://docs.python.org/3/library/importlib.metadata.html#entry-points, "Compatibility Note"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use importlib_metadata from PyPI as fallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also be possible, yep.
As it's just so little effort, I thought it's simpler to just handle the fallback here.

entries = entry_points().get("can.interface", [])

BACKENDS.update(
{interface.name: tuple(interface.value.split(":")) for interface in entries}
)
except ImportError:
from pkg_resources import iter_entry_points
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not for long, see #1234. 😃


Expand Down