Skip to content

Commit

Permalink
Bump tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <gaborjbernat@gmail.com>
  • Loading branch information
gaborbernat committed Jul 23, 2022
1 parent c527302 commit 19f29c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 50 deletions.
28 changes: 12 additions & 16 deletions tasks/make_zipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
from collections import defaultdict, deque
from email import message_from_string
from pathlib import Path, PurePosixPath
from shlex import quote
from stat import S_IWUSR
from tempfile import TemporaryDirectory

from packaging.markers import Marker
from packaging.requirements import Requirement

if sys.version_info[0] == 2:
from pipes import quote
else:
from shlex import quote

HERE = Path(__file__).parent.absolute()

VERSIONS = ["3.{}".format(i) for i in range(10, 4, -1)] + ["2.7"]
VERSIONS = [f"3.{i}" for i in range(10, 4, -1)] + ["2.7"]


def main():
Expand All @@ -50,7 +46,7 @@ def create_zipapp(dest, packages):
zip_app.writestr("__main__.py", (HERE / "__main__zipapp.py").read_bytes())
bio.seek(0)
zipapp.create_archive(bio, dest)
print("zipapp created at {}".format(dest))
print(f"zipapp created at {dest}")


def write_packages_to_zipapp(base, dist, modules, packages, zip_app):
Expand Down Expand Up @@ -86,7 +82,7 @@ def write_packages_to_zipapp(base, dist, modules, packages, zip_app):
del content


class WheelDownloader(object):
class WheelDownloader:
def __init__(self, into):
if into.exists():
shutil.rmtree(into)
Expand All @@ -108,7 +104,7 @@ def run(self, target, versions):
whl = self._get_wheel(dep, platform[2:] if platform and platform.startswith("==") else None, version)
if whl is None:
if dep_str not in wheel_store:
raise RuntimeError("failed to get {}, have {}".format(dep_str, wheel_store))
raise RuntimeError(f"failed to get {dep_str}, have {wheel_store}")
whl = wheel_store[dep_str]
else:
wheel_store[dep_str] = whl
Expand Down Expand Up @@ -143,7 +139,7 @@ def _download(self, platform, stop_print_on_fail, *args):
@staticmethod
def get_dependencies(whl, version):
with zipfile.ZipFile(str(whl), "r") as zip_file:
name = "/".join(["{}.dist-info".format("-".join(whl.name.split("-")[0:2])), "METADATA"])
name = "/".join([f"{'-'.join(whl.name.split('-')[0:2])}.dist-info", "METADATA"])
with zip_file.open(name) as file_handler:
metadata = message_from_string(file_handler.read().decode("utf-8"))
deps = metadata.get_all("Requires-Dist")
Expand Down Expand Up @@ -171,7 +167,7 @@ def get_dependencies(whl, version):
platform_positions = WheelDownloader._marker_at(markers, "sys_platform")
deleted = 0
for pos in platform_positions: # can only be ore meaningfully
platform = "{}{}".format(markers[pos][1].value, markers[pos][2].value)
platform = f"{markers[pos][1].value}{markers[pos][2].value}"
deleted += WheelDownloader._del_marker_at(markers, pos - deleted)
platforms.append(platform)
if not platforms:
Expand Down Expand Up @@ -231,7 +227,7 @@ def run_suppress_output(cmd, stop_print_on_fail=False):
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
out, err = process.communicate()
if stop_print_on_fail and process.returncode != 0:
print("exit with {} of {}".format(process.returncode, " ".join(quote(i) for i in cmd)), file=sys.stdout)
print(f"exit with {process.returncode} of {' '.join(quote(i) for i in cmd)}", file=sys.stdout)
if out:
print(out, file=sys.stdout)
if err:
Expand All @@ -254,19 +250,19 @@ def get_wheels_for_support_versions(folder):
wheel_versions.wheel = wheel
for name, p_w_v in packages.items():
for platform, w_v in p_w_v.items():
print("{} - {}".format(name, platform))
print(f"{name} - {platform}")
for wheel, wheel_versions in w_v.items():
print("{} of {} (use {})".format(" ".join(wheel_versions.versions), wheel, wheel_versions.wheel))
print(f"{' '.join(wheel_versions.versions)} of {wheel} (use {wheel_versions.wheel})")
return packages


class WheelForVersion(object):
class WheelForVersion:
def __init__(self, wheel=None, versions=None):
self.wheel = wheel
self.versions = versions if versions else []

def __repr__(self):
return "{}({!r}, {!r})".format(self.__class__.__name__, self.wheel, self.versions)
return f"{self.__class__.__name__}({self.wheel!r}, {self.versions!r})"


