Skip to content

refactor validators to remove duplicate files #5214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2cf19ff
removing old generated validators
bmaranville May 8, 2025
1f911b6
write single json instead of python files
bmaranville May 8, 2025
930509f
generate validator class instances from json data
bmaranville May 8, 2025
3fd1cfd
use validators from ValidatorCache
bmaranville May 8, 2025
665595d
use validators from ValidatorCache
bmaranville May 8, 2025
af43f68
use DataValidator from ValidatorCache
bmaranville May 8, 2025
771f918
trace validator should be instance not class of DataValidator
bmaranville May 8, 2025
6d905e7
use validators from ValidatorCache
bmaranville May 8, 2025
58ab3e1
use template validator from ValidatorCache
bmaranville May 8, 2025
44f7a4e
allow overlaying args on derived classes
bmaranville May 8, 2025
2507be9
add DataValidator to autogenerated instances provided by ValidatorCac…
bmaranville May 8, 2025
5d1ccdb
add DataValidator to autogenerated instances provided by ValidatorCac…
bmaranville May 8, 2025
6bd2bb3
add DataValidator to autogenerated instances provided by ValidatorCac…
bmaranville May 8, 2025
fdaf441
use a copy of the DataValidator in BaseFigure, with local set_uid att…
bmaranville May 8, 2025
7baa252
update validator params store
bmaranville May 8, 2025
0e913eb
DataValidator is an instance already, and is not callable
bmaranville May 8, 2025
ba8ec10
use heatmap colorscale validator
bmaranville May 8, 2025
2454767
update documentation example to use validator from ValidatorCache
bmaranville May 8, 2025
c62f6cb
cleanup
bmaranville May 9, 2025
cb4c504
black formatting
bmaranville May 9, 2025
6f777ef
black formatting
bmaranville May 9, 2025
6be6f28
revert this file - it is auto-generated
bmaranville May 9, 2025
1b99411
cleanup
bmaranville May 9, 2025
03d85de
use ValidatorCache for generated Layout validators
bmaranville May 9, 2025
f8daca4
black formatting
bmaranville May 9, 2025
0184bd4
feat: regenerating validators with all recent changes
gvwilson Jun 4, 2025
513337c
fix: address code review issues
emilykl Jun 4, 2025
37c387e
fix path to _validators.json
emilykl Jun 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: address code review issues
-   fix black exclude parameter in pyproject.toml to properly exclude ONLY directories
-   reintroduce py38 in codegen/__init__.py
-   remove commented-out lines
-   add plotly/validators/_validators.json to pyproject.toml
-   regenerate code
  • Loading branch information
emilykl authored and gvwilson committed Jun 10, 2025
commit 513337ccb66c7727d0929fdd5da3a9a3063b2ef4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ See the [Python documentation](https://plotly.com/python/) for more examples.

Built on top of [plotly.js](https://github.com/plotly/plotly.js), `plotly.py` is a high-level, declarative charting library. plotly.js ships with over 30 chart types, including scientific charts, 3D graphs, statistical charts, SVG maps, financial charts, and more.

`plotly.py` is [MIT Licensed](https://github.com/plotly/plotly.py/blob/main/LICENSE.txt). Plotly graphs can be viewed in Jupyter and marimo notebooks, standalone HTML files, or integrated into [Dash applications](https://dash.plotly.com/).
`plotly.py` is [MIT Licensed](https://github.com/plotly/plotly.py/blob/main/LICENSE.txt). Plotly graphs can be viewed in [Jupyter notebooks](https://jupyter.org), other Python notebook software such as [marimo](https://marimo.io), as standalone HTML files, or integrated into [Dash applications](https://dash.plotly.com/).

[Contact us](https://plotly.com/consulting-and-oem/) for consulting, dashboard development, application integration, and feature additions.

Expand Down
2 changes: 1 addition & 1 deletion codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Target Python version for code formatting with Black.
# Must be one of the values listed in pyproject.toml.
BLACK_TARGET_VERSIONS = "py39 py310 py311 py312"
BLACK_TARGET_VERSIONS = "py38 py39 py310 py311 py312"


# Import notes
Expand Down
1 change: 0 additions & 1 deletion codegen/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def write_validator_json(outdir, params: dict):
filepath = opath.join(outdir, "validators", "_validators.json")
with open(filepath, "w") as f:
f.write(json.dumps(params, indent=4))
# f.write(str(params))


def build_data_validator_params(base_trace_node: TraceNode):
Expand Down
15 changes: 7 additions & 8 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,9 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
"""
from .validator_cache import ValidatorCache

DataValidator = ValidatorCache.get_validator("", "data")
FramesValidator = ValidatorCache.get_validator("", "frames")
LayoutValidator = ValidatorCache.get_validator("", "layout")
# from .validators import DataValidator, LayoutValidator, FramesValidator
data_validator = ValidatorCache.get_validator("", "data")
frames_validator = ValidatorCache.get_validator("", "frames")
layout_validator = ValidatorCache.get_validator("", "layout")

super(BaseFigure, self).__init__()

Expand Down Expand Up @@ -526,8 +525,8 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
# This is the validator that handles importing sequences of trace
# objects
# We make a copy because we are overriding the set_uid attribute
# and do not want to alter all other uses of the cached DataValidator
self._data_validator = copy(DataValidator)
# and do not want to alter all other uses of the cached data_validator
self._data_validator = copy(data_validator)
self._data_validator.set_uid = self._set_trace_uid

# ### Import traces ###
Expand Down Expand Up @@ -571,7 +570,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
# ------
# ### Construct layout validator ###
# This is the validator that handles importing Layout objects
self._layout_validator = LayoutValidator
self._layout_validator = layout_validator

# ### Import Layout ###
self._layout_obj = self._layout_validator.validate_coerce(
Expand Down Expand Up @@ -606,7 +605,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
# ### Construct frames validator ###
# This is the validator that handles importing sequences of frame
# objects
self._frames_validator = FramesValidator
self._frames_validator = frames_validator

# ### Import frames ###
self._frame_objs = self._frames_validator.validate_coerce(
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ plotly = [
"package_data/*",
"package_data/templates/*",
"package_data/datasets/*",
"plotly/validators/_validators.json"
]

[tool.black]
line-length = 88
target_version = ['py38', 'py39', 'py310', 'py311', 'py312']
include = '\.pyi?$'
exclude = '''

(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.hg
Expand All @@ -85,7 +85,7 @@ exclude = '''
| js
| submodules
| plotly/matplotlylib/mplexporter
)
)/
'''

[tool.jupyter-packaging.builder]
Expand Down
Loading