-
Notifications
You must be signed in to change notification settings - Fork 9
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
smiles extra and decorator for rdkit functions #200
Conversation
return func(*args, **kwargs) | ||
return wrapper | ||
|
||
@requires_rdkit |
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.
this is not code that is actually used, right?
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.
yes, just as a reference for @boopthesnoot
alphabase/peptide/smiles.py
Outdated
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
from rdkit import Chem |
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.
is there another option to find out that the package is there, without actually importing it? this would avoid the side effect of this decorator
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.
also, this will only work if the imports are done within the functions not for top-level imports, right?
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.
You could use importlib.util.find_spec("rdkit") is not None
which still invokes the import machinery to some degree.
On the second point, I think there is no way around this.
If you have a module level import you will always fail during initialization.
Maybe it's possible with some heavy import magic but I'm not aware.
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.
okay, but can we then not just catch the import error in the smiles
module, and change it to the user-friendly error message?
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.
Yes, I prefer to catch ImportError once this module is imported
extra_requirements/smiles.txt
Outdated
@@ -0,0 +1 @@ | |||
rdkit>=2024.3.3 |
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.
fix version? :-)
What is the connection between this PR and #199 |
If smiles is imported in many other modules, i think it is better to place rdkit in the main requirement |
This allows to install rdkit only when the smiles extra is defined.
All RDKit dependent functions will give a meaningfull error message if called: