Skip to content

Commit

Permalink
fix: always use resolved stored data_plugin path
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Jun 7, 2023
1 parent b8c7560 commit 1bdd2e2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions biothings/hub/dataplugin/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import json
import os
import pathlib
import pprint
import re
import subprocess
Expand Down Expand Up @@ -129,31 +130,39 @@ def _dict_for_docker(self, data_url):

def can_load_plugin(self):
plugin = self.get_plugin_obj()
df = plugin["download"]["data_folder"]
if "manifest.json" in os.listdir(df) and os.path.exists(os.path.join(df, "manifest.json")):
df = pathlib.Path(plugin["download"]["data_folder"])
# if "manifest.json" in os.listdir(df) and os.path.exists(os.path.join(df, "manifest.json")):
if pathlib.Path(df, "manifest.json").exists():
return True
elif "manifest.yaml" in os.listdir(df) and os.path.exists(os.path.join(df, "manifest.yaml")):
# elif "manifest.yaml" in os.listdir(df) and os.path.exists(os.path.join(df, "manifest.yaml")):
elif pathlib.Path(df, "manifest.yaml").exists():
return True
else:
return False

def load_plugin(self):
plugin = self.get_plugin_obj()
df = plugin["download"]["data_folder"]
self.plugin_path_name = os.path.basename(df)
if os.path.exists(df):
mf = os.path.join(df, "manifest.json")
mf_yaml = os.path.join(df, "manifest.yaml")
df = pathlib.Path(plugin["download"]["data_folder"])
# self.plugin_path_name = os.path.basename(df)
self.plugin_path_name = df.name
# if os.path.exists(df):
if df.exists():
# mf = os.path.join(df, "manifest.json")
# mf_yaml = os.path.join(df, "manifest.yaml")
mf = pathlib.Path(df, "manifest.json")
mf_yaml = pathlib.Path(df, "manifest.yaml")
manifest = None
if os.path.exists(mf):
# if os.path.exists(mf):
if mf.exists():
self.logger.debug(f"Loading manifest: {mf}")
manifest = json.load(open(mf))
elif os.path.exists(mf_yaml):
# elif os.path.exists(mf_yaml):
elif mf_yaml.exists():
self.logger.debug(f"Loading manifest: {mf_yaml}")
manifest = yaml.safe_load(open(mf_yaml))
if manifest:
try:
self.interpret_manifest(manifest, df)
self.interpret_manifest(manifest, df.as_posix())
except Exception as e:
self.invalidate_plugin("Error loading manifest: %s" % str(e))
else:
Expand Down Expand Up @@ -619,7 +628,7 @@ def loader(self):
loader = klass(self.plugin_name)
if loader.can_load_plugin():
self._loader = loader
self.logger.info("For plugin '%s', selecting loader %s" % (self.plugin_name, self._loader))
self.logger.debug("For plugin '%s', selecting loader %s" % (self.plugin_name, self._loader))
self.register_loader()
break
else:
Expand Down

0 comments on commit 1bdd2e2

Please sign in to comment.