Python pkg_resources.get_provider() Examples
The following are 9
code examples of pkg_resources.get_provider().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pkg_resources
, or try the search function
.
Example #1
Source File: version.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _get_version_from_pkg_resources(self): """Obtain a version from pkg_resources or setup-time logic if missing. This will try to get the version of the package from the pkg_resources record associated with the package, and if there is no such record falls back to the logic sdist would use. """ try: requirement = pkg_resources.Requirement.parse(self.package) provider = pkg_resources.get_provider(requirement) result_string = provider.version except pkg_resources.DistributionNotFound: # The most likely cause for this is running tests in a tree # produced from a tarball where the package itself has not been # installed into anything. Revert to setup-time logic. from pbr import packaging result_string = packaging.get_version(self.package) return SemanticVersion.from_pip_string(result_string)
Example #2
Source File: version.py From keras-lambda with MIT License | 6 votes |
def _get_version_from_pkg_resources(self): """Obtain a version from pkg_resources or setup-time logic if missing. This will try to get the version of the package from the pkg_resources record associated with the package, and if there is no such record falls back to the logic sdist would use. """ try: requirement = pkg_resources.Requirement.parse(self.package) provider = pkg_resources.get_provider(requirement) result_string = provider.version except pkg_resources.DistributionNotFound: # The most likely cause for this is running tests in a tree # produced from a tarball where the package itself has not been # installed into anything. Revert to setup-time logic. from pbr import packaging result_string = packaging.get_version(self.package) return SemanticVersion.from_pip_string(result_string)
Example #3
Source File: shared_data.py From recruit with Apache License 2.0 | 5 votes |
def get_package_loader(self, package, package_path): from pkg_resources import DefaultProvider, ResourceManager, get_provider loadtime = datetime.utcnow() provider = get_provider(package) manager = ResourceManager() filesystem_bound = isinstance(provider, DefaultProvider) def loader(path): if path is None: return None, None path = posixpath.join(package_path, path) if not provider.has_resource(path): return None, None basename = posixpath.basename(path) if filesystem_bound: return ( basename, self._opener(provider.get_resource_filename(manager, path)), ) s = provider.get_resource_string(manager, path) return basename, lambda: (BytesIO(s), loadtime, len(s)) return loader
Example #4
Source File: loaders.py From pipenv with MIT License | 5 votes |
def __init__(self, package_name, package_path="templates", encoding="utf-8"): from pkg_resources import DefaultProvider from pkg_resources import get_provider from pkg_resources import ResourceManager provider = get_provider(package_name) self.encoding = encoding self.manager = ResourceManager() self.filesystem_bound = isinstance(provider, DefaultProvider) self.provider = provider self.package_path = package_path
Example #5
Source File: shared_data.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def get_package_loader(self, package, package_path): from pkg_resources import DefaultProvider, ResourceManager, get_provider loadtime = datetime.utcnow() provider = get_provider(package) manager = ResourceManager() filesystem_bound = isinstance(provider, DefaultProvider) def loader(path): if path is None: return None, None path = posixpath.join(package_path, path) if not provider.has_resource(path): return None, None basename = posixpath.basename(path) if filesystem_bound: return ( basename, self._opener(provider.get_resource_filename(manager, path)), ) s = provider.get_resource_string(manager, path) return basename, lambda: (BytesIO(s), loadtime, len(s)) return loader
Example #6
Source File: shared_data.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def get_package_loader(self, package, package_path): from pkg_resources import DefaultProvider, ResourceManager, get_provider loadtime = datetime.utcnow() provider = get_provider(package) manager = ResourceManager() filesystem_bound = isinstance(provider, DefaultProvider) def loader(path): if path is None: return None, None path = posixpath.join(package_path, path) if not provider.has_resource(path): return None, None basename = posixpath.basename(path) if filesystem_bound: return ( basename, self._opener(provider.get_resource_filename(manager, path)), ) s = provider.get_resource_string(manager, path) return basename, lambda: (BytesIO(s), loadtime, len(s)) return loader
Example #7
Source File: shared_data.py From scylla with Apache License 2.0 | 5 votes |
def get_package_loader(self, package, package_path): from pkg_resources import DefaultProvider, ResourceManager, get_provider loadtime = datetime.utcnow() provider = get_provider(package) manager = ResourceManager() filesystem_bound = isinstance(provider, DefaultProvider) def loader(path): if path is None: return None, None path = posixpath.join(package_path, path) if not provider.has_resource(path): return None, None basename = posixpath.basename(path) if filesystem_bound: return ( basename, self._opener(provider.get_resource_filename(manager, path)), ) s = provider.get_resource_string(manager, path) return basename, lambda: (BytesIO(s), loadtime, len(s)) return loader
Example #8
Source File: base.py From pyrocore with GNU General Public License v2.0 | 5 votes |
def __init__(self): """ Initialize CLI. """ self.startup = time.time() self.LOG = pymagic.get_class_logger(self) # Get version number self.version = self.VERSION if not self.version: # Take version from package provider = pkg_resources.get_provider(__name__) pkg_meta = (provider.get_metadata("PKG-INFO") or provider.get_metadata("METADATA") or self._get_pkg_meta()) pkg_dict = dict(line.split(": ", 1) for line in pkg_meta.splitlines() if ": " in line ) self.version = pkg_dict.get("Version", "DEV") where = os.path.commonprefix([__file__, os.path.realpath(sys.argv[0]), sys.prefix]) where = re.sub('^' + os.path.expanduser('~') + os.sep, '~' + os.sep, where + os.sep).rstrip(os.sep) self.version_info = '{}{}{} on Python {}'.format( self.version, ' from ' if where else '', where, sys.version.split()[0]) self.args = None self.options = None self.return_code = 0 self.parser = OptionParser( "%prog [options] " + self.ARGS_HELP + "\n\n" "%prog " + self.version_info + ('\n' + self.COPYRIGHT if self.COPYRIGHT else "") + "\n\n" + textwrap.dedent(self.__doc__.rstrip()).lstrip('\n') + '\n'.join(self.ADDITIONAL_HELP) + "\n\nFor more details, see the full documentation at" + "\n\n https://pyrocore.readthedocs.io/", version="%prog " + self.version_info)
Example #9
Source File: __init__.py From em-slack-tableflip with MIT License | 5 votes |
def set_project_info(): """Set project information from setup tools installation.""" # CUSTOMIZE THIS VALUE FOR YOUR OWN INSTALLATION base_url = 'https://slack-tableflip.herokuapp.com' # Get app info from the dist app_name = 'slack_tableflip' provider = get_provider(app_name) return { 'name': app_name, 'name_full': 'EM Slack Tableflip', 'author_url': 'http://www.erinmorelli.com', 'github_url': 'https://github.com/ErinMorelli/em-slack-tableflip', 'version': '1.10', 'version_int': 1.10, 'package_path': provider.module_path, 'copyright': '2015-{0}'.format(str(date.today().year)), 'client_secret': os.environ['SLACK_CLIENT_SECRET'], 'client_id': os.environ['SLACK_CLIENT_ID'], 'base_url': base_url, 'oauth_url': 'https://slack.com/oauth/authorize', 'auth_url': '{0}/authenticate'.format(base_url), 'user_url': '{0}/validate'.format(base_url), 'team_url': '{0}/authorize'.format(base_url), 'team_scope': [ 'commands' ], 'user_scope': [ 'chat:write:bot', 'chat:write:user', 'identify' ] } # Project info