Skip to content

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

Open
alongd wants to merge 2 commits into
mainfrom
fix-distutils-py314
Open

fix: replace removed distutils.spawn with shutil.which (Python 3.12+)#908
alongd wants to merge 2 commits into
mainfrom
fix-distutils-py314

Conversation

@alongd

@alongd alongd commented Jul 4, 2026

Copy link
Copy Markdown
Member

Problem

distutils was removed from the Python standard library in 3.12, so arc/main.py's
from distutils.spawn import find_executable raises ModuleNotFoundError on Python 3.14.
It only appears to work in environments where setuptools happens to install its distutils
compatibility shim — a fresh CI env without that shim fails.

Because arc.main is imported transitively by most of ARC (and by downstream consumers like
T3), this breaks at import/collection time. Concretely, the T3 test suite currently dies with:

ImportError while importing test module '.../tests/test_common.py'.
E   ModuleNotFoundError: No module named 'distutils'

(chain: t3.commonarc.species.speciesarc.mainfrom distutils.spawn import find_executable)

Fix

Replace the single stdlib usage with shutil.which, the documented drop-in replacement for
distutils.spawn.find_executable — both return the path to the executable found on PATH, or
None. shutil is already imported in arc/main.py, so no new import is added.

The 7 affected call sites all look up ESS executables on PATH (g03/g09/g16/qchem/orca/
molpro/terachem), and the downstream truthiness checks (if g03 or g09 or g16: …) are unchanged.

Scope / safety

  • This is the only distutils usage anywhere in arc/*.py, and there are no other
    removed-stdlib imports — this single change makes the ARC import graph Python-3.12+/3.14 clean.
  • ARC's own arc.settings.settings.find_executable(env_name, ...) is a different function
    (it locates the python interpreter of a named conda env) and is intentionally left untouched;
    arc/job/adapters/ase_adapter.py imports that settings function, not the stdlib one.

🤖 Generated with Claude Code

`distutils` was removed from the Python standard library in 3.12, so
`from distutils.spawn import find_executable` raises ModuleNotFoundError
on Python 3.14 (it only works where setuptools happens to install its
distutils compatibility shim). This breaks importing `arc.main`, which
in turn breaks every downstream import of ARC (e.g. the T3 test suite
fails at collection with `No module named 'distutils'`).

Replace the single stdlib usage with `shutil.which`, the documented
drop-in for `distutils.spawn.find_executable` (both return the path to
the executable on PATH, or None). `shutil` is already imported.

Note: ARC's own `arc.settings.settings.find_executable` is a different
function (finds the python of a named conda env) and is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ARC’s ESS executable discovery to be compatible with Python 3.12+ by removing the deprecated/removed distutils dependency and using the standard-library replacement.

Changes:

  • Removed from distutils.spawn import find_executable from arc/main.py.
  • Replaced ESS executable lookups (g03/g09/g16/qchem/orca/molpro/terachem) with shutil.which().
Comments suppressed due to low confidence (1)

arc/main.py:812

  • The else: that logs "Did not find ESS on the local machine" is currently attached to if diagnostics: (inside the if any(...) block). This causes a misleading log message when ESS executables are found but diagnostics is False. The else should instead pair with if any(...) (and optionally simplify the any([...]) expression).
            terachem = shutil.which('terachem')
            if terachem:
                self.ess_settings['molpro'] = ['local']
            if any([val for val in self.ess_settings.values()]):
                if diagnostics:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread arc/main.py Outdated
… log)

Two pre-existing bugs in ARC.check_ess_settings's local-ESS scan,
surfaced by review of the surrounding block:

1. When a local TeraChem executable is found, availability was recorded
   under `self.ess_settings['molpro']` instead of `['terachem']`
   (copy-paste error), so TeraChem was mis-registered and Molpro could
   be falsely reported as available.

2. The "Did not find ESS on the local machine" log was nested under the
   `if diagnostics:` branch, so it fired as the `else` of `diagnostics`
   rather than the `else` of `if any(ESS found)`. As written, whenever
   ESS *were* found but `diagnostics` was False, it logged the opposite
   ("Did not find ESS"). Dedent the `else` to pair with the `any(...)`
   check so the not-found message only fires when nothing was found.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.10%. Comparing base (e7f2c98) to head (c62bdbb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #908      +/-   ##
==========================================
- Coverage   63.15%   63.10%   -0.06%     
==========================================
  Files         114      114              
  Lines       38178    38177       -1     
  Branches     9990     9990              
==========================================
- Hits        24113    24090      -23     
- Misses      11183    11199      +16     
- Partials     2882     2888       +6     
Flag Coverage Δ
functionaltests 63.10% <ø> (-0.06%) ⬇️
unittests 63.10% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants