-
Notifications
You must be signed in to change notification settings - Fork 40
Name the installable package in missing dependency errors #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75fcf6c
0a4cf24
d44ad7d
3053d25
1b36041
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| from __future__ import annotations | ||
|
|
||
| import inspect | ||
| import re | ||
| import warnings | ||
| from collections import defaultdict | ||
| from collections.abc import ( | ||
|
|
@@ -61,6 +62,8 @@ | |
| from dascore.utils.io import IOResourceManager, get_handle_from_resource | ||
| from dascore.utils.mapping import FrozenDict | ||
| from dascore.utils.misc import ( | ||
| _get_install_message, | ||
| _get_install_name, | ||
| _iter_filesystem, | ||
| _locked, | ||
| _reinit_after_fork, | ||
|
|
@@ -1298,6 +1301,23 @@ def _count_generator(generator): | |
| return entity_count | ||
|
|
||
|
|
||
| _MISSING_MODULE_PATTERN = re.compile(r"^(\S+) is not installed") | ||
|
|
||
|
|
||
| def _get_missing_install_name(exception: MissingOptionalDependencyError) -> str: | ||
| """Get the installable package name from a missing dependency error.""" | ||
| if exception.install_name: | ||
| return exception.install_name | ||
| # Errors raised outside of optional_import (eg by a third party FiberIO) | ||
| # identify the module, if at all, with the module name or the message form | ||
| # optional_import used to use. Any other message could say anything, so | ||
| # nothing is recommended for installation. | ||
| if not (name := exception.name or ""): | ||
| match = _MISSING_MODULE_PATTERN.match(exception.msg or "") | ||
| name = match.group(1) if match else "" | ||
| return _get_install_name(name) | ||
|
|
||
|
|
||
| def _handle_missing_optionals(output_count, optional_dep_dict): | ||
| """ | ||
| Inform the user there are files that can be read but the proper | ||
|
|
@@ -1306,10 +1326,17 @@ def _handle_missing_optionals(output_count, optional_dep_dict): | |
| If there are other readable files that were found, raise a warning. | ||
| Otherwise, raise a MissingOptionalDependencyError. | ||
| """ | ||
| counts = ", ".join( | ||
| f"{name or 'unknown'} ({count} files)" | ||
| for name, count in sorted(optional_dep_dict.items()) | ||
| ) | ||
| # Unidentifiable packages can't be included in an install command. | ||
| packages = [x for x in optional_dep_dict if x] | ||
| install = f" {_get_install_message(packages)}" if packages else "" | ||
| msg = ( | ||
| f"DASCore found files that can be read if additional packages are " | ||
| f"installed. The needed packages and the found number of files are: " | ||
| f"{dict(optional_dep_dict)}" | ||
| f"{counts}.{install}" | ||
| ) | ||
| warn_or_raise( | ||
| msg, | ||
|
|
@@ -1416,7 +1443,7 @@ def _iter_scan_results( | |
| scan_kwargs["snap"] = snap | ||
| source = fiber_io.scan(resource, **scan_kwargs) | ||
| except MissingOptionalDependencyError as ex: | ||
| missing_optional_deps[ex.msg.split(" ")[0]] += 1 | ||
| missing_optional_deps[_get_missing_install_name(ex)] += 1 | ||
| continue | ||
|
Comment on lines
1445
to
1447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| # scan() is best-effort across many resources, so surface | ||
| # dependency/compatibility problems as warnings and keep | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 50370
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 13842
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 23056
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 50370
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 18299
🏁 Script executed:
Repository: DASDAE/dascore
Length of output: 277
Handle missing optional dependencies for directory scans.
fiber_io.scanat line 1438 runs outside theMissingOptionalDependencyErrorhandler. A directory FiberIO plugin that requires an optional package can abortdc.scaninstead of aggregating the dependency and continuing. Add equivalent handling for directory scans.🤖 Prompt for AI Agents