Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@bmaranville
Copy link
Contributor

Code PR

  • I have read through thecontributing notes and understand the structure of the package. In particular, if my PR modifies code ofplotly.graph_objects, my modifications concern thecodegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

Refactor of validators

This refactor is based onrelease-6.0.1rc0

Helps address#1208

Motivation

The large number of files in theplotly/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:

  1. Nearly all the validator classes inplotly.validators inherit directly from classes in_plotly_utils.basevalidators
  2. None of them override any methods at all, they just provide custom kwargs to__init__
  3. Almost all access to the validators in the codebase is through theplotly.validator_cache.ValidatorCache.get_validator(parent_name, prop_name)
  4. All these validator python source modules aregenerated by the plotly build system, by runningpython commands.py codegen

In this PR, the following changes are made:

  1. Duringcodegen, 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 with
    • "superclass": the name of the validator class to instantiate
    • "params": the custom kwargs to use when instantiating the validator class
  2. TheValidatorCache.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 from
    basevalidators, with the custom init kwargs, finally returning the instance
  3. Usages of direct import of validator classes fromplotly.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.

LiamConnorsand others added30 commitsMarch 25, 2025 10:21
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>
@gvwilson
Copy link
Contributor

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.

@gvwilsongvwilson self-assigned thisMay 12, 2025
@gvwilsongvwilson added featuresomething new P1needed for current cycle communitycommunity contribution labelsMay 12, 2025
@gvwilson
Copy link
Contributor

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

alexcjohnson reacted with heart emoji

@bmaranville
Copy link
ContributorAuthor

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.

@gvwilsongvwilson deleted the branchplotly:release-6.1.0rc0June 4, 2025 12:42
@gvwilson
Copy link
Contributor

closed in favor of#5214 (which rebases these changes on top ofmain).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

@gvwilsongvwilson

Labels

communitycommunity contributionfeaturesomething newP1needed for current cycle

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@bmaranville@gvwilson@LiamConnors@emilykl

[8]ページ先頭

©2009-2025 Movatter.jp