Replace distutils.util.strtobool in tests with a local helper#8298
Open
Sanjays2402 wants to merge 1 commit into
Open
Replace distutils.util.strtobool in tests with a local helper#8298Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
`tests/utils.py` imported `strtobool` from `distutils.util`, but `distutils` was removed from the standard library in Python 3.12 (PEP 632). On a setuptools-free interpreter (increasingly common with modern venvs, uv, and minimal CI images) this import raises `ModuleNotFoundError: No module named 'distutils'` at collection time, which breaks the entire test suite -- all 20 test modules that import from `tests.utils` fail to collect. When setuptools is installed it vendors a `distutils` shim, but that shim is deprecated and is being removed (it is gone on Python 3.14, which this project targets). Replace the import with a small local `strtobool` that reproduces the exact semantics of `distutils.util.strtobool` (truthy: y/yes/t/true/on/1; falsy: n/no/f/false/off/0; ValueError otherwise). setup.py already advertises support for Python 3.12, 3.13 and 3.14.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
tests/utils.pyimportsstrtoboolfromdistutils.util:distutilswas removed from the standard library in Python 3.12 (PEP 632).tests/utils.pyis imported (viafrom .utils import ...) by 20 test modules, so on an interpreter without thedistutilsshim this raises at collection time and the entire test suite fails to run:When it triggers
uv, and minimal CI images: hardModuleNotFoundError, whole suite uncollectable.distutilsshim so the import succeeds today, but the shim is deprecated and is removed on Python 3.14 — which this project already targets (setup.pyadvertisesProgramming Language :: Python :: 3.12/3.13/3.14, and CI runs on 3.14).Either way, relying on
distutilshere is on borrowed time.The fix
Replace the import with a small local
strtoboolthat reproduces the exact semantics ofdistutils.util.strtobool:This is the standard PEP 632 migration for
strtobool(the stdlib provides no replacement). It's test-only — no change to shipped code.Verification (local, Python 3.12.12, no setuptools)
Before — collection fails:
After:
distutilsspec for every truthy/falsy value (incl. mixed case) and theValueErrorpath — all match.ruff check tests/utils.py→ All checks passed!ruff format --check tests/utils.py→ already formatted.Notes
strtoboolhelper lives intests/utils.pyright next to its only caller (parse_flag_from_env), matching how the codebase already reads env flags likeRUN_SLOW/RUN_REMOTE.RUN_SLOW,RUN_REMOTE,RUN_LOCAL,RUN_PACKAGED) is unchanged.