mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 05:44:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,18 +1,19 @@
|
|||
"""Utilities for extracting common archive formats"""
|
||||
from __future__ import annotations
|
||||
|
||||
import zipfile
|
||||
import tarfile
|
||||
import os
|
||||
import shutil
|
||||
import posixpath
|
||||
import contextlib
|
||||
from distutils.errors import DistutilsError
|
||||
import os
|
||||
import posixpath
|
||||
import shutil
|
||||
import tarfile
|
||||
import zipfile
|
||||
|
||||
from distutils.errors import DistutilsError
|
||||
from pkg_resources import ensure_directory
|
||||
|
||||
__all__ = [
|
||||
"unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter",
|
||||
"UnrecognizedFormat", "extraction_drivers", "unpack_directory",
|
||||
'unpack_archive', 'unpack_zipfile', 'unpack_tarfile', 'default_filter',
|
||||
'UnrecognizedFormat', 'extraction_drivers', 'unpack_directory',
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -27,7 +28,8 @@ def default_filter(src, dst):
|
|||
|
||||
def unpack_archive(
|
||||
filename, extract_dir, progress_filter=default_filter,
|
||||
drivers=None):
|
||||
drivers=None,
|
||||
):
|
||||
"""Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``
|
||||
|
||||
`progress_filter` is a function taking two arguments: a source path
|
||||
|
|
@ -57,7 +59,7 @@ def unpack_archive(
|
|||
return
|
||||
else:
|
||||
raise UnrecognizedFormat(
|
||||
"Not a recognized archive type: %s" % filename
|
||||
'Not a recognized archive type: %s' % filename,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -67,7 +69,7 @@ def unpack_directory(filename, extract_dir, progress_filter=default_filter):
|
|||
Raises ``UnrecognizedFormat`` if `filename` is not a directory
|
||||
"""
|
||||
if not os.path.isdir(filename):
|
||||
raise UnrecognizedFormat("%s is not a directory" % filename)
|
||||
raise UnrecognizedFormat('%s is not a directory' % filename)
|
||||
|
||||
paths = {
|
||||
filename: ('', extract_dir),
|
||||
|
|
@ -97,7 +99,7 @@ def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
|
|||
"""
|
||||
|
||||
if not zipfile.is_zipfile(filename):
|
||||
raise UnrecognizedFormat("%s is not a zip file" % (filename,))
|
||||
raise UnrecognizedFormat('{} is not a zip file'.format(filename))
|
||||
|
||||
with zipfile.ZipFile(filename) as z:
|
||||
for info in z.infolist():
|
||||
|
|
@ -128,7 +130,8 @@ def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
|
|||
def _resolve_tar_file_or_dir(tar_obj, tar_member_obj):
|
||||
"""Resolve any links and extract link targets as normal files."""
|
||||
while tar_member_obj is not None and (
|
||||
tar_member_obj.islnk() or tar_member_obj.issym()):
|
||||
tar_member_obj.islnk() or tar_member_obj.issym()
|
||||
):
|
||||
linkpath = tar_member_obj.linkname
|
||||
if tar_member_obj.issym():
|
||||
base = posixpath.dirname(tar_member_obj.name)
|
||||
|
|
@ -186,7 +189,7 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
|
|||
tarobj = tarfile.open(filename)
|
||||
except tarfile.TarError as e:
|
||||
raise UnrecognizedFormat(
|
||||
"%s is not a compressed or uncompressed tar file" % (filename,)
|
||||
'{} is not a compressed or uncompressed tar file'.format(filename),
|
||||
) from e
|
||||
|
||||
for member, final_dst in _iter_open_tar(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue