Add helpful hint error message if optional dependencies not yet installed. - #1656
Add helpful hint error message if optional dependencies not yet installed.#1656Sevans711 wants to merge 27 commits into
Conversation
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.
03869b5 to
8e2a07a
Compare
(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.
8e2a07a to
1210ae0
Compare
rajeeja
left a comment
There was a problem hiding this comment.
One unreachable branch, see inline.
| 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) |
There was a problem hiding this comment.
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].
There was a problem hiding this comment.
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.
…/github.com/UXARRAY/uxarray into sevans/_raise_hint_if_optional_deps_missing
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
…_if_optional_deps_missing
| _raise_hint_if_optional_deps_missing("pyproj") | ||
| from pyproj import Geod |
There was a problem hiding this comment.
This pattern looks like it will be difficult to maintain consistently throughout the codebase as we develop it. If we're going to have this, there should definitely be some kind of linting for this so we'll know in the PRs if these are done correctly, and provide an easy way to fix it.
There was a problem hiding this comment.
Thank you for looking into this! Commit c78f80a adds a test to the pytest test suite which should fail if anyone defines a function that imports optional dependencies without all of them being properly included in a call to _raise_hint_if_optional_deps_missing(). The failure mode includes a helpful message which should make it clear enough on how to fix it.
(It also raises clear warnings if bonus optional dependencies are being included, unnecessarily, inside a call to the raise_hint... function.)
I chose to implement this as a pytest test instead of full-blown linting because I have a suspicion that this will be easier to maintain (e.g., I'm not yet familiar with building customized linting algorithms). There's no "fix it for me" button like a proper linting algorithm might provide, but I think that this should still be sufficient? I believe it grants the most important benefits of ensuring this pattern gets maintained, and providing clear instructions for how to fix if it if needed.
There was a problem hiding this comment.
Eh, it's better, but the "fix it for me" button is my ideal in this case.
Ensures it is being used properly throughout the codebase. (Claude helped me write this but I read through it all and poked around slightly to improve function names and add more documentation.)
…_if_optional_deps_missing
This reverts commit 686d1f8.
…_if_optional_deps_missing
Addresses part of #1224 #1225 but does not fully close them.
Overview
Adds
_raise_hint_if_optional_deps_missingwhich raises helpful hint upon trying but failing to import optional dependencies due to them not yet being installed.PR Checklist
General
Testing & Benchmarking
Documentation
docs/api.rst_)AI Disclosure
AI Usage: GitHub Copilot inline code suggestions, some discussion with Claude.