Skip to content

Commit 35e0340

Browse files
committed
Use function from archive_util instead of overwritting ZipFile
1 parent 4882320 commit 35e0340

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

setuptools/wheel.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from setuptools.extern.packaging.tags import sys_tags
1616
from setuptools.extern.packaging.utils import canonicalize_name
1717
from setuptools.command.egg_info import write_requirements
18+
from setuptools.archive_util import _unpack_zipfile_obj
1819

1920

2021
WHEEL_NAME = re.compile(
@@ -27,20 +28,6 @@
2728
"__import__('pkg_resources').declare_namespace(__name__)\n"
2829

2930

30-
class ZipFilePreserveMode(zipfile.ZipFile):
31-
""" Extended ZipFile class to preserve file mode """
32-
def _extract_member(self, member, targetpath, pwd):
33-
if not isinstance(member, zipfile.ZipInfo):
34-
member = self.getinfo(member)
35-
36-
targetpath = super()._extract_member(member, targetpath, pwd)
37-
38-
attr = member.external_attr >> 16
39-
if attr != 0:
40-
os.chmod(targetpath, attr)
41-
return targetpath
42-
43-
4431
def unpack(src_dir, dst_dir):
4532
'''Move everything under `src_dir` to `dst_dir`, and delete the former.'''
4633
for dirpath, dirnames, filenames in os.walk(src_dir):
@@ -105,7 +92,7 @@ def get_dist_info(self, zf):
10592

10693
def install_as_egg(self, destination_eggdir):
10794
'''Install wheel as an egg directory.'''
108-
with ZipFilePreserveMode(self.filename) as zf:
95+
with zipfile.ZipFile(self.filename) as zf:
10996
self._install_as_egg(destination_eggdir, zf)
11097

11198
def _install_as_egg(self, destination_eggdir, zf):
@@ -135,8 +122,7 @@ def get_metadata(name):
135122
raise ValueError(
136123
'unsupported wheel format version: %s' % wheel_version)
137124
# Extract to target directory.
138-
os.mkdir(destination_eggdir)
139-
zf.extractall(destination_eggdir)
125+
_unpack_zipfile_obj(zf, destination_eggdir)
140126
# Convert metadata.
141127
dist_info = os.path.join(destination_eggdir, dist_info)
142128
dist = pkg_resources.Distribution.from_location(

0 commit comments

Comments
 (0)