Skip to content

Commit eb5592a

Browse files
authored
Add deprecation warnings for removed components (#697)
1 parent 4e3c0ea commit eb5592a

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

dash_bootstrap_components/__init__.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22
import os
33
import sys
44

5-
from dash_bootstrap_components import icons # noqa
6-
from dash_bootstrap_components import themes # noqa
7-
from dash_bootstrap_components import _components
5+
from dash_bootstrap_components import _components, icons, themes
86
from dash_bootstrap_components._components import * # noqa
97
from dash_bootstrap_components._table import _generate_table_from_df
108
from dash_bootstrap_components._version import __version__
119

12-
_current_path = os.path.dirname(os.path.abspath(__file__))
10+
__all__ = _components.__all__ + ["icons", "themes"]
1311

14-
METADATA_PATH = os.path.join(_current_path, "_components", "metadata.json")
12+
_current_path = os.path.dirname(os.path.abspath(__file__))
13+
_METADATA_PATH = os.path.join(_current_path, "_components", "metadata.json")
1514

1615
_js_dist = [
1716
{
1817
"relative_package_path": (
1918
"_components/dash_bootstrap_components.min.js"
2019
),
2120
"external_url": (
22-
"https://unpkg.com/dash-bootstrap-components@{}"
21+
f"https://unpkg.com/dash-bootstrap-components@{__version__}"
2322
"/dist/dash_bootstrap_components.min.js"
24-
).format(__version__),
23+
),
2524
"namespace": "dash_bootstrap_components",
2625
}
2726
]
@@ -38,3 +37,44 @@
3837
sys.modules[__name__].Table.from_dataframe = classmethod(
3938
_generate_table_from_df
4039
)
40+
41+
42+
# TODO: when Python 3.6 support is dropped we can simplify this with PEP 562
43+
# https://www.python.org/dev/peps/pep-0562/
44+
class _V1DeprecationWarningWrapper:
45+
def __init__(self, wrapped, deprecated):
46+
self.wrapped = wrapped
47+
self.deprecated = deprecated
48+
49+
def __getattr__(self, name):
50+
if name in self.deprecated:
51+
# TODO: update URL before release
52+
raise AttributeError(
53+
f"{name} was deprecated in dash-bootstrap-components version "
54+
f"1.0.0. You are using {__version__}. For more details please "
55+
"see the migration guide: "
56+
"https://dbc-v1.herokuapp.com/migration-guide/"
57+
)
58+
return getattr(self.wrapped, name)
59+
60+
def __dir__(self):
61+
# required for autocomplete. filter out os, and sys imports
62+
return [
63+
item
64+
for item in self.wrapped.__dir__()
65+
if item not in {"os", "sys"}
66+
]
67+
68+
69+
sys.modules[__name__] = _V1DeprecationWarningWrapper(
70+
sys.modules[__name__],
71+
[
72+
"CardColumns",
73+
"CardDeck",
74+
"FormGroup",
75+
"InputGroupAddon",
76+
"Jumbotron",
77+
"ListGroupItemHeading",
78+
"ListGroupItemText",
79+
],
80+
)

docs/components_page/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_component_metadata(component_path):
1212

1313
@lru_cache(maxsize=1)
1414
def _load_metadata():
15-
return _get_metadata(dbc.METADATA_PATH)
15+
return _get_metadata(dbc._METADATA_PATH)
1616

1717

1818
def _get_metadata(metadata_path):

0 commit comments

Comments
 (0)