Skip to content

Python 3.12 compatibility#58

Draft
timbernat wants to merge 14 commits into
mainfrom
py312-updates
Draft

Python 3.12 compatibility#58
timbernat wants to merge 14 commits into
mainfrom
py312-updates

Conversation

@timbernat

@timbernat timbernat commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Description

Update package code and build config to allow use with Python 3.12+ as Python 3.11 enters end-of-life.

Todos

Notable points that this PR has either accomplished or will accomplish.

  • Enable pip install polymerist without dependency conflicts in envirnment with at least Python 3.12
  • Update with minimal changes to source, and without breaking examples
  • Resolve Support for Python 3.12 #57

Questions

  • What are sources of 3.12 incompatibility?
    • In-code (e.g. typehints, which did change)
      • Update unit tests
      • _importlib.resources.common.get_package deprecation
    • Dependency (e.g. importlib, OpenFF)
      • mBuild (a lot actually, including np.vecdot deprecation, pkg_resources, and mbuild.plugins)
    • Excise espaloma-charge from:
      • Shipped conda envs
      • Install instructions
      • Docs

Status

  • Confirm import across all subpackages
  • Verify CI workflow runs w/ 3.12 added to matrix
  • Check compat on PyPI (dev) release
  • Ready to go

@timbernat timbernat self-assigned this Apr 29, 2026
@timbernat timbernat added the priority:medium Moderate urgency, issue has major impacts on some but not most parts of the codebase label Apr 29, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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

@timbernat

Copy link
Copy Markdown
Owner Author

@joelaforet, combing through I've made headway in some places but run into problems on others. Diving into the leads given in #58, the specific break was due to deprecation of importlib.resources._common.get_package(), which was harder than expected to find in the changelog but I eventually tracked down the commit, from as far back as 10/2022! The prior get_package() functionality was replaceable with a check for the submodule_search_locations return value from the module's spec, which is compatible with both 3.11 and 3.12, requiring only _common.resolve imported. I've confirmed this fix is backward-compatible between 3.11 and 3.12 against the tests for pkginspect.

As far as other dependencies, mBuild seems to be causing an inordinate amount of issues, including:

  • GMSO requiring pkg_resources (documented in CI fail, likely due to setuptools<82.0 unpin)
  • Missing mbuild.plugins internal dependency (this CI fail)
  • Deprecation errors from within mbuild on a np.vecdot import, through I haven't been able to reproduce this consistently.

There also seems to be some sensitivity to installation order, i.e. whether pip-installing polymerist then installing mbuild and or creating an env from a conda.yml and pip-installing afterwards. Digging into that more will take time and might require some extra eyes, but I'm hoping resolving that will be the trickiest blocker to getting 3.12 support in. It's not clear to me as-writing where other incompatibilities may lie; for now, I've removed all upper version pins in the shipped env .ymls and will add them back in if necessary.

@joelaforet

Copy link
Copy Markdown

I dug into the Python 3.12 dependency failures and opened a small follow-up PR with the proposed metadata/env changes: #59.\n\nSummary of findings:\n- The source-level Python 3.12 incompatibility is the private importlib.resources._common usage in pkginspect.py. The current PR fix using ModuleSpec.submodule_search_locations for package detection looks like the right minimal fix.\n- Current conda-forge can solve python=3.12 with mbuild + openff-toolkit, and also with mbuild-base + openff-toolkit-base. That pair does not appear to be the current hard blocker.\n- The actual hard dependency conflict is in the broader optional/test stack: current mbuild pulls gmso>=0.16.1, which requires numpy>=2.0, while espaloma_charge pulls dgl -> tensorflow-base=2.17.0, whose Python 3.12 build requires numpy>=1.26.4,<2.0a0. This explains the order-dependent NumPy backtracking/regression behavior.\n- The saved sequential-install logs in polymerist_py312_context were pinned to python 3.13.*, not 3.12. For this PR, requires-python should not be opened to unbounded >=3.11 unless we also intend to validate Python 3.13+.\n\nConcrete recommendation:\n- Keep the pkginspect.py importlib fix from this PR.\n- Set requires-python to >=3.11,<3.13 for this pass.\n- Do not force numpy>=2.0 in pyproject while Espaloma/TensorFlow remains in the supported/tested dependency stack. Leave numpy unconstrained at the Polymerist package level and let environment-specific solves choose the compatible side.\n- Restore the unrelated setuptools<82, packmol<=20.15.1, and lammps<=2024.08.29 pins unless/until there is a separate PR validating those changes.\n\nValidation I ran:\n- mamba dry-run solve for the updated Python 3.12 runtime dependency set succeeded.\n- mamba dry-run python=3.12 mbuild openff-toolkit succeeded.\n- Focused test: mamba run -n polymerist-env python -m pytest -q polymerist/tests/genutils/importutils/test_pkginspect.py -> 44 passed, 9 xfailed.

@timbernat timbernat added priority:high Immediate attention required, breaks most or all package-level functionality dependency Changes to how library code interacts with or imports external libraries and removed priority:medium Moderate urgency, issue has major impacts on some but not most parts of the codebase labels Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependency Changes to how library code interacts with or imports external libraries priority:high Immediate attention required, breaks most or all package-level functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Python 3.12

3 participants