Print a hint when one of optional dependencies of a package not found
Project description
Optional Dependency Hint
This package gives a clearer ImportError message when an
optional dependency is missing, including an install hint like
pip install mypkg[extra].
Installation
pip install optional-dependency-hint
Requirements
- Python
>=3.8
Quick Start
import optdep
# Declare `tqdm` as an optional dependency of `mypkg`
# and tell users how to install it.
optdep.add("tqdm", "mypkg", "progbar")
import tqdm
# If `tqdm` is missing:
# ImportError: Optional dependency tqdm is not installed.
# You may install it with mypkg by: `pip install mypkg[progbar]`
If you only want the default message without install instructions:
import optdep
optdep.add("tqdm")
import tqdm
# If `tqdm` is missing:
# ImportError: Optional dependency tqdm is not installed.
API
optdep.add(module_name, this_pkg_name=None, extra=None, exist_behavior="skip")
module_name(str): target optional dependency module name.this_pkg_name(str | None): your package name shown in hint message.extra(str | None): extra name shown aspkg[extra].exist_behavior("skip" | "overwrite" | "error"): behavior when the module was already registered.
exist_behavior semantics
skip(default): keep old registration.overwrite: replace old registration with the new one.error: raiseRuntimeError.
Notes
- Call
optdep.add(...)before importing the optional module. - This package registers an import hook via
sys.meta_pathat import time.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optional_dependency_hint-0.1.0.tar.gz.
File metadata
- Download URL: optional_dependency_hint-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e44674cf5529ba6c99f3d8d40cf0d0a28a64a822aab872a19e611a5873feedf
|
|
| MD5 |
722001c7fcfdc5221e109bed257b2c83
|
|
| BLAKE2b-256 |
1f36a9d47e8fdd1be4298d54d5f251595fafc2fa850549ac9ffe9ce0569128f9
|
File details
Details for the file optional_dependency_hint-0.1.0-py3-none-any.whl.
File metadata
- Download URL: optional_dependency_hint-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0fd85e57853558c62019d8d9f103dcae323dc25b2cdafc6e356428cd324e2b7
|
|
| MD5 |
2ec1e92b1442577911c9e4bf0fbcb91c
|
|
| BLAKE2b-256 |
f58a3067f73a5c049e2e7ac085e6c9b2fb4a6574311b853702a3ed54a4239eec
|