-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modifying 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. 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. Assign an empty string to the `data_docs` field of generated validators. 1. Introduce a method `_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: 50365842 bytes Current size of plotly/**/*.py: 38256842 bytes Change: -26%
- Loading branch information
Showing
14,849 changed files
with
245,607 additions
and
460,318 deletions.
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 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 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,29 @@ | ||
"""Calculate total size and total number of files of package.""" | ||
|
||
from pathlib import Path | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Main driver.""" | ||
assert len(sys.argv) == 3, "Usage: get_size.py src_dir build_dir" | ||
src_files, src_bytes = get_size(sys.argv[1]) | ||
build_files, build_bytes = get_size(sys.argv[2]) | ||
print(f"src,files,{src_files}") | ||
print(f"src,bytes,{src_bytes}") | ||
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 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 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 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 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 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 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.