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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
174e5ff
Merge branch 'main' into refactor-validators
gvwilson Jun 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
41 changes: 13 additions & 28 deletions codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
build_from_imports_py,
)
from codegen.validators import (
write_validator_py,
write_data_validator_py,
get_data_validator_params,
get_validator_params,
write_validator_json,
get_data_validator_instance,
)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this line -- needs to remain the same as what's in pyproject.toml

Suggested change
BLACK_TARGET_VERSIONS = "py39 py310 py311 py312"
BLACK_TARGET_VERSIONS = "py38 py39 py310 py311 py312"



# Import notes
Expand Down Expand Up @@ -171,22 +172,27 @@ def perform_codegen(reformat=True):
if node.is_compound and not isinstance(node, ElementDefaultsNode)
]

validator_params = {}
# Write out validators
# --------------------
# # ### Layout ###
for node in all_layout_nodes:
write_validator_py(outdir, node)
get_validator_params(node, validator_params)

# ### Trace ###
for node in all_trace_nodes:
write_validator_py(outdir, node)
get_validator_params(node, validator_params)

# ### Frames ###
for node in all_frame_nodes:
write_validator_py(outdir, node)
get_validator_params(node, validator_params)

# ### Data (traces) validator ###
write_data_validator_py(outdir, base_traces_node)
get_data_validator_params(base_traces_node, validator_params)

# Write out the JSON data for the validators
os.makedirs(validators_pkgdir, exist_ok=True)
write_validator_json(outdir, validator_params)

# Alls
# ----
Expand Down Expand Up @@ -217,27 +223,6 @@ def perform_codegen(reformat=True):
layout_array_nodes,
)

# Write validator __init__.py files
# ---------------------------------
# ### Write __init__.py files for each validator package ###
validator_rel_class_imports = {}
for node in all_datatype_nodes:
if node.is_mapped:
continue
key = node.parent_path_parts
validator_rel_class_imports.setdefault(key, []).append(
f"._{node.name_property}.{node.name_validator_class}"
)

# Add Data validator
root_validator_pairs = validator_rel_class_imports[()]
root_validator_pairs.append("._data.DataValidator")

# Output validator __init__.py files
validators_pkg = opath.join(outdir, "validators")
for path_parts, rel_classes in validator_rel_class_imports.items():
write_init_py(validators_pkg, path_parts, [], rel_classes)

# Write datatype __init__.py files
# --------------------------------
datatype_rel_class_imports = {}
Expand Down
9 changes: 3 additions & 6 deletions codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,11 @@ class {datatype_class}(_{node.name_base_datatype}):\n"""
"""
)

subplot_validator_names = [n.name_validator_class for n in subplot_nodes]

validator_csv = ", ".join(subplot_validator_names)
subplot_dict_str = (
"{"
+ ", ".join(
f"'{subname}': {valname}"
for subname, valname in zip(subplot_names, subplot_validator_names)
f'"{subname}": ValidatorCache.get_validator("layout", "{subname}")'
for subname in subplot_names
)
+ "}"
)
Expand All @@ -153,7 +150,7 @@ def _subplotid_validators(self):
-------
dict
\"\"\"
from plotly.validators.layout import ({validator_csv})
from plotly.validator_cache import ValidatorCache

return {subplot_dict_str}

Expand Down
Loading