本文整理匯總了Python中pkg_resources.DistributionNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.DistributionNotFound方法的具體用法?Python pkg_resources.DistributionNotFound怎麽用?Python pkg_resources.DistributionNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.DistributionNotFound方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tests_flatten_egginfo_json_missing_deps
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def tests_flatten_egginfo_json_missing_deps(self):
"""
Missing dependencies should not cause a hard failure.
"""
make_dummy_dist(self, (
('requires.txt', '\n'.join([
'uilib>=1.0',
])),
), 'app', '2.0')
working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir])
# Python dependency acquisition failures should fail hard.
with self.assertRaises(pkg_resources.DistributionNotFound):
calmjs_dist.flatten_egginfo_json(['app'], working_set=working_set)
示例2: register_entrypoints
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def register_entrypoints(self):
"""Look through the `setup_tools` `entry_points` and load all of
the formats.
"""
for spec in iter_entry_points(self.entry_point_group):
format_properties = {"name": spec.name}
try:
format_properties.update(spec.load())
except (DistributionNotFound, ImportError) as err:
self.log.info(
"ipymd format {} could not be loaded: {}".format(
spec.name, err))
continue
self.register(**format_properties)
return self
示例3: test_get_version_setup
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def test_get_version_setup(self):
def mock1(*args, **kwargs):
raise OSError
try:
backup1 = subprocess.check_output
except AttributeError:
backup1 = None
subprocess.check_output = mock1
def mock2(*args, **kwargs):
raise pkg_resources.DistributionNotFound
backup2 = pkg_resources.require
pkg_resources.require = mock2
try:
self.assertEquals("0.0.0-unversioned", _get_version_setup())
finally:
if backup1:
subprocess.check_output = backup1
pkg_resources.require = backup2
示例4: create_parent_parser
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def create_parent_parser(prog_name):
parent_parser = argparse.ArgumentParser(prog=prog_name, add_help=False)
parent_parser.add_argument(
'-v', '--verbose',
action='count',
help='enable more verbose output')
try:
version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version
except pkg_resources.DistributionNotFound:
version = 'UNKNOWN'
parent_parser.add_argument(
'-V', '--version',
action='version',
version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}')
.format(version),
help='display version information')
return parent_parser
示例5: _get_version_from_pkg_resources
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
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)
示例6: _get_version_info
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def _get_version_info(self, modname, all_dist_info):
try:
dist_info = pkg_resources.get_distribution(modname)
return dist_info.project_name, dist_info.version
except pkg_resources.DistributionNotFound:
ml = modname.split('.')
if len(ml) > 1:
modname = '.'.join(ml[:-1])
return self._get_version_info(modname, all_dist_info)
else:
tmod = modname.split('.')[0]
x = [
(i['project_name'], i['version'])
for i in all_dist_info if tmod in i['mods']
]
if x:
return x[0]
else:
return _, _
示例7: __call__
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def __call__(self):
"""Executes the wrapped function and catch common exceptions"""
try:
self.function()
except (IOError, ValueError, OSError,
RuntimeError, AssertionError) as err:
self.exit('fatal error: {}'.format(err))
except pkg_resources.DistributionNotFound:
self.exit(
'fatal error: phonemizer package not found\n'
'please install phonemizer on your system')
except KeyboardInterrupt:
self.exit('keyboard interruption, exiting')
示例8: check_requirements
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def check_requirements():
if sys.version_info < PYTHON_VERSION:
raise SystemExit('Python version %d.%d required; found %d.%d.'
% (PYTHON_VERSION[0], PYTHON_VERSION[1],
sys.version_info[0], sys.version_info[1]))
for package_name, min_version in DEPENDENCIES.items():
dep_err = False
try:
package_version = pkg_resources.require(package_name)[0].version
except pkg_resources.DistributionNotFound:
dep_err = True
else:
package_version = get_package_version(package_version)
if not dep_err:
if min_version > package_version:
dep_err = True
if dep_err:
raise ImportError('`%s` version %d.%d or later required.'
% ((package_name, ) + min_version))
示例9: test_returns_default_info_when_given_bad_file_name
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def test_returns_default_info_when_given_bad_file_name(self, mock_dist):
def not_installed(x):
raise pkg_resources.DistributionNotFound
mock_dist.side_effect = not_installed
info = ciftify.config.ciftify_version('some-file-that-doesnt-exist')
assert info
assert self.ciftify_path in info
assert 'Commit:' in info
assert 'Last commit for' not in info
示例10: test_returns_default_info_when_no_file_provided
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def test_returns_default_info_when_no_file_provided(self, mock_dist):
def not_installed(x):
raise pkg_resources.DistributionNotFound
mock_dist.side_effect = not_installed
info = ciftify.config.ciftify_version()
assert info
assert self.ciftify_path in info
assert 'Commit:' in info
assert 'Last commit for' not in info
示例11: test_returns_path_only_when_git_log_cant_be_found
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def test_returns_path_only_when_git_log_cant_be_found(self, mock_log,
mock_dist):
mock_log.return_value = ''
def not_installed(x):
raise pkg_resources.DistributionNotFound
mock_dist.side_effect = not_installed
info = ciftify.config.ciftify_version()
assert info
assert self.ciftify_path in info
assert "Commit:" not in info
示例12: use_setuptools
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=DEFAULT_SAVE_DIR, download_delay=15):
"""
Ensure that a setuptools version is installed.
Return None. Raise SystemExit if the requested version
or later cannot be installed.
"""
to_dir = os.path.abspath(to_dir)
# prior to importing, capture the module state for
# representative modules.
rep_modules = 'pkg_resources', 'setuptools'
imported = set(sys.modules).intersection(rep_modules)
try:
import pkg_resources
pkg_resources.require("setuptools>=" + version)
# a suitable version is already installed
return
except ImportError:
# pkg_resources not available; setuptools is not installed; download
pass
except pkg_resources.DistributionNotFound:
# no version of setuptools was found; allow download
pass
except pkg_resources.VersionConflict as VC_err:
if imported:
_conflict_bail(VC_err, version)
# otherwise, unload pkg_resources to allow the downloaded version to
# take precedence.
del pkg_resources
_unload_pkg_resources()
return _do_download(version, download_base, to_dir, download_delay)
示例13: get_version
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def get_version():
try:
return pkg_resources.get_distribution('apsconnectcli').version
except pkg_resources.DistributionNotFound:
return bin_version()
示例14: test_get_version_from_package_error
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def test_get_version_from_package_error(self):
with patch('apsconnectcli.apsconnect.pkg_resources') as pkg_mock, \
patch('apsconnectcli.apsconnect.bin_version') as bin_mock:
bin_mock.return_value = 'v100500'
pkg_mock.DistributionNotFound = DistributionNotFound
pkg_mock.get_distribution.side_effect = DistributionNotFound()
result = get_version()
self.assertEqual(result, 'v100500')
示例15: distribution_version
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import DistributionNotFound [as 別名]
def distribution_version(name):
"""try to get the version of the named distribution,
returs None on failure"""
from pkg_resources import get_distribution, DistributionNotFound
try:
dist = get_distribution(name)
except DistributionNotFound:
pass
else:
return dist.version