我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用pkg_resources.get_provider()。
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)
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. """ # Lazy import because pkg_resources is costly to import so defer until # we absolutely need it. import pkg_resources 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)
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) return 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 return packaging.get_version(self.package)
def test_redocjs_lib_is_copied(sphinxdocs): srcdir, outdir = sphinxdocs extdir = py.path.local( pkg_resources.get_provider('sphinxcontrib.redoc').module_path) assert outdir.join('_static', 'redoc.js').check() assert outdir.join('_static', 'redoc.js').computehash() \ == extdir.join('redoc.js').computehash()
def get_yt_version(): try: from yt.__hg_version__ import hg_version return hg_version except ImportError: pass import pkg_resources yt_provider = pkg_resources.get_provider("yt") path = os.path.dirname(yt_provider.module_path) version = get_git_version(path) if version is None: return version else: return version[:12].strip().decode('utf-8')
def __call__(self, opts): import pkg_resources yt_provider = pkg_resources.get_provider("yt") path = os.path.dirname(yt_provider.module_path) vstring = _print_installation_information(path) if vstring is not None: print("This installation CAN be automatically updated.") if opts.update_source: update_hg_or_git(path) elif opts.update_source: _print_failed_source_update() if vstring is not None and opts.outputfile is not None: open(opts.outputfile, "w").write(vstring)
def __call__(self, opts): import pkg_resources yt_provider = pkg_resources.get_provider("yt") path = os.path.dirname(yt_provider.module_path) vstring = _print_installation_information(path) if vstring is not None: print() print("This installation CAN be automatically updated.") update_hg_or_git(path) else: _print_failed_source_update(opts.reinstall)