本文整理匯總了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方法的25個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: install_package
點讚 6
# 需要導入模塊: 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
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:19,
示例2: show_version
點讚 6
# 需要導入模塊: 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))
開發者ID:Rapptz,項目名稱:discord.py,代碼行數:18,
示例3: cli
點讚 6
# 需要導入模塊: 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")
開發者ID:FPGAwars,項目名稱:apio,代碼行數:19,
示例4: install_scripts
點讚 6
# 需要導入模塊: 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)
開發者ID:jpush,項目名稱:jbox,代碼行數:19,
示例5: create_parent_parser
點讚 6
# 需要導入模塊: 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
開發者ID:hyperledger,項目名稱:sawtooth-core,代碼行數:22,
示例6: install_scripts
點讚 6
# 需要導入模塊: 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)
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,
示例7: _get_info
點讚 6
# 需要導入模塊: 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)
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:23,
示例8: send_usage_stats
點讚 6
# 需要導入模塊: 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')
開發者ID:singer-io,項目名稱:target-csv,代碼行數:19,
示例9: get_mlperf_log
點讚 6
# 需要導入模塊: 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
開發者ID:IntelAI,項目名稱:models,代碼行數:26,
示例10: main
點讚 6
# 需要導入模塊: 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[""]:
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)
開發者ID:Scony,項目名稱:godot-gdscript-toolkit,代碼行數:22,
示例11: _get_version_info
點讚 6
# 需要導入模塊: 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 _, _
開發者ID:crew102,項目名稱:reprexpy,代碼行數:21,
示例12: __init__
點讚 5
# 需要導入模塊: 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)
開發者ID:Gurux,項目名稱:Gurux.DLMS.Python,代碼行數:39,
示例13: getPackageVersion
點讚 5
# 需要導入模塊: 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
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:13,
示例14: check_plugin_version
點讚 5
# 需要導入模塊: 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
開發者ID:ryantam626,項目名稱:jupyterlab_code_formatter,代碼行數:17,
示例15: get
點讚 5
# 需要導入模塊: 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
}
)
)
開發者ID:ryantam626,項目名稱:jupyterlab_code_formatter,代碼行數:13,
示例16: _create_headers
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def _create_headers(
self, plugin_version: t.Optional[str] = None
) -> t.Dict[str, str]:
return {
"Plugin-Version": plugin_version
if plugin_version is not None
else pkg_resources.get_distribution("jupyterlab_code_formatter").version
}
開發者ID:ryantam626,項目名稱:jupyterlab_code_formatter,代碼行數:10,
示例17: update_available
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def update_available(package_name):
packages = [dist.project_name for dist in pkg_resources.working_set]
if package_name not in packages:
dprint(f"The package: [{package_name}] is not a dependency of this software.", origin=L_DEPENDENCIES)
return None
vers = check_pypi_version(package_name)
if vers is not None:
dprint(f"{package_name} available: {vers}", origin=L_DEPENDENCIES)
dprint(f"{package_name} current: {pkg_resources.get_distribution(package_name).version}", origin=L_DEPENDENCIES)
if vers != pkg_resources.get_distribution(package_name).version:
dprint(f"There is a newer version of: [{package_name}({vers})] available.", origin=L_DEPENDENCIES)
return True
return False
開發者ID:DuckBoss,項目名稱:JJMumbleBot,代碼行數:15,
示例18: check_and_update
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def check_and_update(package_name, pip_cmd):
vers = check_pypi_version(package_name)
if vers != pkg_resources.get_distribution(package_name).version:
dprint(f"There is a newer version of: [{package_name}({vers})] available. Updating...", origin=L_DEPENDENCIES)
if update_package(package_name, pip_cmd):
return vers
return None
開發者ID:DuckBoss,項目名稱:JJMumbleBot,代碼行數:9,
示例19: get_version
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def get_version():
try:
return pkg_resources.get_distribution('apsconnectcli').version
except pkg_resources.DistributionNotFound:
return bin_version()
開發者ID:cloudblue,項目名稱:apsconnect-cli,代碼行數:7,
示例20: version
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def version():
"""Print version information."""
import pkg_resources
lavatory_version = pkg_resources.get_distribution('lavatory').version
click.echo(lavatory_version)
開發者ID:gogoair,項目名稱:lavatory,代碼行數:7,
示例21: versions
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def versions(self):
"""Access versions."""
with self._client() as podman:
vers = podman.GetVersion()
client = '0.0.0'
try:
client = pkg_resources.get_distribution('podman').version
except Exception: # pylint: disable=broad-except
pass
vers['client_version'] = client
return collections.namedtuple('Version', vers.keys())(**vers)
開發者ID:containers,項目名稱:python-podman,代碼行數:14,
示例22: test_import_about
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def test_import_about():
from custodia import __about__
assert __about__.__title__ == 'custodia'
dist = pkg_resources.get_distribution('custodia')
assert dist.version == __about__.__version__ # pylint: disable=no-member
開發者ID:latchset,項目名稱:custodia,代碼行數:8,
示例23: distribution_version
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [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
開發者ID:pytest-dev,項目名稱:py,代碼行數:12,
示例24: __init__
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def __init__(self):
super().__init__()
self.__version = {"current_version": get_distribution('thingsboard_gateway').version,
"latest_version": None}
self.__instance_id = str(uuid1())
self.__platform = "deb"
self.__os_version = platform()
self.__previous_check = 0
self.__check_period = 3600.0
self.__request_timeout = 5
self.__stopped = True
self.start()
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:14,
示例25: _get_moler_version
點讚 5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import get_distribution [as 別名]
def _get_moler_version():
setup_py_path = os.path.join(os.path.dirname(__file__), "..", "..", "setup.py")
if "site-packages" in setup_py_path:
try:
return pkg_resources.get_distribution("moler").version
except pkg_resources.DistributionNotFound:
return _get_moler_version_cloned_from_git_repository(setup_py_path)
else:
return _get_moler_version_cloned_from_git_repository(setup_py_path)
開發者ID:nokia,項目名稱:moler,代碼行數:12,
注:本文中的pkg_resources.get_distribution方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。