-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Open
bmaranville
wants to merge
82
commits into
plotly:release-6.1.0rc0
Choose a base branch
from
bmaranville:refactor-validators
base: release-6.1.0rc0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor validators #5173
bmaranville
wants to merge
82
commits into
plotly:release-6.1.0rc0
from
bmaranville:refactor-validators
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ly.py into kaleido-docs-updates
Co-authored-by: Emily KL <[email protected]>
Co-authored-by: Emily KL <[email protected]>
Co-authored-by: Emily KL <[email protected]>
Co-authored-by: Emily KL <[email protected]>
Co-authored-by: Emily KL <[email protected]>
…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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.