From ba91d952d977b285f79351c4b100d230c155cf23 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sat, 28 Aug 2021 10:27:08 +0100 Subject: [PATCH] Remove compatibility code for Python < 3.6 --- flit_core/flit_core/wheel.py | 51 +++--------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/flit_core/flit_core/wheel.py b/flit_core/flit_core/wheel.py index afb752cf..b3c9eef4 100644 --- a/flit_core/flit_core/wheel.py +++ b/flit_core/flit_core/wheel.py @@ -10,20 +10,8 @@ import stat import sys import tempfile -try: - from types import SimpleNamespace # Python 3 -except ImportError: - from argparse import Namespace as SimpleNamespace # Python 2 - -HAVE_ZIPFILE36 = True -if sys.version_info >= (3, 6): - import zipfile -else: - try: - import zipfile36 as zipfile - except ImportError: - import zipfile - HAVE_ZIPFILE36 = False +from types import SimpleNamespace +import zipfile from flit_core import __version__ from . import common @@ -62,13 +50,7 @@ def __init__(self, directory, module, metadata, entrypoints, target_fp): # If SOURCE_DATE_EPOCH is set (e.g. by Debian), it's used for # timestamps inside the zip file. d = datetime.utcfromtimestamp(int(os.environ['SOURCE_DATE_EPOCH'])) - if HAVE_ZIPFILE36: - log.info("Zip timestamps will be from SOURCE_DATE_EPOCH: %s", d) - else: - log.warning( - "Can't use timestamp from SOURCE_DATE_EPOCH: " - "Need Python >= 3.6 or the zipfile36 backport for this." - ) + log.info("Zip timestamps will be from SOURCE_DATE_EPOCH: %s", d) # zipfile expects a 6-tuple, not a datetime object self.source_time_stamp = (d.year, d.month, d.day, d.hour, d.minute, d.second) except (KeyError, ValueError): @@ -101,30 +83,7 @@ def wheel_filename(self): tag = ('py2.' if self.metadata.supports_py2 else '') + 'py3-none-any' return '{}-{}.whl'.format(dist_name, tag) - def _add_file_old(self, full_path, rel_path): - log.debug("Adding %s to zip file", full_path) - full_path, rel_path = str(full_path), str(rel_path) - if os.sep != '/': - # We always want to have /-separated paths in the zip file and in - # RECORD - rel_path = rel_path.replace(os.sep, '/') - - self.wheel_zip.write(full_path, arcname=rel_path) - - hashsum = hashlib.sha256() - with open(full_path, 'rb') as src: - while True: - buf = src.read(1024 * 8) - if not buf: - break - hashsum.update(buf) - - size = os.stat(full_path).st_size - hash_digest = urlsafe_b64encode(hashsum.digest()).decode( - 'ascii').rstrip('=') - self.records.append((rel_path, hash_digest, size)) - - def _add_file_zf36(self, full_path, rel_path): + def _add_file(self, full_path, rel_path): log.debug("Adding %s to zip file", full_path) full_path, rel_path = str(full_path), str(rel_path) if os.sep != '/': @@ -161,8 +120,6 @@ def _add_file_zf36(self, full_path, rel_path): hash_digest = urlsafe_b64encode(hashsum.digest()).decode('ascii').rstrip('=') self.records.append((rel_path, hash_digest, size)) - _add_file = _add_file_zf36 if HAVE_ZIPFILE36 else _add_file_old - @contextlib.contextmanager def _write_to_zip(self, rel_path, mode=0o644): sio = io.StringIO()