Skip to content

Add helpful hint error message if optional dependencies not yet installed. - #1656

Open
Sevans711 wants to merge 18 commits into
sevans/tests-for-optional-depsfrom
sevans/_raise_hint_if_optional_deps_missing
Open

Add helpful hint error message if optional dependencies not yet installed.#1656
Sevans711 wants to merge 18 commits into
sevans/tests-for-optional-depsfrom
sevans/_raise_hint_if_optional_deps_missing

Conversation

@Sevans711

@Sevans711 Sevans711 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Addresses part of #1224 #1225 but does not fully close them.

Overview

Adds _raise_hint_if_optional_deps_missing which raises helpful hint upon trying but failing to import optional dependencies due to them not yet being installed.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • Adequate tests are created if there is new functionality
  • Tests are not too basic (such as simply calling a function and nothing else)
  • Tests cover all major paths in your new functions
  • [N/A] If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation

  • Docstrings have been added to all new functions
  • Docstrings have been updated with any function changes
  • [N/A] User (public) functions have been added to docs/api.rst
  • Internal (private) function names start with an underscore (_)

AI Disclosure

AI Usage: GitHub Copilot inline code suggestions, some discussion with Claude.

  • I take responsibility for all AI-generated content in my PR.
  • I have tested all AI-generated content in my PR.

@Sevans711 Sevans711 added the dependencies Pull requests that update a dependency file label Aug 7, 2026
also add string matching to test_check_requires_viz_and_geo in both the installed_with_geo and the installed_with_viz cases, and left a comment about why it wasn't added in the installed_with_no_opts case.
@Sevans711
Sevans711 force-pushed the sevans/_raise_hint_if_optional_deps_missing branch from 03869b5 to 8e2a07a Compare August 10, 2026 14:50
(maybe not necessary… but also trying to re-trigger CI jobs here, due to github actions downtime yesterday causing stalled jobs with no "rerun jobs" button available.)
also add string matching to test_check_requires_viz_and_geo in both the installed_with_geo and the installed_with_viz cases, and left a comment about why it wasn't added in the installed_with_no_opts case.
@Sevans711
Sevans711 force-pushed the sevans/_raise_hint_if_optional_deps_missing branch from 8e2a07a to 1210ae0 Compare August 10, 2026 20:02

@rajeeja rajeeja 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.

One unreachable branch, see inline.

Comment thread uxarray/utils/imports.py Outdated
extra in need_extras for extra in extras
): # still maybe in case (1) or (2).
pass # this package is already covered by other needed extras!
elif len(extras) == 0: # case (3)

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.

Unreachable — the assert above guarantees len(extras) >= 2, so this likely wants >= 2 not == 0. Means a cartopy-only miss suggests [all] instead of [geo] or [viz].

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for looking into this! Commit 0f638de fixes this, makes slight improvements to message readability in case of many extras, and adds a test to the CI with expectations about the error messages. That test would have crashed before this fix, and it hard-codes the expected error messages for clarity and readability.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@Sevans711
Sevans711 requested a review from rajeeja August 14, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants