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

Bug entry point #818

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion physicsnemo/registry/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

import warnings
from importlib.metadata import EntryPoint, entry_points

# NOTE: This is for backport compatibility, some entry points seem to be using this old class
# Exact cause of this is unknown but it seems to be related to multiple versions
# of importlib being present in the environment
from importlib_metadata import EntryPoint as EntryPointOld
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we avoid this import from importlib_metadata? This has been deprecated in the newer versions of Python

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a small comment explaining what this is, why it here?
We will forget in a month.

importlib_metadata is a back port of new APIs for previous python vesions, also users dont necessarily need this installed. If it happens to be installed, we should check it.

Or does this come with base python (I dont think so but maybe)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Best guess is somehow older versions of importlib are getting being used and some how this impacts the return type on entry_points

Copy link
Collaborator

@NickGeneva NickGeneva Mar 20, 2025

Choose a reason for hiding this comment

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

What about this solution?

sphinx-doc/sphinx#10157 (comment)

NVM this one wont work...


from typing import List, Union

import physicsnemo
Expand Down Expand Up @@ -120,8 +126,10 @@ def factory(self, name: str) -> "physicsnemo.Module":

model = self._model_registry.get(name)
if model is not None:
if isinstance(model, EntryPoint):
if isinstance(model, EntryPoint) or isinstance(model, EntryPointOld):
model = model.load()
else:
raise TypeError(f"Model {name} is not a valid entry point.")
return model

raise KeyError(f"No model is registered under the name {name}")
Expand Down