Repository navigation
Expand file tree
/
Copy pathoptional_deps.py
More file actions
62 lines (55 loc) · 1.45 KB
/
Copy pathoptional_deps.py
File metadata and controls
62 lines (55 loc) · 1.45 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Checks for optional dependencies using lazy import from
`PEP 562 <https://www.python.org/dev/peps/pep-0562/>`_.
"""
from importlib.util import find_spec
# First, the top-level packages:
# TODO: This list is a duplicate of the dependencies in pyproject.toml "all", but
# some of the package names are different from the pip-install name (e.g.,
# beautifulsoup4 -> bs4).
# Some optional parts of the standard library also find a place here,
# but don't appear in pyproject.toml
_optional_deps = [
"asdf_astropy",
"bleach",
"bottleneck",
"bs4",
"bz2", # stdlib
"certifi",
"dask",
"duckdb",
"fsspec",
"h5py",
"html5lib",
"ipykernel",
"IPython",
"ipywidgets",
"ipydatagrid",
"jplephem",
"lxml",
"matplotlib",
"mpmath",
"narwhals",
"numpy_quaddtype",
"pandas",
"PIL",
"polars",
"pytz",
"s3fs",
"scipy",
"skyfield",
"sortedcontainers",
"uncompresspy",
"lzma", # stdlib
"pyarrow",
"pytest_mpl",
"array_api_strict",
]
_deps = {k.upper(): k for k in _optional_deps}
# Any subpackages that have different import behavior:
_deps["PLT"] = "matplotlib"
__all__ = [f"HAS_{pkg}" for pkg in _deps]
def __getattr__(name):
if name in __all__:
return find_spec(_deps[name.removeprefix("HAS_")]) is not None
raise AttributeError(f"Module {__name__!r} has no attribute {name!r}.")