本文整理汇总了Python中pkg_resources.get_distribution方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.get_distribution方法的具体用法?Python pkg_resources.get_distribution怎么用?Python pkg_resources.get_distribution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.get_distribution方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_version
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def show_version():
entries = []
entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info))
version_info = discord.version_info
entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))
if version_info.releaselevel != 'final':
pkg = pkg_resources.get_distribution('discord.py')
if pkg:
entries.append(' - discord.py pkg_resources: v{0}'.format(pkg.version))
entries.append('- aiohttp v{0.__version__}'.format(aiohttp))
entries.append('- websockets v{0.__version__}'.format(websockets))
uname = platform.uname()
entries.append('- system info: {0.system} {0.release} {0.version}'.format(uname))
print('\n'.join(entries))
示例2: install_package
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def install_package(package, version="upgrade"):
from sys import executable
from subprocess import check_call
result = False
if version.lower() == "upgrade":
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
else:
from pkg_resources import get_distribution
current_package_version = None
try:
current_package_version = get_distribution(package)
except Exception:
pass
if current_package_version is None or current_package_version != version:
installation_sign = "==" if ">=" not in version else ""
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "--user"])
return result
示例3: cli
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def cli(ctx):
"""Check the latest Apio version."""
current_version = get_distribution('apio').version
latest_version = get_pypi_latest_version()
if latest_version is None:
ctx.exit(1)
if latest_version == current_version:
click.secho('You\'re up-to-date!\nApio {} is currently the '
'newest version available.'.format(latest_version),
fg='green')
else:
click.secho('You\'re not updated\nPlease execute '
'`pip install -U apio` to upgrade.',
fg="yellow")
示例4: install_scripts
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def install_scripts(distributions):
"""
Regenerate the entry_points console_scripts for the named distribution.
"""
try:
from setuptools.command import easy_install
import pkg_resources
except ImportError:
raise RuntimeError("'wheel install_scripts' needs setuptools.")
for dist in distributions:
pkg_resources_dist = pkg_resources.get_distribution(dist)
install = wheel.paths.get_install_command(dist)
command = easy_install.easy_install(install.distribution)
command.args = ['wheel'] # dummy argument
command.finalize_options()
command.install_egg_scripts(pkg_resources_dist)
示例5: create_parent_parser
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [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
示例6: install_scripts
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def install_scripts(distributions):
"""
Regenerate the entry_points console_scripts for the named distribution.
"""
try:
from setuptools.command import easy_install
import pkg_resources
except ImportError:
raise RuntimeError("'wheel install_scripts' needs setuptools.")
for dist in distributions:
pkg_resources_dist = pkg_resources.get_distribution(dist)
install = get_install_command(dist)
command = easy_install.easy_install(install.distribution)
command.args = ['wheel'] # dummy argument
command.finalize_options()
command.install_egg_scripts(pkg_resources_dist)
示例7: _get_info
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def _get_info(name):
metadata = _get_metadata(name)
version = pkg_resources.get_distribution(name).version
if metadata:
if metadata['is_release']:
released = 'released'
else:
released = 'pre-release'
sha = metadata['git_version']
else:
version_parts = version.split('.')
if version_parts[-1].startswith('g'):
sha = version_parts[-1][1:]
released = 'pre-release'
else:
sha = ""
released = "released"
for part in version_parts:
if not part.isdigit():
released = "pre-release"
return dict(name=name, version=version, sha=sha, released=released)
示例8: send_usage_stats
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def send_usage_stats():
try:
version = pkg_resources.get_distribution('target-csv').version
conn = http.client.HTTPConnection('collector.singer.io', timeout=10)
conn.connect()
params = {
'e': 'se',
'aid': 'singer',
'se_ca': 'target-csv',
'se_ac': 'open',
'se_la': version,
}
conn.request('GET', '/i?' + urllib.parse.urlencode(params))
response = conn.getresponse()
conn.close()
except:
logger.debug('Collection request failed')
示例9: get_mlperf_log
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def get_mlperf_log():
"""Shielded import of mlperf_log module."""
try:
import mlperf_compliance
def test_mlperf_log_pip_version():
"""Check that mlperf_compliance is up to date."""
import pkg_resources
version = pkg_resources.get_distribution("mlperf_compliance")
version = tuple(int(i) for i in version.version.split("."))
if version < _MIN_VERSION:
tf.compat.v1.logging.warning(
"mlperf_compliance is version {}, must be >= {}".format(
".".join([str(i) for i in version]),
".".join([str(i) for i in _MIN_VERSION])))
raise ImportError
return mlperf_compliance.mlperf_log
mlperf_log = test_mlperf_log_pip_version()
except ImportError:
mlperf_log = None
return mlperf_log
示例10: main
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def main():
arguments = docopt(
__doc__,
version="gdparse {}".format(
pkg_resources.get_distribution("gdtoolkit").version
),
)
if not isinstance(arguments, dict):
print(arguments)
sys.exit(0)
for file_path in arguments["<file>"]:
with open(file_path, "r") as fh: # TODO: handle exception
content = fh.read()
tree = parser.parse(content) # TODO: handle exception
if arguments["--pretty"]:
print(tree.pretty())
elif arguments["--verbose"]:
print(tree)
示例11: _get_version_info
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [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 _, _
示例12: __init__
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def __init__(self, args):
try:
print("gurux_dlms version: " + pkg_resources.get_distribution("gurux_dlms").version)
print("gurux_net version: " + pkg_resources.get_distribution("gurux_net").version)
print("gurux_serial version: " + pkg_resources.get_distribution("gurux_serial").version)
except Exception:
#It's OK if this fails.
print("pkg_resources not found")
settings = GXSettings()
ret = settings.getParameters(args)
if ret != 0:
return
#There might be several notify messages in GBT.
self.notify = GXReplyData()
self.client = settings.client
self.translator = GXDLMSTranslator()
self.reply = GXByteBuffer()
settings.media.trace = settings.trace
print(settings.media)
#Start to listen events from the media.
settings.media.addListener(self)
#Set EOP for the media.
if settings.client.interfaceType == InterfaceType.HDLC:
settings.media.eop = 0x7e
try:
print("Press any key to close the application.")
#Open the connection.
settings.media.open()
#Wait input.
input()
print("Closing")
except (KeyboardInterrupt, SystemExit, Exception) as ex:
print(ex)
settings.media.close()
settings.media.removeListener(self)
示例13: getPackageVersion
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def getPackageVersion(name):
"""
Get a python package version.
Returns: a string or None
"""
try:
pkg = pkg_resources.get_distribution(name)
return pkg.version
except:
return None
示例14: check_plugin_version
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def check_plugin_version(handler: APIHandler):
server_extension_version = pkg_resources.get_distribution(
"jupyterlab_code_formatter"
).version
lab_extension_version = handler.request.headers.get("Plugin-Version")
version_matches = server_extension_version == lab_extension_version
if not version_matches:
handler.set_status(
422,
f"Mismatched versions of server extension ({server_extension_version}) "
f"and lab extension ({lab_extension_version}). "
f"Please ensure they are the same.",
)
handler.finish()
return version_matches
示例15: get
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import get_distribution [as 别名]
def get(self) -> None:
"""Show what version is this server plguin on."""
self.finish(
json.dumps(
{
"version": pkg_resources.get_distribution(
"jupyterlab_code_formatter"
).version
}
)
)