Spaces:
Running
Running
File size: 999 Bytes
f3270e6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# Copyright (C) 2021-2025, Mindee.
# This program is licensed under the Apache License 2.0.
# See LICENSE or go to <https://opensource.org/licenses/Apache-2.0> for full license details.
import importlib.metadata
import logging
__all__ = ["requires_package", "CLASS_NAME"]
CLASS_NAME: str = "words"
ENV_VARS_TRUE_VALUES = {"1", "ON", "YES", "TRUE"}
def requires_package(name: str, extra_message: str | None = None) -> None: # pragma: no cover
"""
package requirement helper
Args:
name: name of the package
extra_message: additional message to display if the package is not found
"""
try:
_pkg_version = importlib.metadata.version(name)
logging.info(f"{name} version {_pkg_version} available.")
except importlib.metadata.PackageNotFoundError:
raise ImportError(
f"\n\n{extra_message if extra_message is not None else ''} "
f"\nPlease install it with the following command: pip install {name}\n"
)
|