-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: modifying code generation to reduce bundle size #4978
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
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3cb9303
feat: modify code generation to reduce bundle size
gvwilson 556dd53
merging latest changes from master
gvwilson 13df0c5
feat: merging code generator work with latest changes on master
gvwilson d339c7b
Merge branch 'main' into codegen2
gvwilson 51911a4
merge: branch 'main' into codegen2
gvwilson c3dbd41
feat: update black and format code to match Python 3.11
gvwilson d69844f
feat: incorporating feedback from @emilykl
gvwilson 97c418f
feat: adding https://plotly.com/python/css-colors/ URL for colors.
gvwilson 0fc297e
Merge branch 'main' into codegen2
gvwilson a7f5810
feat: rebuilding after merging main
gvwilson db82ee4
fix: satisfying black formatting
gvwilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
Next
Next commit
feat: modify code generation to reduce bundle size
1. Add `bin/get_size.py` so that `python bin/get_size.py plotly build` reports the number of files and total size in bytes of the `plotly` directory (where generated code is put) and the `build` directory that is populated by `python setup.py build`. 1. Modify `codegen/__init__.py` and `./setup.py` so that `python setup.py --reformat=false` disables reformatting. 1. Assign an empty string to the `data_docs` field of generated validators. (This has a major impact because those docs are duplicated many times.) 1. Alias name of base validator during import in `codegen/validators.py`. 1. Remove the long list of CSS colors from help strings for color properties. 1. Replace `super(Parent, self)` with `super()` in generated code. 1. Drop use of sys.version_info and TYPE_CHECKING. Removed the check for Python < 3.7 using `sys.version_info` and as a backup checking `typing.TYPE_CHECKING`; this saves a little space and also cleans up the code. 1. Remove mention of Chart Studio and explicit enumeration of system font names from plotly.js / plot-schema.json so that this text isn't copied dozens of times into the plotly.py bundle. 1. Introduce `_init_provided()` for `BaseFigure` and `BasePlotlyType` that calls a helper function `_initialize_provided()` to replace repetitions of: ``` _v = arg.pop("something", None) _v = something if something is not None else _v if _v is not None: self["something"] = _v ``` Original size of plotly/**/*.py: 42283582 bytes Current size of plotly/**/*.py: 31931739 bytes Change: -25%
- Loading branch information
commit 3cb93037ff81940f6e9fc0284729e18d06b863fe
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Calculate total size and total number of files of package.""" | ||
|
||
from pathlib import Path | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Main driver.""" | ||
assert 2 <= len(sys.argv) <= 3, "Usage: get_size.py src_dir [build_dir]" | ||
|
||
src_files, src_bytes = get_size(sys.argv[1]) | ||
print(f"src,files,{src_files}") | ||
print(f"src,bytes,{src_bytes}") | ||
|
||
if len(sys.argv) == 3: | ||
build_files, build_bytes = get_size(sys.argv[2]) | ||
print(f"build,files,{build_files}") | ||
print(f"build,bytes,{build_bytes}") | ||
|
||
|
||
def get_size(root_dir): | ||
"""Count files and size in bytes.""" | ||
num_files, num_bytes = 0, 0 | ||
for f in Path(root_dir).glob("**/*.*"): | ||
if "__pycache__" not in str(f): | ||
num_files += 1 | ||
num_bytes += f.stat().st_size | ||
return num_files, num_bytes | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.