Skip to content

Commit

Permalink
update: builder func and create plugin func with env var
Browse files Browse the repository at this point in the history
-  update plugin builder to look for external plugin in `OPENVAR_PLUGIN`
-  update create plugin function to use env_var by default
- Add `loadEnvironmentVariables()` so plugin tests do not fail.
  • Loading branch information
FedericaBrando committed Mar 12, 2024
1 parent 0dd8449 commit 7b5cb71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions openvariant/annotation/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ def _plugin_builder(x: dict, base_path: str = None) -> PluginBuilder:
ctxt = _get_plugin_context(mod)
except ModuleNotFoundError:
try:
files = list(glob.iglob(f"{os.getcwd()}/**/{x[AnnotationTypes.PLUGIN.value]}", recursive=True))
files = list(glob.iglob(f"{os.environ['OPENVAR_PLUGIN']}/**/{x[AnnotationTypes.PLUGIN.value]}", recursive=True))
if len(files) == 0:
raise FileNotFoundError(f"Unable to find '{x[AnnotationTypes.PLUGIN.value]}' plugin in '{os.getcwd()}'")
raise FileNotFoundError(f"Unable to find '{x[AnnotationTypes.PLUGIN.value]}' plugin in '{os.environ['OPENVAR_PLUGIN']}'")
else:
try:
for package in files:
Expand All @@ -263,7 +263,7 @@ def _plugin_builder(x: dict, base_path: str = None) -> PluginBuilder:
func = _get_plugin_function(mod)
ctxt = _get_plugin_context(mod)
except (ImportError, AttributeError):
raise ImportError(f"Unable to import 'run' on the plugin.")
raise ImportError("Unable to import 'run' on the plugin.")
except ModuleNotFoundError:
raise ModuleNotFoundError(f"Unable to found '{x[AnnotationTypes.PLUGIN.value]}' plugin.")
except (ImportError, AttributeError) as e:
Expand Down
4 changes: 2 additions & 2 deletions openvariant/tasks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial


def _add_action(name: str, directory: str = None) -> None:
def _add_action(name: str) -> None:
"""Create a new plugin
It will generate all the required structure for a new plugin (files and folders).
Expand All @@ -20,7 +20,7 @@ def _add_action(name: str, directory: str = None) -> None:
directory : str
The path to create the plugin.
"""
path = directory if directory is not None else os.getcwd()
path = os.environ['OPENVAR_PLUGIN']
if os.path.exists(f"{path}/{name}"):
raise FileExistsError(f"Directory {path}/{name} already exists.")
os.mkdir(f"{path}/{name}")
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from openvariant.utils.utils import loadEnvironmentVariables

loadEnvironmentVariables()

0 comments on commit 7b5cb71

Please sign in to comment.