[docs]classErsiliaBase(object):""" Base class of Ersilia. This class is used as a configuration for many of the classes of the package. """def__init__(self,config_json=None,credentials_json=None):self.eos_dir=EOSself.config_json=config_jsonself.credentials_json=credentials_jsonself.cfg=Config(json_file=config_json)self.cred=Credentials(json_file=credentials_json)self._lake_dir=self._abs_path(os.path.join(EOS,"isaura","lake"))self._tmp_dir=self._abs_path(os.path.join(EOS,self.cfg.LOCAL.TMP))ifnotos.path.exists(self._tmp_dir):os.makedirs(self._tmp_dir,exist_ok=True)self._dest_dir=self._abs_path(os.path.join(EOS,self.cfg.LOCAL.DEST))ifnotos.path.exists(self._dest_dir):os.makedirs(self._dest_dir,exist_ok=True)self._bentoml_dir=os.path.join(self._abs_path(os.path.join(Path.home(),"bentoml")),"repository")self._bundles_dir=os.path.join(self.eos_dir,"repository")ifnotos.path.exists(self._bundles_dir):os.makedirs(self._bundles_dir,exist_ok=True)self.logger=logger@staticmethoddef_abs_path(path):returnos.path.abspath(path)def_model_path(self,model_id):folder=os.path.join(self._dest_dir,model_id)returnfolderdef_get_latest_bentoml_tag(self,model_id):path=os.path.join(self._bentoml_dir,model_id)ifnotos.path.exists(path):returnNoneitems=sorted(os.listdir(path))ifnotitems:returnNoneelse:returnitems[-1]def_get_latest_bundle_tag(self,model_id):path=os.path.join(self._bundles_dir,model_id)ifnotos.path.exists(path):returnNoneitems=sorted(os.listdir(path))ifnotitems:returnNoneelse:returnitems[-1]def_get_bentoml_location(self,model_id):tag=self._get_latest_bentoml_tag(model_id)path=os.path.join(self._bentoml_dir,model_id)ifnotos.path.exists(path):returnNoneiftagisnotNone:returnos.path.join(path,tag)else:returnpathdef_get_bundle_location(self,model_id):tag=self._get_latest_bundle_tag(model_id)path=os.path.join(self._bundles_dir,model_id)ifnotos.path.exists(path):returnNoneiftagisnotNone:returnos.path.join(path,tag)else:returnpathdef_get_bento_location(self,model_id):bundle_path=self._get_bundle_location(model_id)ifresolve_pack_method(bundle_path)!="bentoml":returnNonecmd=["bentoml","get","%s:latest"%model_id,"--print-location","--quiet"]result=subprocess.run(cmd,stdout=subprocess.PIPE)result=result.stdout.decode("utf-8").rstrip()returnresultdef_is_ready(self,model_id):"""Check whether a model exists in the local computer"""try:self._get_latest_bundle_tag(model_id)except:returnFalsepath=os.path.join(self._abs_path(self._dest_dir),model_id)ifnotos.path.exists(path):returnFalsereturnTruedef_has_credentials(self):ifself.credisNone:returnFalsereturnTrue