-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Refactor validators #5173
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
Refactor validators #5173
Conversation
...ly.py into kaleido-docs-updates
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
Co-authored-by: Emily KL <4672118+emilykl@users.noreply.github.com>
...ly.py into kaleido-docs-updates
...ly.py into kaleido-docs-updates
...DataValidator now
...y into refactor-validators
this is looking good - thank you very much @bmaranville. We won't try to get it into the 6.1 release, but it will definitely be part of 6.2.
Note: plotly.py 6.1.0rc0 is 7549710 bytes as a .tar.gz; these changes get that down to 6601687 bytes, which is a 12.5% reduction on top of the reductions in #4978. cc @alexcjohnson
this is looking good - thank you very much @bmaranville. We won't try to get it into the 6.1 release, but it will definitely be part of 6.2.
That's great! Thanks very much for walking me through the code paths related to this issue. I look forward to seeing it in the 6.2 release.
Code PR
plotly.graph_objects, my modifications concern thecodegenfiles 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.1rc0Helps address #1208
Motivation
The large number of files in the
plotly/validatorsfolder 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.BooleanValidatorMitigation
Things to note, in the current validator arrangement:
plotly.validatorsinherit directly from classes in_plotly_utils.basevalidators__init__plotly.validator_cache.ValidatorCache.get_validator(parent_name, prop_name)python commands.py codegenIn 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.jsonand for each(parent_name, prop_name)combination we add an entry to the store withValidatorCache.get_validatormethod 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.validatorsin the codebase are refactored to use theValidatorCacheinstead (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.