def get(self, name, **kwargs): """ Load package from store, install it locally and load. :param name: the name of the package :param kwargs: :return: the loaded module """ pkgname = basename(name) meta = self.data_store.metadata(name) dstdir = self.packages_path pip_source = meta.kind_meta['pip_source'] # pip does not know about pypi pip_name = pip_source.replace('pypi://', '') mod = install_and_import(pip_name, pkgname, dstdir) return mod
def get(self, name, **kwargs): """ Load package from store, install it locally and load. :param name: the name of the package :param kwargs: :return: the loaded module """ packagefname = '{}.tar.gz'.format( os.path.join(self.data_store.tmppath, name)) dstdir = self.packages_path if not os.path.exists(os.path.join(dstdir, name)): filename = self.data_store._get_obj_store_key(name, '.pkg') outf = self.data_store.fs.get_version(filename) with open(packagefname, 'wb') as pkgf: pkgf.write(outf.read()) mod = install_and_import(packagefname, name, dstdir) else: mod = load_from_path(name, dstdir) return mod
def get(self, name, keep=False, **kwargs): """ Load package from store, install it locally and load. This runs `pip install <package spec>`, taking the package specification from Metadata.kind_meta['pip-source']. See the put() method for details. :param name: the name of the package :param keep: keep the packages load path in sys.path, defaults to False :param kwargs: :return: the loaded module """ pkgname = basename(name) meta = self.data_store.metadata(name) dstdir = self.packages_path pip_source = meta.kind_meta['pip_source'] # pip does not know about pypi pip_name = pip_source.replace('pypi://', '') mod = install_and_import(pip_name, pkgname, dstdir, keep=keep) return mod
def get(self, name, **kwargs): """ Load package from store, install it locally and load. :param name: the name of the package :param kwargs: :return: the loaded module """ pkgname = basename(name) packagefname = '{}.tar.gz'.format(os.path.join(self.data_store.tmppath, pkgname)) os.makedirs(dirname(packagefname), exist_ok=True) self.path = self.packages_path dstdir = self.path if not os.path.exists(os.path.join(dstdir, pkgname)): meta = self.data_store.metadata(name) outf = meta.gridfile with open(packagefname, 'wb') as pkgf: pkgf.write(outf.read()) mod = install_and_import(packagefname, pkgname, dstdir) else: mod = load_from_path(pkgname, dstdir) return mod
def get(self, name, localpath=None, keep=False, install=True, **kwargs): """ Load package from store, install it locally and load. This copies the package's .tar.gz file from om.scripts to a local temp path and runs `pip install` on it. :param name: the name of the package :param keep: keep the packages load path in sys.path, defaults to False :param localpath: the local path to store the package :param install: if True call pip install on the retrieved package :param kwargs: :return: the loaded module """ pkgname = basename(name) packagefname = '{}.tar.gz'.format( os.path.join(localpath or self.data_store.tmppath, pkgname)) os.makedirs(dirname(packagefname), exist_ok=True) self.path = self.packages_path dstdir = localpath or self.path if not os.path.exists(os.path.join(dstdir, pkgname)): meta = self.data_store.metadata(name) outf = meta.gridfile with open(packagefname, 'wb') as pkgf: pkgf.write(outf.read()) if install: mod = install_and_import(packagefname, pkgname, dstdir, keep=keep) else: mod = packagefname elif install: mod = load_from_path(pkgname, dstdir, keep=keep) else: mod = os.path.join(dstdir, pkgname) return mod