Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Code PR
plotly.graph_objects
, my modifications concern thecodegen
files and not generated files.modified existing tests.
new tutorial notebook (please see the doc checklist as well).
Refactor of validators
This refactor is based on
release-6.0.1rc0
Helps address #1208
Motivation
The large number of files in the
plotly/validators
folder slows down package installation, esp. on systems where files are inspected for viruses during install (e.g. Windows)The majority of the code is duplicated across these files as well, as there are e.g. >650 instances of nearly-identical classes inheriting
_plotly_utils.basevalidators.BooleanValidator
Mitigation
Things to note, in the current validator arrangement:
plotly.validators
inherit directly from classes in_plotly_utils.basevalidators
__init__
plotly.validator_cache.ValidatorCache.get_validator(parent_name, prop_name)
python commands.py codegen
In this PR, the following changes are made:
codegen
, instead of generating and writing thousands of python files toplotly/validators/...
, we create a single JSON file store atplotly/validators/_validators.json
and for each(parent_name, prop_name)
combination we add an entry to the store withValidatorCache.get_validator
method is modified so that rather than calculating an import path and then importing a validator class from the file tree, it looks up the custom kwargs and validator class name from the JSON store, then creates (and caches) a new instance of the validator class frombasevalidators
, with the custom init kwargs, finally returning the instanceplotly.validators
in the codebase are refactored to use theValidatorCache
instead (there were only a handful of these cases)The net result is that the number of files to be installed is reduced from 14981 to 1652.