if __name__ == "__main__":
Expand Down
5 changes: 2 additions & 3 deletions tasks/release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Handles creating a release PR"""
from pathlib import Path
from subprocess import check_call
Expand Down Expand Up @@ -60,9 +59,9 @@ def tag_release_commit(release_commit, repo, version) -> TagReference:
print("tag release commit")
existing_tags = [x.name for x in repo.tags]
if version in existing_tags:
print("delete existing tag {}".format(version))
print(f"delete existing tag {version}")
repo.delete_tag(version)
print("create tag {}".format(version))
print(f"create tag {version}")
tag = repo.create_tag(version, ref=release_commit, force=True)
return tag

Expand Down
21 changes: 6 additions & 15 deletions tasks/update_embedded.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
#!/usr/bin/env python
"""
Helper script to rebuild virtualenv.py from virtualenv_support
"""
from __future__ import print_function, unicode_literals
"""Helper script to rebuild virtualenv.py from virtualenv_support"""

import codecs
import os
import re
import sys
from zlib import crc32 as _crc32

if sys.version_info < (3,):
print("requires Python 3 (use tox from Python 3 if invoked via tox)")
raise SystemExit(1)


def crc32(data):
"""Python version idempotent"""
Expand All @@ -31,7 +22,7 @@ def crc32(data):


def rebuild(script_path):
with open(script_path, "rt") as current_fh:
with open(script_path) as current_fh:
script_content = current_fh.read()
script_parts = []
match_end = 0
Expand All @@ -53,21 +44,21 @@ def rebuild(script_path):


def handle_file(previous_content, filename, variable_name, previous_encoded):
print("Found file {}".format(filename))
print(f"Found file {filename}")
current_path = os.path.realpath(os.path.join(here, "..", "src", "virtualenv_embedded", filename))
_, file_type = os.path.splitext(current_path)
keep_line_ending = file_type in (".bat",)
with open(current_path, "rt", encoding="utf-8", newline="" if keep_line_ending else None) as current_fh:
with open(current_path, encoding="utf-8", newline="" if keep_line_ending else None) as current_fh:
current_text = current_fh.read()
current_crc = crc32(current_text)
current_encoded = b64.encode(gzip.encode(current_text.encode())[0])[0].decode()
if current_encoded == previous_encoded:
print(" File up to date (crc: {:08x})".format(current_crc))
print(f" File up to date (crc: {current_crc:08x})")
return False, previous_content
# Else: content has changed
previous_text = gzip.decode(b64.decode(previous_encoded.encode())[0])[0].decode()
previous_crc = crc32(previous_text)
print(" Content changed (crc: {:08x} -> {:08x})".format(previous_crc, current_crc))
print(f" Content changed (crc: {previous_crc:08x} -> {current_crc:08x})")
new_part = file_template.format(filename=filename, variable=variable_name, data=current_encoded)
return True, new_part

Expand Down
27 changes: 11 additions & 16 deletions tasks/upgrade_wheels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Helper script to rebuild virtualenv_support. Downloads the wheel files using pip
"""
from __future__ import absolute_import, unicode_literals

import os
import shutil
Expand Down Expand Up @@ -70,31 +69,33 @@ def run():

outcome = (1 if STRICT else 0) if (added or removed) else 0
for key, versions in added.items():
text = "* upgrade embedded {} to {}".format(key, fmt_version(versions))
text = f"* upgrade embedded {key} to {fmt_version(versions)}"
if key in removed:
text += " from {}".format(removed[key])
text += f" from {removed[key]}"
del removed[key]
print(text)
for key, versions in removed.items():
print("* removed embedded {} of {}".format(key, fmt_version(versions)))
print(f"* removed embedded {key} of {fmt_version(versions)}")

support_table = OrderedDict((".".join(str(j) for j in i), list()) for i in SUPPORT)
for package in sorted(new_batch.keys()):
for folder, version in sorted(folders.items()):
if (folder / package).exists():
support_table[version].append(package)
support_table = {k: OrderedDict((i.split("-")[0], i) for i in v) for k, v in support_table.items()}

bundle = ",".join(
f"{v!r}: {{ {','.join(f'{p!r}: {f!r}' for p, f in l.items())} }}" for v, l in support_table.items()
)
msg = dedent(
"""
f"""
from __future__ import absolute_import, unicode_literals
from virtualenv.seed.wheels.util import Wheel
from virtualenv.util.path import Path
BUNDLE_FOLDER = Path(__file__).absolute().parent
BUNDLE_SUPPORT = {{ {0} }}
MAX = {1}
BUNDLE_SUPPORT = {{ {bundle} }}
MAX = {repr(next(iter(support_table.keys())))}
def get_embed_wheel(distribution, for_py_version):
Expand All @@ -109,13 +110,7 @@ def get_embed_wheel(distribution, for_py_version):
"BUNDLE_FOLDER",
)
""".format(
",".join(
"{!r}: {{ {} }}".format(v, ",".join("{!r}: {!r}".format(p, f) for p, f in l.items()))
for v, l in support_table.items()
),
repr(next(iter(support_table.keys()))),
),
""",
)
dest_target = DEST / "__init__.py"
dest_target.write_text(msg)
Expand All @@ -126,7 +121,7 @@ def get_embed_wheel(distribution, for_py_version):


def fmt_version(versions):
return ", ".join("``{}``".format(v) for v in versions)
return ", ".join(f"``{v}``" for v in versions)


def collect_package_versions(new_packages):
Expand Down

0 comments on commit 19f29c0

Please sign in to comment.