本文整理匯總了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