本文整理匯總了Python中pkg_resources.ResolutionError方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.ResolutionError方法的具體用法?Python pkg_resources.ResolutionError怎麽用?Python pkg_resources.ResolutionError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.ResolutionError方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: is_installed
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def is_installed(requirement):
try:
pkg_resources.require(requirement)
except pkg_resources.ResolutionError:
return False
else:
return True
示例2: find_ca_bundle
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
if os.name=='nt':
return get_win_certfile()
else:
for cert_path in cert_paths:
if os.path.isfile(cert_path):
return cert_path
try:
return pkg_resources.resource_filename('certifi', 'cacert.pem')
except (ImportError, ResolutionError, ExtractionError):
return None
示例3: _certifi_where
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def _certifi_where():
try:
return __import__('certifi').where()
except (ImportError, ResolutionError, ExtractionError):
pass
示例4: find_ca_bundle
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
if os.name == 'nt':
return get_win_certfile()
else:
for cert_path in cert_paths:
if os.path.isfile(cert_path):
return cert_path
try:
return pkg_resources.resource_filename('certifi', 'cacert.pem')
except (ImportError, ResolutionError, ExtractionError):
return None
示例5: with_requires
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def with_requires(*requirements):
"""Run a test case only when given requirements are satisfied.
.. admonition:: Example
This test case runs only when `numpy>=1.10` is installed.
>>> import unittest
>>> from chainer import testing
>>> class Test(unittest.TestCase):
... @testing.with_requires('numpy>=1.10')
... def test_for_numpy_1_10(self):
... pass
Args:
requirements: A list of string representing requirement condition to
run a given test case.
"""
ws = pkg_resources.WorkingSet()
try:
ws.require(*requirements)
skip = False
except pkg_resources.ResolutionError:
skip = True
msg = 'requires: {}'.format(','.join(requirements))
return unittest.skipIf(skip, msg)
示例6: without_requires
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def without_requires(*requirements):
"""Run a test case only when given requirements are not satisfied.
.. admonition:: Example
This test case runs only when `numpy>=1.10` is not installed.
>>> from chainer import testing
... class Test(unittest.TestCase):
... @testing.without_requires('numpy>=1.10')
... def test_without_numpy_1_10(self):
... pass
Args:
requirements: A list of string representing requirement condition to
run a given test case.
"""
ws = pkg_resources.WorkingSet()
try:
ws.require(*requirements)
skip = True
except pkg_resources.ResolutionError:
skip = False
msg = 'requires: {}'.format(','.join(requirements))
return unittest.skipIf(skip, msg)
示例7: skipif_requires_satisfied
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def skipif_requires_satisfied(*requirements):
ws = pkg_resources.WorkingSet()
try:
ws.require(*requirements)
except pkg_resources.ResolutionError:
return False
return skipif(True)
示例8: with_requires
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def with_requires(*requirements):
"""Run a test case only when given requirements are satisfied.
.. admonition:: Example
This test case runs only when `numpy>=1.18` is installed.
>>> from cupy import testing
... class Test(unittest.TestCase):
... @testing.with_requires('numpy>=1.18')
... def test_for_numpy_1_18(self):
... pass
Args:
requirements: A list of string representing requirement condition to
run a given test case.
"""
# Delay import of pkg_resources because it is excruciatingly slow.
# See https://github.com/pypa/setuptools/issues/510
import pkg_resources
ws = pkg_resources.WorkingSet()
try:
ws.require(*requirements)
skip = False
except pkg_resources.ResolutionError:
skip = True
msg = 'requires: {}'.format(','.join(requirements))
return unittest.skipIf(skip, msg)
示例9: nni_info
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def nni_info(*args):
if args[0].version:
try:
print(pkg_resources.get_distribution('nni').version)
except pkg_resources.ResolutionError:
print_error('Get version failed, please use `pip3 list | grep nni` to check nni version!')
else:
print('please run "nnictl {positional argument} --help" to see nnictl guidance')
示例10: check_version
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def check_version(args):
try:
trial_keeper_version = pkg_resources.get_distribution('nni').version
except pkg_resources.ResolutionError as err:
# package nni does not exist, try nni-tool package
nni_log(LogType.Error, 'Package nni does not exist!')
os._exit(1)
if not args.nni_manager_version:
# skip version check
nni_log(LogType.Warning, 'Skipping version check!')
else:
try:
trial_keeper_version = regular.search(trial_keeper_version).group('version')
nni_log(LogType.Info, 'trial_keeper_version is {0}'.format(trial_keeper_version))
nni_manager_version = regular.search(args.nni_manager_version).group('version')
nni_log(LogType.Info, 'nni_manager_version is {0}'.format(nni_manager_version))
log_entry = {}
if trial_keeper_version != nni_manager_version:
nni_log(LogType.Error, 'Version does not match!')
error_message = 'NNIManager version is {0}, TrialKeeper version is {1}, NNI version does not match!'.format(
nni_manager_version, trial_keeper_version)
log_entry['tag'] = 'VCFail'
log_entry['msg'] = error_message
rest_post(gen_send_version_url(args.nnimanager_ip, args.nnimanager_port), json.dumps(log_entry), 10,
False)
os._exit(1)
else:
nni_log(LogType.Info, 'Version match!')
log_entry['tag'] = 'VCSuccess'
rest_post(gen_send_version_url(args.nnimanager_ip, args.nnimanager_port), json.dumps(log_entry), 10,
False)
except AttributeError as err:
nni_log(LogType.Error, err)
示例11: check_version
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import ResolutionError [as 別名]
def check_version(args):
try:
trial_runner_version = pkg_resources.get_distribution('nni').version
except pkg_resources.ResolutionError as err:
# package nni does not exist, try nni-tool package
nni_log(LogType.Error, 'Package nni does not exist!')
os._exit(1)
if not args.nni_manager_version:
# skip version check
nni_log(LogType.Warning, 'Skipping version check!')
else:
try:
command_channel = args.command_channel
trial_runner_version = regular.search(trial_runner_version).group('version')
nni_log(LogType.Info, '{0}: runner_version is {1}'.format(args.node_id, trial_runner_version))
nni_manager_version = regular.search(args.nni_manager_version).group('version')
nni_log(LogType.Info, '{0}: nni_manager_version is {1}'.format(args.node_id, nni_manager_version))
log_entry = {}
if trial_runner_version != nni_manager_version:
nni_log(LogType.Error, '{0}: Version does not match!'.format(args.node_id))
error_message = '{0}: NNIManager version is {1}, Trial runner version is {2}, NNI version does not match!'.format(
args.node_id, nni_manager_version, trial_runner_version)
log_entry['tag'] = 'VCFail'
log_entry['msg'] = error_message
command_channel.send(CommandType.VersionCheck, log_entry)
while not command_channel.sent():
time.sleep(1)
os._exit(1)
else:
nni_log(LogType.Info, '{0}: Version match!'.format(args.node_id))
log_entry['tag'] = 'VCSuccess'
command_channel.send(CommandType.VersionCheck, log_entry)
except AttributeError as err:
nni_log(LogType.Error, '{0}: {1}'.format(args.node_id, err))