Skip to content

Commit

Permalink
Andrew/baile (plotly#244)
Browse files Browse the repository at this point in the history
* Delete vendor path in app.py

* Add mocks to test app.py

* Improve app.py to can test it

* Use subscribe_once() in to_image()

* Change isinstance to remove dependency

* Delete useless tuple

* Create create baile, init module and process_images

* Import json in app.py

* Create imports in init module

* Change make_spec to to_spec

* Delete transform function

* Format

* Delete to_spec of init module

* Move html and js files to vendor/

* Update path of script_path in process_images.py

* Create process_images() and update to_image() use in app.py

* Improve baile import in app.py

* Change tuple to list in init module

* Create .gitignore

* Delete asyncio import and format process_images.py

* Create pyproject.toml

* Add version of dependency in pyproject.toml

* Add *.egg-info/ in .gitignore

* Create results/ and placeholder

* Create and delete some comments in process_images.py

* Add and modify some comments in process_images,py

* Add comment in process_images.py:to_spec()

* Reorganize some constants in process_images.py

* Create get_figure_dimensions() in process_images.py

* Create get_image_by_response() in process_image.py

* Format get_image_by_response()

* Lint

* Reorganize to_image()

* Create verify_format() in process_images.py

* Rename some variables to use snake_case in app.py

* Add comments and format code in app.py

* Modify comment

* Create Tab class in tab.py

* Add Tab in init module

* Simplify some default values in to_spec()

* Change get_image_by_response() to from_response()

* Simplify some default values in to_image()

* Reorganize to_image()

* Simplify conditionals to get parameters

* Create layout_opts parameter and get_layout_info()

* Improve constants use in get_layout_info()

* Add strategy to read and write files with to_image()

* Create write_file() in process_images.py

* Fix inheritance issue

* Update app.py

* Improve get_layout_info() with conditionals

* Add path in to_image() of app.py

* Add warning in to_image() of process_images.py

* Use try except in write_file()

* Move app.py to tests/

* Format tests/app.py

* Move mocks and results folders to tests/

* Rename results/ to images/

* Update .gitignore for folder rename

* Update path in app.py for folder rename

* Use new thread to run write_file() in to_image()

* Create prepare.py

* Rename process_image.py to main.py

* Add mathjax to vendor/

* Add mathjax as script in baile/vendor/index.html

* Add rule to avoid ignore placeholder in .gitignore

* Add .gitkeep to keep tests/images directory

* Delete placeholder in images/

* Delete placeholder in .gitignore

* Modify comment in .gitignore

* Change import in init module

* Create create() in Tab and use it in main.py:to_image()

* Change create to a classmethod and modify init in tab.py

* Create browser.py

* Update main to use baile.Browser

* Delete useless method in Tab

* Create _from_json_to_img() in main.py

* Create _verify_path_and_name() in main.py

* Create _run_in_chromium() in main.py

* Add some comments in main.py:to_image()

* Format main.py

* Improve main.py to can use multiple jsons and create some methods

* Update app.py

* Use Browser without context in main.py

* Add strategy about queue for tabs and add some comments

* Add debugs in main.py:_run_in_chromium()

* Update app.py

* Improve browser to use context, debug and timeout

* Improve some debugs in main.py:_run_in_chromium()

* Update app.py

* Changes for improvements

* Add conditionals and parameters to debug in main.py

* Add headless parameter in to_image()

* Lint and format main.py

* Delete useless imports in app.py

* Add argparse to improve app.py

* Format app.py

* Add startegy to use argparse for the mocks in app.py

* Improve app.py to use --benchmark flag

* Improve 'Benchmark' print

* Change 'file' to 'path_mock' in app.py

* Change 'path_mock' to 'mock_path' in app.py

* Reorganize _run_in_chromium() to fixbug

* Add --headless and --no_headless flags to use in app.py

* Rename _verify_figures() to _get_json_path() in main.py

* Rename _verify_path_and_name() to _load_figure()

* Rename print_todo() to print_from_event()

* Rename _run_in_chromium() to _generate_image()

* Rename _from_json_to_img() to _run_kaleido_in_tab()

* Change to_image() to create_image()

* Rename verify_format() to get_format() in prepare.py

* Rename prepare.py to fig_properties.py

* Change write_file() to _write_file()

* Use logging module to improve logs

* Change warning to logging.warning in main.py

* Improve the use of logging with levels and handlers

* Change exception to error and use basicConfig in main.py

* Improve the logic to get logger in main.py and add handler

* Format main.py

* Improve the use of the handler in the logger in app.py

* Use the handler and the name in the logger in fig_properties.py

* Use relative path for the logger in app.py

* Use kwargs in browser.py

* Move SCRIPT_PATH from fig_properties.py to browser.py

* Create custom_logging.py

* Add comments in custom_logging.py

* Use custom_logging.py in main.py

* Use custom_logging.py in app.py

* Avoid use logging in app.py and use print

* Delete useless import

* Add level with logging and simplify the use of inspect

* Add empty tuple to avoid error in debug2()

* Delete useless import in custom_logging.py

* Add handler in custom_logging.py

* Improve message in debug2()

* Simplify debug2()

* Delete default level in custom_logging.py

* Use capitalize() for functions name in custom_logging.py

* Use upper() for the functions in custom_logging.py

* Create _get_name() function in custom_logging.py

* Improve _get_name() with conditionals and add () in the return

* Format custom_logging.py

* Use custom_logging.py in fig_properties.py

* Add conditional to detect error in send_comand() in main.py

* Add comment in custom_logging.py

* Add and improve comments in custom_logging.py

* Change chereograper to choreographer in the main.py imports

* Change overwrite to wrap in custom_logging.py comments

* Reorganize functions in custom_logging.py

* Change _log() to log() in custom_logging.py

* Improve _get_name() to add the logging function in the return

* Add formatter in custom_logging.py

* Add package in _get_name()

* Rename logging_function to level in _get_name()

* Add tag parameter to all the levels in custom_logging.py

* Add conditionals and simplify _get_name()

* Add : in conditional to fix bug

* Format custom_logging.py

* Delete custom_logging.py and use logistro package

* Use logistro to improve the paser in app.py

* Change customize_parser() use in app.py for logistro update

* Format test

* Add boiler plate to pyproject.toml

* Reorganize classes

* Make page wait until loaded event

* Organize default args for tab.write_fig

* Generate path/filename automatically

* Update manual test to new api

* Add iterable support for write_fig

* Debug path generation semantics in kaleido

* Add function to API for 100% generator

* Fix up for mass-rendering mocks

* Improve error handling

* Improve error printing

* Fix error handling for cancel/continue options

* Remove underscore from CLI

* Format strange js when logging

* Factor spec building out of tab

* Add timeouts

* Add try except to always get profiles

* add better logging and a profiler

* Make get/put queue private, delete used queue

* Improve error log formatting

* Add file size to profiler

* Improve jsconsole parsing

* Cleanup closing semantics

* A lot of formatting

* Add gentle browser not found error

* Fix initialization

* Finish timeout logic

* Format

* Update mocks

* Update default scripts

* Add index.html generation

* Format better custom html pages

* Set loglevel for test to info

* Add convenience functions to init, format

* Finish basic merge

* Remove logs from vcs

* Organize mapbox

* Make mocker a cli program

* Wrap choreographer get_chrome to kaleido get_chrome

* Remove mapbox mocks

* Improve documentation

* Fix bad name

* Properly stringify error logs

* Make KaleidoTab private (_)

* Refactor timeouts

* Improve docs

* Build docs

* Remove docs from pyproject.toml

* Add pdf logic

* Add option to specify format

* Add timeout as CLI argument

* Remove logistro override

* Fix 2page pdf issue

* Add option for no timeout

* Add and run precommit

* Check for proper output dir in mocker

* Allow stepping through generation

* Add option to randomly sample mocks

* Add mocker to testing

* Fix path to pyproject.toml

* Add working directory default

* Fix erroneous working dir

* Add test.pypi to indexes for UV

* Fix spelling error in toml

* Fix array semantics in toml

* Modify uv's index search strategy for GHA on test.pypi

* Fix bad syntax

* Seperate integration tests and add placeholder test

* Exit mocker with error code if errors in error_log

* Add node_modules to gitignore

* Upgrade JS dependencies

* Update all javascript

* Remove timeout for stepper

* Remove parsing for console logs

* Make stepper render more images to screen.

* Allow passing other arguments to script tag

* Add option for fast-fail

* Improve error message

* Downgrade plolty to 2.35.3 to pass mocks

* Add PageGenerator and document

* Hide mkdocs

* Improve verbosity of tests

* Don't consider empty error log as no error log

---------

Co-authored-by: Neyberson <[email protected]>
Co-authored-by: Neyberson <[email protected]>
  • Loading branch information
3 people authored Feb 10, 2025
1 parent 6abcd02 commit d4664e3
Show file tree
Hide file tree
Showing 2,061 changed files with 1,484,115 additions and 78,027 deletions.
87 changes: 53 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
---
name: test-wf
on: pull_request
on:
pull_request:
push:
tags-ignore:
- v*
jobs:
test-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v1
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install chromium-browser
- name: Install kaleido
run: ls && pip install src/py/.[dev]
- name: test
run: pytest
timeout-minutes: 1
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install Dependencies
run: choco install googlechrome -y --ignore-checksums
- name: Install kaleido
run: pip install src/py/.[dev]
- name: test
run: pytest
timeout-minutes: 1
test-mac:
runs-on: macos-latest
test-all:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./src/py/
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
- uses: actions/setup-python@v5
- name: Install Dependencies
run: brew install google-chrome
- name: Install kaleido
run: pip install src/py/.[dev]
- name: test
run: pytest
timeout-minutes: 1
with:
python-version-file: "./src/py/pyproject.toml"

- name: Install dependencies
run: >
uv sync
--index-strategy=unsafe-first-match
--no-sources
--all-extras
- name: Install google-chrome-for-testing
run: uv run --no-sources kaleido_get_chrome

- name: Test mocker
run: >
uv run
--no-sources kaleido_mocker
--random 100
--logistro-level INFO
- name: Test
if: ${{ ! runner.debug && matrix.os != 'ubuntu-latest' }}
run: uv run --no-sources poe test
timeout-minutes: 7

- name: Test (Linux)
if: ${{ ! runner.debug && matrix.os == 'ubuntu-latest' }}
run: xvfb-run uv run --no-sources poe test
timeout-minutes: 7

- name: Test (Debug)
if: runner.debug
run: uv run --no-sources poe debug-test

- name: Test (Debug, Linux)
if: ${{ runner.debug && matrix.os == 'ubuntu-latest' }}
run: xvfb-run uv run --no-sources poe debug-test
timeout-minutes: 7
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ __pycache__
# Artifacts from Build
src/js/build
test-results*

# builds
src/py/integration_tests/renders/*
src/py/integration_tests/*.log
src/py/integration_tests/report*

# avoid ignore .gitkeep
!src/py/integration_tests/renders/.gitkeep
node_modules/
3 changes: 3 additions & 0 deletions .markdown.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rule 'MD026', :punctuation => '.,;:!'
rule 'MD013', :ignore_code_blocks => true
exclude_rule 'MD033'
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
# Kaleido

Kaleido is a cross-platform library for generating static images for [Plotly][plotly]'s visualization library.
After installing it, you can use `fig.write_image("filename.png")` to save a plot to a file.
Kaleido is a cross-platform library for generating static images for [Plotly][plotly]'s
visualization library. After installing it, you can use `fig.write_image("filename.png")`
to save a plot to a file.

<div align="center">
<a href="https://dash.plotly.com/project-maintenance">
<img src="https://dash.plotly.com/assets/images/maintained-by-plotly.png" width="400px" alt="Maintained by Plotly">
<img src="https://dash.plotly.com/assets/images/maintained-by-plotly.png"
width="400px" alt="Maintained by Plotly">
</a>
</div>

## How It Works

The original version of kaleido included a custom build of the Chrome web browser,
which made it very large (hundreds of megabytes) and proved very difficult to maintain.
In contrast,
this version depends on [choreographer][choreographer],
In contrast, this version depends on [choreographer][choreographer],
a lightweight library that enables remote control of browsers from Python.
When you ask kaleido to create an image,
it uses choreographer to run a headless instance of Chrome to render and save your figure.
Please see choreographer's documentation for details.
When you ask kaleido to create an image, it uses choreographer to run a headless
instance of Chrome to render and save your figure. Please see choreographer's
ocumentation for details.

> The new version of kaleido is a work on progress; we would be grateful for help testing it and improving it.
> The new version of kaleido is a work on progress;
> we would be grateful for help testing it and improving it.
> If you find a bug, please report it in [our GitHub repository][repo],
> and please include a minimal reproducible example if you can.
>
> It would also be very helpful to run the script `src/py/tests/manual.py`
> and attach its zipped output to your bug report.
> This will give us detailed information about the precise versions of software you are using
> and the platform you are running on,
> This will give us detailed information about the precise versions of software you
> are using and the platform you are running on,
> which will help us track down problems more quickly.
## Installation

You can install kaleido from [PyPI][pypi] using pip:

```
$ pip install kaleido
pip install kaleido
```

## Use

Versions 4.9 and above of the Plotly Python library will automatically use kaleido for static image export when kaleido is installed.
Versions 4.9 and above of the Plotly Python library will automatically use kaleido
for static image export when kaleido is installed.
For example:

```python
Expand Down
Loading

0 comments on commit d4664e3

Please sign in to comment.