Skip to content

Commit 9109fbb

Browse files
committed
Adjusted according to review comments
1 parent ead5c06 commit 9109fbb

19 files changed

+98
-169
lines changed

.pylintrc

-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ min-public-methods = 1
1414
good-names = i,
1515
df,
1616
_
17-
18-
[TYPECHECK]
19-
signature-mutators=deprecated_plugin_arguments

CONTRIBUTING.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
- [OAuth 2.0 Authorization Code flow](#oauth-2.0-authorization-code-flow)
1313
- [Run tests](#run-tests)
1414
- [Build documentation](#build-documentation)
15-
- [Deprecate plugins or arguments](#deprecate-plugins-or-arguments)
1615

1716
## Creating a new plugin
1817

@@ -644,7 +643,7 @@ Example of auto-built documentation for `webviz-config` can be seen
644643
Plugins can be marked as deprecated by using the `@deprecated_plugin(short_message, long_message)` decorator.
645644

646645
```python
647-
from ..webviz_deprecated import deprecated_plugin
646+
from webviz_config.webviz_deprecated import deprecated_plugin
648647
649648
650649
@deprecated_plugin("This message is shown to the end user in the app.", "This message is shown in the documentation of the plugin.")
@@ -653,27 +652,37 @@ class MyPlugin(WebvizPluginABC):
653652
```
654653

655654
Plugin arguments can be marked as deprecated by using the `@deprecated_plugin_arguments(check={})` decorator in front of the `__init__` function.
656-
Arguments can either be marked as deprecated in any case (MyPluginExample1) or their values can be checked within a function (MyPluginExample2)
657-
which returns a tuple containing a short string shown to the end user in the app and a long string shown in the plugin's documentation.
655+
Arguments can either be marked as deprecated in any case (see `MyPluginExample1`) or their values can be checked within a function (see `MyPluginExample2`) which returns a tuple containing a short string shown to the end user in the app and a long string shown in the plugin's documentation.
658656

659657
```python
660658
from typing import Optional, Tuple
661-
from ..webviz_deprecated import deprecated_plugin_arguments
659+
from webviz_config.webviz_deprecated import deprecated_plugin_arguments
662660
663661
664662
class MyPluginExample1(WebvizPluginABC):
665663
...
666-
@deprecated_plugin_arguments(check={"arg3": ("This message is shown to the end user in the app.", "This message is shown in the documentation of the plugin.")})
664+
@deprecated_plugin_arguments(
665+
{
666+
"arg3": (
667+
"Short message shown to the end user both in the app and documentation.",
668+
(
669+
"This can be a long message, which is shown only in the documentation, explaining "
670+
"e.g. why it is deprecated and which plugin should be used instead."
671+
)
672+
)
673+
}
674+
)
667675
def __init__(self, arg1: str, arg2: int, arg3: Optional[int] = None):
668676
...
669677
670678
class MyPluginExample2(WebvizPluginABC):
671679
...
672-
@deprecated_plugin_arguments(check=check_deprecation)
680+
@deprecated_plugin_arguments(check_deprecation)
673681
def __init__(self, arg1: str, arg2: int, arg3: Optional[int] = None):
674682
...
675683
676684
def check_deprecation(arg1: int, arg3: int) -> Optional[Tuple[str, str]]:
677685
if arg3 == arg1:
678686
return ("This message is shown to the end user in the app.", "This message is shown in the documentation of the plugin.")
687+
return None
679688
```

examples/basic_example.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pages:
2121
- title: Table example
2222
content:
2323
- DataTable:
24-
csv_file: /home/ruben/repos/webviz-config/examples/example_data.csv
24+
csv_file: ./example_data.csv
2525

2626
- title: PDF example
2727
content:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def get_long_description() -> str:
7777
"cryptography>=2.4",
7878
"dash>=1.16",
7979
"dash-pivottable>=0.0.2",
80-
"decorator>=5.0.6",
8180
"flask-caching>=1.4",
8281
"flask-talisman>=0.6",
8382
"jinja2>=2.10",
@@ -87,6 +86,7 @@ def get_long_description() -> str:
8786
"pyarrow>=0.16",
8887
"pyyaml>=5.1",
8988
"tqdm>=4.8",
89+
"dataclasses>=0.8; python_version<'3.7'",
9090
"importlib-metadata>=1.7; python_version<'3.8'",
9191
"typing-extensions>=3.7; python_version<'3.8'",
9292
"webviz-core-components>=0.1.0",

tests/test_plugin_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import webviz_config
2-
from webviz_config.plugins import metadata
2+
from webviz_config.plugins import METADATA
33

44

55
def test_webviz_config_metadata():
6-
meta = metadata["BannerImage"]
6+
meta = METADATA["BannerImage"]
77

88
assert meta["dist_name"] == "webviz-config"
99
assert meta["dist_version"] == webviz_config.__version__

webviz_config/_config_parser.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from .utils import terminal_colors
1212
from .utils._get_webviz_plugins import _get_webviz_plugins
1313
from ._deprecation_store import (
14-
deprecation_store,
14+
DEPRECATION_STORE,
1515
DeprecatedArgument,
16-
DeprecatedArgumentCheck
16+
DeprecatedArgumentCheck,
1717
)
1818

1919
SPECIAL_ARGS = ["self", "app", "webviz_settings", "_call_signature"]
@@ -25,7 +25,7 @@ def _call_signature(
2525
config_folder: pathlib.Path,
2626
contact_person: typing.Optional[dict] = None,
2727
) -> tuple:
28-
# pylint: disable=too-many-branches,too-many-statements
28+
# pylint: disable=too-many-branches,too-many-statements,too-many-locals
2929
"""Takes as input the name of a plugin together with user given arguments
3030
(originating from the configuration file). Returns the equivalent Python code wrt.
3131
initiating an instance of that plugin (with the given arguments).
@@ -119,13 +119,13 @@ def _call_signature(
119119
kwargs_including_defaults = kwargs
120120
deprecation_warnings = []
121121

122-
deprecated_plugin = deprecation_store().get_stored_plugin_deprecation(
122+
deprecated_plugin = DEPRECATION_STORE.get_stored_plugin_deprecation(
123123
getattr(standard_plugins, plugin_name)
124124
)
125125
if deprecated_plugin:
126126
deprecation_warnings.append(deprecated_plugin.short_message)
127127

128-
deprecations = deprecation_store().get_stored_plugin_argument_deprecations(
128+
deprecations = DEPRECATION_STORE.get_stored_plugin_argument_deprecations(
129129
getattr(standard_plugins, plugin_name).__init__
130130
)
131131

@@ -139,21 +139,21 @@ def _call_signature(
139139
if deprecation.argument_name in kwargs_including_defaults.keys():
140140
deprecation_warnings.append(deprecation.short_message)
141141
warnings.warn(
142-
"""Deprecated Argument: {} with value '{}' in method {} in module {}
142+
"""Deprecated Argument: {} with value '{}' in method {} in module {}
143143
------------------------
144144
{}
145145
===
146146
{}
147147
""".format(
148-
deprecation.argument_name,
149-
kwargs_including_defaults[deprecation.argument_name],
150-
deprecation.method_name,
151-
getattr(deprecation.method_reference, "__module__"),
152-
deprecation.short_message,
153-
deprecation.long_message,
154-
),
155-
DeprecationWarning,
156-
)
148+
deprecation.argument_name,
149+
kwargs_including_defaults[deprecation.argument_name],
150+
deprecation.method_name,
151+
getattr(deprecation.method_reference, "__module__"),
152+
deprecation.short_message,
153+
deprecation.long_message,
154+
),
155+
FutureWarning,
156+
)
157157
elif isinstance(deprecation, DeprecatedArgumentCheck):
158158
mapped_args: typing.Dict[str, typing.Any] = {}
159159
for arg in deprecation.argument_names:
@@ -166,23 +166,24 @@ def _call_signature(
166166
if result:
167167
deprecation_warnings.append(result[0])
168168
warnings.warn(
169-
"""Deprecated Argument(s): {} with value '{}' in method {} in module {}
169+
"""Deprecated Argument(s): {} with value '{}' in method {} in module {}
170170
------------------------
171171
{}
172172
===
173173
{}
174174
""".format(
175175
deprecation.argument_names,
176176
[
177-
value for key, value in kwargs_including_defaults.items()
177+
value
178+
for key, value in kwargs_including_defaults.items()
178179
if key in deprecation.argument_names
179180
],
180181
deprecation.method_name,
181182
getattr(deprecation.method_reference, "__module__"),
182183
result[0],
183184
result[1],
184185
),
185-
DeprecationWarning,
186+
FutureWarning,
186187
)
187188

188189
special_args = ""
@@ -356,9 +357,7 @@ def clean_configuration(self) -> None:
356357
)
357358

358359
plugin["_call_signature"] = _call_signature(
359-
plugin_name,
360-
kwargs,
361-
self._config_folder,
360+
plugin_name, kwargs, self._config_folder,
362361
)
363362

364363
self.assets.update(getattr(standard_plugins, plugin_name).ASSETS)

webviz_config/_deprecation_store.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from dataclasses import dataclass
33

44

5-
@dataclass(eq=True, frozen=True)
5+
@dataclass(frozen=True)
66
class DeprecatedPlugin:
77
class_reference: Any
88
short_message: str
99
long_message: str
1010

11-
@dataclass(eq=True, frozen=True)
11+
12+
@dataclass(frozen=True)
1213
class DeprecatedArgument:
1314
method_reference: Any
1415
method_name: str
@@ -17,7 +18,8 @@ class DeprecatedArgument:
1718
short_message: str
1819
long_message: str
1920

20-
@dataclass(eq=True, frozen=True)
21+
22+
@dataclass(frozen=True)
2123
class DeprecatedArgumentCheck:
2224
method_reference: Any
2325
method_name: str
@@ -42,29 +44,25 @@ def register_deprecated_plugin(self, deprecated_plugin: DeprecatedPlugin) -> Non
4244
] = deprecated_plugin
4345

4446
def register_deprecated_plugin_argument(
45-
self, deprecated_plugin_argument: Union[DeprecatedArgument, DeprecatedArgumentCheck]
47+
self,
48+
deprecated_plugin_argument: Union[DeprecatedArgument, DeprecatedArgumentCheck],
4649
) -> None:
4750
"""This function is automatically called by the decorator
4851
@deprecated_plugin_arguments, registering the __init__ function it decorates.
4952
"""
5053
self.stored_plugin_argument_deprecations.append(deprecated_plugin_argument)
5154

5255
def get_stored_plugin_deprecation(self, plugin: Any) -> Optional[DeprecatedPlugin]:
53-
if plugin in self.stored_plugin_deprecations:
54-
return self.stored_plugin_deprecations[plugin]
55-
return None
56+
return self.stored_plugin_deprecations.get(plugin)
5657

5758
def get_stored_plugin_argument_deprecations(
5859
self, method: Callable
5960
) -> List[Union[DeprecatedArgument, DeprecatedArgumentCheck]]:
60-
deprecations: List[Union[DeprecatedArgument, DeprecatedArgumentCheck]] = []
61-
for stored in self.stored_plugin_argument_deprecations:
62-
if stored.method_reference == method:
63-
deprecations.append(stored)
64-
65-
return deprecations
61+
return [
62+
stored
63+
for stored in self.stored_plugin_argument_deprecations
64+
if stored.method_reference == method
65+
]
6666

67-
def deprecation_store() -> DeprecationStore:
68-
return DEPRECATION_STORE
6967

7068
DEPRECATION_STORE = DeprecationStore()

webviz_config/_docs/_build_docs.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
import webviz_config.plugins
3434
from .._config_parser import SPECIAL_ARGS
3535
from ..utils._get_webviz_plugins import _get_webviz_plugins
36-
from .._deprecation_store import DEPRECATION_STORE, DeprecatedArgument, DeprecatedArgumentCheck
36+
from .._deprecation_store import (
37+
DEPRECATION_STORE,
38+
DeprecatedArgument,
39+
DeprecatedArgumentCheck,
40+
)
3741

3842

3943
class ArgInfo(TypedDict, total=False):
@@ -77,7 +81,10 @@ def _find_plugin_deprecated_arguments(plugin: Any) -> Dict[str, Tuple[str, str]]
7781
# Completely deprecated arguments have priority over deprecation check functions
7882
for deprecated_argument in deprecated_arguments:
7983
if isinstance(deprecated_argument, DeprecatedArgument):
80-
result[deprecated_argument.argument_name] = (deprecated_argument.long_message, "")
84+
result[deprecated_argument.argument_name] = (
85+
deprecated_argument.long_message,
86+
"",
87+
)
8188
return result
8289

8390

@@ -122,10 +129,7 @@ def _extract_init_arguments_and_check_for_deprecation(
122129
result[arg]["typehint_string"] = _annotation_to_string(annotation)
123130

124131
for arg, arg_info in result.items():
125-
if arg in documented_args:
126-
arg_info["description"] = " ".join(documented_args[arg].split())
127-
else:
128-
arg_info["description"] = ""
132+
arg_info["description"] = " ".join(documented_args.get(arg, "").split())
129133

130134
if arg in deprecated_arguments:
131135
arg_info["deprecated"] = True
@@ -152,7 +156,7 @@ def _document_plugin(plugin: Tuple[str, Any]) -> PluginInfo:
152156
(
153157
has_deprecated_arguments,
154158
arguments,
155-
deprecation_check_code
159+
deprecation_check_code,
156160
) = _extract_init_arguments_and_check_for_deprecation(
157161
docstring_parts[1] if len(docstring_parts) > 1 else None, reference
158162
)
@@ -167,13 +171,13 @@ def _document_plugin(plugin: Tuple[str, Any]) -> PluginInfo:
167171
"description": docstring_parts[0] if docstring != "" else None,
168172
"name": name,
169173
"package_doc": import_module(subpackage).__doc__, # type: ignore
170-
"dist_name": webviz_config.plugins.metadata[name]["dist_name"],
171-
"dist_version": webviz_config.plugins.metadata[name]["dist_version"],
174+
"dist_name": webviz_config.plugins.METADATA[name]["dist_name"],
175+
"dist_version": webviz_config.plugins.METADATA[name]["dist_version"],
172176
"deprecated": deprecated is not None,
173177
"deprecation_text_short": deprecated.short_message if deprecated else "",
174178
"deprecation_text_long": deprecated.long_message if deprecated else "",
175179
"has_deprecated_arguments": has_deprecated_arguments,
176-
"deprecation_check_code": deprecation_check_code
180+
"deprecation_check_code": deprecation_check_code,
177181
}
178182

179183
return plugin_info

webviz_config/_docs/_create_schema.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
"content": {
2525
"description": "Content on the page",
2626
"type": "array",
27-
"items": {
28-
"oneOf": [
29-
{"type": "string"},
30-
]
31-
},
27+
"items": {"oneOf": [{"type": "string"},]},
3228
},
3329
},
3430
"required": ["title", "content"],

webviz_config/_docs/open_docs.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def _index() -> str:
2727
webviz_config.utils.LocalhostOpenBrowser(port, token)
2828

2929
app.run(
30-
host="localhost",
31-
port=port,
32-
debug=False,
30+
host="localhost", port=port, debug=False,
3331
)
3432

3533

0 commit comments

Comments
 (0)