Skip to content

check_ar6_magicc7_version reports a missing openscm_runner when the real cause is a different ImportError #71

Description

@karla-spiller

Summary

check_ar6_magicc7_version in src/gcages/ar6/scm_running.py catches any ImportError from import openscm_runner.adapters and reports it as a missing optional dependency:

try:
    import openscm_runner.adapters  # noqa: PLC0415
except ImportError as exc:
    raise MissingOptionalDependencyError(
        "check_ar6_magicc7_version", requirement="openscm_runner"
    ) from exc

ModuleNotFoundError subclasses ImportError, so a failure inside openscm_runner is reported as openscm_runner being absent.

What it looks like

On Python 3.12+, openscm_runner.adapters imports the CICERO-SCM adapter, which imports distutils — removed from the standard library in 3.12 (openscm/openscm-runner#110). With openscm_runner installed and importable, we got:

MissingOptionalDependencyError: `check_ar6_magicc7_version` requires openscm_runner to be installed

The suggested fix is to install a package that is already installed. The actual missing module is distutils, which the message never mentions. The chained __cause__ carries it, but the top-level message is what gets read and acted on — it cost us a while to get past.

Suggested fix

Distinguish "the package is absent" from "the package failed to import". For example:

try:
    import openscm_runner.adapters
except ImportError as exc:
    if getattr(exc, "name", None) in {"openscm_runner", None}:
        raise MissingOptionalDependencyError(
            "check_ar6_magicc7_version", requirement="openscm_runner"
        ) from exc
    raise

Re-raising preserves the original message, which names distutils directly. Alternatively, keep MissingOptionalDependencyError but include str(exc) in the message.

Verified against the current release (v0.14.0).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions