-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make a processing extra with optional dependencies
- Loading branch information
Showing
7 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,7 @@ | |
"split": False, | ||
"cli": False, | ||
"ligand": False, | ||
"extra": False, | ||
} | ||
__docformat__ = "numpy" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Handling optional dependencies.""" | ||
|
||
try: | ||
import py3Dmol | ||
except ImportError: | ||
pass | ||
|
||
import sys | ||
|
||
|
||
def requires_extra(module_name, install_name=None): | ||
"""Generate a decorator to require an optional dependency for the given function. | ||
Parameters | ||
---------- | ||
module_name : str | ||
Name of the module to check for | ||
install_name : str, optional | ||
Name of the module to install if it is not found. If not specified, `module_name` is used | ||
""" | ||
if install_name is None: | ||
install_name = module_name | ||
|
||
def decorator(func): | ||
def wrapper(*args, **kwargs): | ||
if module_name not in sys.modules: | ||
raise ImportError( | ||
f"{install_name} must be installed to use this function. " | ||
f"Install it with `pip install {install_name}` or together with most other optional dependencies with `pip install proteinflow[processing]`." | ||
) | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator | ||
|
||
|
||
@requires_extra("py3Dmol") | ||
def _get_view(canvas_size): | ||
return py3Dmol.view(width=canvas_size[0], height=canvas_size[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters