Skip to content

Commit 64d8e93

Browse files
committed
generalize the zip function
1 parent 5fd4143 commit 64d8e93

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

.evergreen/scripts/generate_config.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from __future__ import annotations
1111

1212
from dataclasses import dataclass
13-
from itertools import product, zip_longest
13+
from itertools import cycle, product, zip_longest
1414
from typing import Any
1515

1616
from shrub.v3.evg_build_variant import BuildVariant
@@ -69,7 +69,7 @@ def create_variant(
6969

7070

7171
def get_python_binary(python: str, host: str) -> str:
72-
"""Get the appropriate python binary given a python version and host"""
72+
"""Get the appropriate python binary given a python version and host."""
7373
if host == "win64":
7474
is_32 = python.startswith("32-bit")
7575
if is_32:
@@ -98,22 +98,11 @@ def get_display_name(base: str, host: str, version: str, python: str) -> str:
9898
return f"{base} {HOSTS[host].display_name} {version} {python}"
9999

100100

101-
def get_pairs(versions: list[str], pythons: list[str]) -> str:
102-
"""Get pairs of versions and pythons, ensuring that we hit all of each.
103-
The shorter list will repeat until the full length of the longer list.
104-
"""
105-
values = []
106-
i = 0
107-
for version, python in zip_longest(versions, pythons):
108-
if version is None:
109-
values.append((versions[i % len(versions)], python))
110-
i += 1
111-
elif python is None:
112-
values.append((version, pythons[i % len(pythons)]))
113-
i += 1
114-
else:
115-
values.append((version, python))
116-
return values
101+
def zip_cycle(*iterables, empty_default=None):
102+
"""Get all combinations of the inputs, cycling over the shorter list(s)."""
103+
cycles = [cycle(i) for i in iterables]
104+
for _ in zip_longest(*iterables):
105+
yield tuple(next(i, empty_default) for i in cycles)
117106

118107

119108
##############
@@ -130,7 +119,7 @@ def create_ocsp_variants() -> list[BuildVariant]:
130119

131120
# OCSP tests on rhel8 with all server v4.4+ and python versions.
132121
versions = [v for v in ALL_VERSIONS if v != "4.0"]
133-
for version, python in get_pairs(versions, ALL_PYTHONS):
122+
for version, python in zip_cycle(versions, ALL_PYTHONS):
134123
expansions = base_expansions.copy()
135124
expansions["VERSION"] = version
136125
host = "rhel8"

0 commit comments

Comments
 (0)