Skip to content

fix: replace removed distutils.spawn with shutil.which (Python 3.12+) - #402

Merged
JarbasAl merged 1 commit into
devfrom
fix/remove-distutils
Jul 23, 2026
Merged

fix: replace removed distutils.spawn with shutil.which (Python 3.12+)#402
JarbasAl merged 1 commit into
devfrom
fix/remove-distutils

Conversation

@JarbasAl

Copy link
Copy Markdown
Member

Problem

distutils was removed from the Python standard library in 3.12. This breaks import of two modules that still use it:

ModuleNotFoundError: No module named 'distutils'

Affected modules:

  • ovos_utils.sound — uses distutils.spawn.find_executable to locate audio players (play, ogg123, pw-play, paplay, aplay, mpg123) and media probes (ffprobe, mediainfo)
  • ovos_utils.device_input — uses distutils.spawn.find_executable to locate libinput/xinput

Both modules fail to import at all on Python 3.12+.

Fix

Replace from distutils.spawn import find_executable with from shutil import which, and every find_executable(...) call with which(...). shutil.which is the stdlib replacement recommended for this exact use case (same signature/behavior: returns the resolved path or None).

Existing unit tests (test/unittests/test_sound.py, test/unittests/test_device_input.py) patched find_executable by name, so those mock targets were updated to which as well. No behavior changes.

Test plan

  • ast.parse sanity check on both edited modules
  • grep -r distutils ovos_utils/ returns nothing
  • pytest test/unittests/test_sound.py test/unittests/test_device_input.py — 39 passed

This fix was authored with Claude Code.

distutils was removed from the standard library in Python 3.12, so
ovos_utils.sound and ovos_utils.device_input fail to import with
ModuleNotFoundError: No module named 'distutils'. shutil.which is a
drop-in stdlib replacement for distutils.spawn.find_executable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@JarbasAl, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 90ba71df-61b8-4d0a-a3f0-662ecbff0bd0

📥 Commits

Reviewing files that changed from the base of the PR and between 2bae79c and c9f950a.

📒 Files selected for processing (4)
  • ovos_utils/device_input.py
  • ovos_utils/sound.py
  • test/unittests/test_device_input.py
  • test/unittests/test_sound.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/remove-distutils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the fix label Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The automated sentinels have completed their watch. 💂‍♂️

I've aggregated the results of the automated checks for this PR below.

🔍 Lint

I've gathered the facts for your review. 📖

ruff: issues found — see job log

🏷️ Release Preview

The release train is fueling up! 🚂

Current: 0.13.6a1Next: 0.13.7a1

Signal Value
Label (none)
PR title fix: replace removed distutils.spawn with shutil.which (Python 3.12+)
Bump build

✅ PR title follows conventional commit format.


🚀 Release Channel Compatibility

Predicted next version: 0.13.7a1

Channel Status Note Current Constraint
Stable Too new (must be <0.9.0) ovos-utils>=0.8.1,<0.9.0
Testing Too new (must be <0.8.5) ovos-utils>=0.8.4,<0.8.5
Alpha Compatible ovos-utils>=0.13.6a1

⚖️ License Check

I've checked the licenses of all dev-dependencies too. 🛠️

✅ No license violations found.

Policy: Apache 2.0 (universal donor). StrongCopyleft / NetworkCopyleft / WeakCopyleft / Other / Error categories fail. MPL allowed.

🔒 Security (pip-audit)

The security scan is now complete. 🏁

✅ No known vulnerabilities found (47 packages scanned).

📊 Coverage

A forensic look at what's being executed. 🔎

85.2% total coverage

Files below 80% coverage (5 files)
File Coverage Missing lines
ovos_utils/log_parser.py 48.4% 225
ovos_utils/__init__.py 63.6% 16
ovos_utils/file_utils.py 73.3% 55
ovos_utils/thread_utils.py 76.9% 12
ovos_utils/geolocation.py 78.4% 22

Full report: download the coverage-report artifact.

📋 Repo Health

Checking if we're following maintenance best practices. 📏

✅ All required files present.

Latest Version: 0.13.6a1

ovos_utils/version.py — Version file
README.md — README
LICENSE — License file
pyproject.toml — pyproject.toml
⚠️ setup.py — setup.py
CHANGELOG.md — Changelog
ovos_utils/version.py has valid version block markers

🔨 Build Tests

The build pipeline has finished its work. 🏁

✅ All versions pass

Python Build Install Tests
3.10
3.11
3.12
3.13
3.14

Standard Automated Signature v2.0 🏷️

@JarbasAl
JarbasAl marked this pull request as ready for review July 23, 2026 20:41
@JarbasAl
JarbasAl merged commit cf103e0 into dev Jul 23, 2026
14 checks passed
@JarbasAl
JarbasAl deleted the fix/remove-distutils branch July 23, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant