本文整理汇总了Python中shutil._UNPACK_FORMATS属性的典型用法代码示例。如果您正苦于以下问题:Python shutil._UNPACK_FORMATS属性的具体用法?Python shutil._UNPACK_FORMATS怎么用?Python shutil._UNPACK_FORMATS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类shutil
的用法示例。
在下文中一共展示了shutil._UNPACK_FORMATS属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_shutil_unpack_formats
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import _UNPACK_FORMATS [as 别名]
def get_shutil_unpack_formats(self):
return shutil._UNPACK_FORMATS, shutil._UNPACK_FORMATS.copy()
示例2: restore_shutil_unpack_formats
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import _UNPACK_FORMATS [as 别名]
def restore_shutil_unpack_formats(self, saved):
shutil._UNPACK_FORMATS = saved[0]
shutil._UNPACK_FORMATS.clear()
shutil._UNPACK_FORMATS.update(saved[1])
示例3: _extract_modules
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import _UNPACK_FORMATS [as 别名]
def _extract_modules(self, dep, archive_path: Path, output_path: Path) -> bool:
# say to shutils that wheel can be parsed as zip
if 'wheel' not in shutil._UNPACK_FORMATS: # type: ignore
shutil.register_unpack_format(
name='wheel',
extensions=['.whl'],
function=shutil._unpack_zipfile, # type: ignore
)
with TemporaryDirectory(suffix=dep.name) as package_path: # type: Path # type: ignore
package_path = Path(package_path)
shutil.unpack_archive(str(archive_path), str(package_path))
if len(list(package_path.iterdir())) == 1:
package_path = next(package_path.iterdir())
# find modules
root = PackageRoot(name=dep.name, path=package_path)
if not root.packages:
self.logger.error('cannot find modules', extra=dict(
dependency=dep.name,
version=dep.group.best_release.version,
))
return False
# copy modules
module_path = root.packages[0].path
module_name = root.packages[0].module
self.logger.info('copying module...', extra=dict(
path=str(module_path.relative_to(package_path)),
dependency=dep.name,
))
shutil.copytree(
src=str(module_path),
dst=str(output_path.joinpath(*module_name.split('.'))),
)
return True