Skip to content

Add easy-to-use dependency checkers and module inspection - #92

Open
timbernat wants to merge 26 commits into
mainfrom
dependencies
Open

Add easy-to-use dependency checkers and module inspection#92
timbernat wants to merge 26 commits into
mainfrom
dependencies

Conversation

@timbernat

@timbernat timbernat commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Many places in current and planned MuPT code will require specialize and potentially expensive-to-import non-stdlib dependencies, e.g.:

  • openff-toolkit
  • mbuild
  • rdkit
  • polymerizeit

Given the modular nature of the library, it would be unreasonable to ship every external dependency from every subpackage as the base set of required dependencies for mupt. Instead, it is desirable to provide mechanisms for contributors to declare dependencies up-front and provide callers with more targeted warnings and installation instructions when missing dependencies are encountered.

Further, tools for inspecting the presence and contents of other libraries or other even subpackages of mupt would be desirable for enhancing the developer experience. Use cases include loading pre-compiled data for unit testing or skipping tests (rather than failing them) if certain dependencies are missing,

Todos

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

  • Provide utilities for checking dependencies
    • @requires-type decorator to pre-declare dependencies needed for function or class definitions
    • Provide custom Exception with targeted messages describing declared use case, calling module, and installation instruction if the latter applies
    • Functions for pre-checking if module(s) are installed without just raising ImportError
  • Utilities for inspecting the contents of packages
    • Mechanisms for distinguishing packages vs modules
    • Mechanisms for reading non-code resources (e.g. data files) from packages

Questions

  • Want to tighten up terminology and ensure "library", "module", and "package" are used consistently and correctly throughout

Status

  • Apply dependency checks to places in current code which require external libraries
  • Write tests for new functionality
    • Ensure tests pass on CI run
  • Address Copilot suggestions
  • Pass human-moderated review
  • Ready to go

@timbernat timbernat self-assigned this Aug 1, 2026
@timbernat timbernat added enhancement New feature or request internal Relating to how parts of the internal, non-user-facing API communicate labels Aug 1, 2026
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.53571% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mupt/mutils/imports/names.py 0.00% 20 Missing ⚠️
mupt/mutils/imports/dependencies.py 82.50% 7 Missing ⚠️
mupt/mutils/imports/inspection.py 81.25% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

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 introduces a small mupt.mutils.imports utility subpackage to (a) check for optional dependencies without importing them and (b) inspect modules/packages and access package-shipped resources, along with tests and packaged test data to support these behaviors.

Changes:

  • Added dependency-checking utilities (module_installed, modules_installed, @requires_modules) and a custom missing-dependency exception.
  • Added module/package inspection helpers and package-resource path helpers.
  • Added pytest coverage for new functionality and included mupt.tests.data as package data for resource-loading tests.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
pyproject.toml Adds setuptools package-data config so test resources under mupt.tests.data are included.
mupt/mutils/imports/init.py Introduces the new mutils.imports subpackage namespace.
mupt/mutils/imports/dependencies.py Implements dependency presence checks, decorator enforcement, and a custom exception.
mupt/mutils/imports/inspection.py Implements module/package inspection helpers (and calling-module lookup).
mupt/mutils/imports/names.py Adds helpers for generating module name/label components.
mupt/mutils/imports/resources.py Implements helpers for locating resources within a package.
mupt/tests/mutils/imports/init.py Adds tests package init for the new test suite.
mupt/tests/mutils/imports/test_dependencies.py Adds tests for dependency checking and decorator behavior.
mupt/tests/mutils/imports/test_inspection.py Adds tests for module/package inspection behavior.
mupt/tests/mutils/imports/test_resources.py Adds tests for package resource fetching using packaged test data.
mupt/tests/data/init.py Defines mupt.tests.data as an importable package for resource tests.
mupt/tests/data/sample.dat Sample packaged resource file used by tests.

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

Comment thread mupt/mutils/imports/dependencies.py
Comment thread mupt/mutils/imports/dependencies.py Outdated
Comment thread mupt/mutils/imports/dependencies.py
Comment thread mupt/mutils/imports/dependencies.py Outdated
Comment thread mupt/mutils/imports/inspection.py Outdated
Comment thread mupt/mutils/imports/resources.py Outdated
Comment thread mupt/tests/mutils/imports/test_resources.py Outdated
Comment thread mupt/tests/mutils/imports/test_dependencies.py Outdated
Comment thread mupt/mutils/imports/dependencies.py
Comment thread mupt/mutils/imports/dependencies.py Outdated
timbernat and others added 11 commits July 31, 2026 21:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@timbernat
timbernat requested a review from dwhswenson August 6, 2026 20:46
@timbernat

Copy link
Copy Markdown
Collaborator Author

@dwhswenson Poking for review when you have time; less urgent, but does streamline integration PRs going forward.

For some reason, I don't see an option to run tests thru CI on this PR, and rerunning the Action hangs indefinitely. Any idea what's going on?

image

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

Labels

enhancement New feature or request internal Relating to how parts of the internal, non-user-facing API communicate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants