本文整理匯總了Python中pkg_resources.to_filename方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.to_filename方法的具體用法?Python pkg_resources.to_filename怎麽用?Python pkg_resources.to_filename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.to_filename方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wheel_filename
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import to_filename [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"
示例2: dist_info_name
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import to_filename [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"
示例3: build
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import to_filename [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
示例4: get_local_dist_metadata_filepath
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import to_filename [as 別名]
def get_local_dist_metadata_filepath(dist):
# Dist filename syntax
# name ["-" version ["-py" pyver ["-" required_platform]]] "." ext
# https://setuptools.readthedocs.io/en/latest/formats.html#filename-embedded-metadata
def valid_component(component):
return component[1]
# Stop taking filename components at the first missing/invalid component
filename_component = takewhile(valid_component, (
('', pkg_resources.to_filename(pkg_resources.safe_name(dist.project_name))),
('-', pkg_resources.to_filename(pkg_resources.safe_version(dist.version))),
('-py', dist.py_version),
('-', dist.platform),
))
filename = ''.join(chain(*filename_component))
if isinstance(dist, pkg_resources.EggInfoDistribution):
ext = 'egg-info'
metadata_file = 'PKG-INFO'
elif isinstance(dist, pkg_resources.DistInfoDistribution):
ext = 'dist-info'
metadata_file = 'METADATA'
elif isinstance(dist, pkg_resources.Distribution):
ext = os.path.join('egg', 'EGG-INFO')
metadata_file = 'PKG-INFO'
else:
ext = None
metadata_file = None
filename = '{}.{}'.format(filename, ext)
path = os.path.join(dist.location, filename, metadata_file)
if ext:
return path
else:
return None