本文整理汇总了Python中pkg_resources.safe_version方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.safe_version方法的具体用法?Python pkg_resources.safe_version怎么用?Python pkg_resources.safe_version使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.safe_version方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def run(self):
metadata = self.distribution.metadata
project_name = metadata.get_name()
version = safe_version(metadata.get_version())
print("Collecting artifacts for %s==%s in 'dist' folder:" %
(project_name, version))
dist_files = []
for filename in os.listdir('dist'):
try:
_, file_version, pyversion, command = parse_filename(
filename, project_name=project_name)
if file_version != version:
continue
except ValueError:
continue
filepath = os.path.join('dist', filename)
dist_files.append((command, pyversion, filepath))
if not dist_files:
raise DistutilsOptionError(
"No file collected from the 'dist' folder")
for command, pyversion, filepath in dist_files:
self.upload_file(command, pyversion, filepath)
示例2: _parse_exe_filename
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def _parse_exe_filename(basename, project_name=None, return_tags=True):
remainder, pythontag = basename.rsplit('-', 1)
if not pythontag.startswith('py'):
# There was no python tag with this file, therefore it must be
# python version independent
pythontag = 'py' + '.'.join(str(x) for x in sys.version_info[:2])
remainder = basename
name_and_version, platform = remainder.rsplit('.', 1)
distname, version = name_and_version.rsplit('-', 1)
distname = _wheel_escape(distname)
if project_name is not None and distname != _wheel_escape(project_name):
raise ValueError('File %s.exe does not match project name %s'
% (basename, project_name))
pyversion = pythontag[2:]
if return_tags:
tags = {
'python': pythontag.replace('.', ''),
'platform': _wheel_escape(platform),
}
return (distname, safe_version(version), pyversion, 'bdist_wininst',
tags)
return (distname, safe_version(version), pyversion, 'bdist_wininst')
示例3: safe_version
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def safe_version(*args, **kwargs) -> str:
"""
Package resources is a very slow load
"""
import pkg_resources
return pkg_resources.safe_version(*args, **kwargs)
示例4: safer_version
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def safer_version(version):
return safe_version(version).replace("-", "_")
示例5: patch_missing_pkg_info
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def patch_missing_pkg_info(self, attrs):
# Fake up a replacement for the data that would normally come from
# PKG-INFO, but which might not yet be built if this is a fresh
# checkout.
#
if not attrs or 'name' not in attrs or 'version' not in attrs:
return
key = pkg_resources.safe_name(str(attrs['name'])).lower()
dist = pkg_resources.working_set.by_key.get(key)
if dist is not None and not dist.has_metadata('PKG-INFO'):
dist._version = pkg_resources.safe_version(str(attrs['version']))
self._patched_dist = dist
示例6: safer_version
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def safer_version(version):
return safe_version(version).replace('-', '_')
示例7: wheel_filename
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def wheel_filename(self) -> str:
name = to_filename(self.meta.project_name)
version = to_filename(safe_version(self.meta.version))
return f"{name}-{version}-{self.tag}.whl"
示例8: dist_info_name
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def dist_info_name(self) -> str:
name = to_filename(self.meta.project_name)
version = to_filename(safe_version(self.meta.version))
return f"{name}-{version}.dist-info"
示例9: build
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def build(self, build_dir: str, **kwargs):
if not os.path.exists(build_dir):
os.makedirs(build_dir, exist_ok=True)
stream.echo("- Building {}...".format(stream.cyan("sdist")))
version = to_filename(safe_version(self.meta.version))
target = os.path.join(
build_dir, "{}-{}.tar.gz".format(self.meta.project_name, version)
)
tar = tarfile.open(target, mode="w:gz", format=tarfile.PAX_FORMAT)
try:
tar_dir = "{}-{}".format(self.meta.project_name, version)
files_to_add = self.find_files_to_add(True)
for relpath in files_to_add:
tar.add(
relpath,
arcname=os.path.join(tar_dir, str(relpath)),
recursive=False,
)
stream.echo(f" - Adding: {relpath}", verbosity=stream.DETAIL)
fd, temp_name = tempfile.mkstemp(prefix="pkg-info")
pkg_info = self.format_pkginfo(False).encode("utf-8")
with open(fd, "wb") as f:
f.write(pkg_info)
tar.add(
temp_name, arcname=os.path.join(tar_dir, "PKG-INFO"), recursive=False
)
stream.echo(" - Adding: PKG-INFO", verbosity=stream.DETAIL)
finally:
tar.close()
stream.echo("- Built {}".format(stream.cyan(os.path.basename(target))))
return target
示例10: _parse_wheel_filename
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_version [as 别名]
def _parse_wheel_filename(basename, project_name=None, return_tags=False):
components = basename.split('-')
distname = components[0]
if (project_name is not None and
distname != _wheel_escape(project_name)):
raise ValueError('File %s.whl does not match project name %s'
% (basename, project_name))
if len(components) < 3 or not len(components[2]) >= 3:
raise ValueError('Invalid wheel filename %s.whl' % basename)
version = components[1]
pytag = components[2]
abitag = components[3]
platformtag = components[4]
if pytag == 'py2.py3':
# special handling of the universal Python version tag:
pyversion = '.'.join(str(x) for x in sys.version_info[:2])
elif pytag[:2] == 'py' and len(pytag) == 3:
pyversion = '%s' % pytag[2]
elif pytag[:2] == 'py' and len(pytag) == 4:
pyversion = '%s.%s' % (pytag[2], pytag[3])
elif pytag[:2] == 'cp':
pyversion = '%s.%s' % (pytag[2], pytag[3])
else:
raise ValueError('Invalid or unsupported Python version tag in '
'filename %s.whl' % basename)
if return_tags:
tags = {
'python': pytag,
'abi': abitag,
'platform': platformtag,
}
return (distname, safe_version(version), pyversion, 'bdist_wheel',
tags)
else:
return (distname, safe_version(version), pyversion, 'bdist_wheel')