-
Notifications
You must be signed in to change notification settings - Fork 47
fix: use rai without rai_interfaces #608
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
Conversation
99e8763
to
736064b
Compare
# limitations under the License. | ||
|
||
import importlib.util | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from importlib.machinery import ModuleSpec |
import importlib.util | ||
|
||
|
||
def safe_find_spec(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def safe_find_spec(name): | |
def safe_find_spec(name: str) -> ModuleSpec | None: |
|
||
def safe_find_spec(name): | ||
try: | ||
return importlib.util.find_spec(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with python3.10 and python 3.13 and errors are not raised... When did you encounter this error?
>>> importlib.util.find_spec('aaa')
>>> importlib.util.find_spec('numpy')
ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x10d9b69e0>, origin='/usr/local/lib/python3.10/site-packages/numpy/__init__.py', submodule_search_locations=['/usr/local/lib/python3.10/site-packages/numpy'])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try aaa.aaa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I think we should rewrite all find_spec('rai_interfaces.*') to find_spec('rai_interfaces'). This way we will mitigate the problem without introducing custom safe_find_spec
736064b
to
fa60526
Compare
@boczekbartek I've refactored the solution to this problem to a mere two line changes (removing the submodule part of the rai_interfaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! LGTM
Purpose
While testing RAI installed with pip, I've come across a problem when running a very simple example:
Proposed Changes
Implements
safe_find_spec
to catch an error if package cannot be imported.Issues
#607
Testing