Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compatibility code for Python < 3.6 #440

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 4 additions & 47 deletions flit_core/flit_core/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 != '/':
Expand Down Expand Up @@ -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()
Expand Down