Skip to content

Commit cda7417

Browse files
committed
add some docstrings
1 parent de3ccef commit cda7417

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

scripts/populate_tox/populate_tox.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ def fetch_release(package: str, version: Version) -> dict:
136136

137137

138138
def _prefilter_releases(integration: str, releases: dict[str, dict]) -> list[Version]:
139-
"""Drop versions that are unsupported without making additional API calls."""
139+
"""
140+
Filter `releases`, removing releases that are for sure unsupported.
141+
142+
This function doesn't guarantee that all releases it returns are supported --
143+
there are further criteria that will be checked later in the pipeline because
144+
they require additional API calls to be made. The purpose of this function is
145+
to slim down the list so that we don't have to make more API calls than
146+
necessary for releases that are for sure not supported.
147+
"""
140148
min_supported = _MIN_VERSIONS.get(integration)
141149
if min_supported is not None:
142150
min_supported = Version(".".join(map(str, min_supported)))
@@ -222,7 +230,7 @@ def _supports_lowest(release: Version) -> bool:
222230

223231

224232
def pick_releases_to_test(releases: list[Version]) -> list[Version]:
225-
"""Pick a handful of releases from a list of supported releases."""
233+
"""Pick a handful of releases to test from a list of supported releases."""
226234
# If the package has majors (or major-like releases, even if they don't do
227235
# semver), we want to make sure we're testing them all. If not, we just pick
228236
# the oldest, the newest, and a couple in between.
@@ -271,15 +279,35 @@ def supported_python_versions(
271279
package_python_versions: Union[SpecifierSet, list[Version]],
272280
custom_supported_versions: Optional[SpecifierSet] = None,
273281
) -> list[Version]:
274-
"""Get an intersection of package_python_versions and Python versions supported in the SDK."""
282+
"""
283+
Get the intersection of Python versions supported by the package and the SDK.
284+
285+
Optionally, if `custom_supported_versions` is provided, the function will
286+
return the intersection of Python versions supported by the package, the SDK,
287+
and `custom_supported_versions`. This is used when a test suite definition
288+
in `TEST_SUITE_CONFIG` contains a range of Python versions to run the tests
289+
on.
290+
291+
Examples:
292+
- The Python SDK supports Python 3.6-3.13. The package supports 3.5-3.8. This
293+
function will return [3.6, 3.7, 3.8] as the Python versions supported
294+
by both.
295+
- The Python SDK supports Python 3.6-3.13. The package supports 3.5-3.8. We
296+
have an additional test limitation in place to only test this framework
297+
on Python 3.7, so we can provide this as `custom_supported_versions`. The
298+
result of this function will then by the intersection of all three, i.e.,
299+
[3.7].
300+
"""
275301
supported = []
276302

303+
# Iterate through Python versions from MIN_PYTHON_VERSION to MAX_PYTHON_VERSION
277304
curr = MIN_PYTHON_VERSION
278305
while curr <= MAX_PYTHON_VERSION:
279306
if curr in package_python_versions:
280307
if not custom_supported_versions or curr in custom_supported_versions:
281308
supported.append(curr)
282309

310+
# Construct the next Python version (i.e., bump the minor)
283311
next = [int(v) for v in str(curr).split(".")]
284312
next[1] += 1
285313
curr = Version(".".join(map(str, next)))
@@ -288,6 +316,12 @@ def supported_python_versions(
288316

289317

290318
def pick_python_versions_to_test(python_versions: list[Version]) -> list[Version]:
319+
"""
320+
Given a list of Python versions, pick those that make sense to test on.
321+
322+
Currently, this is the oldest, the newest, and the second newest Python
323+
version.
324+
"""
291325
filtered_python_versions = {
292326
python_versions[0],
293327
}

0 commit comments

Comments
 (0)