plotly / Kaleido

Fast static image export for web-based visualization libraries with zero dependencies
MIT License
379 stars 39 forks source link

Add support for custom chromium commandline arguments #53

Closed jonmmease closed 4 years ago

jonmmease commented 4 years ago

Closes https://github.com/plotly/Kaleido/issues/45

This PR adds support for fully customizing the chromium flags used by the kaleido process. It also adds --disable-dev-shm-usage to the list of default arguments. This is helpful in certain docker configurations with limited /dev/shm size and it is also the default for puppeteer.

The default arguments are returned by the default_chromium_args class method. e.g.

from kaleido.scopes.plotly import PlotlyScope
PlotlyScope.default_chromium_args()
('--disable-gpu',
 '--allow-file-access-from-files',
 '--disable-breakpad',
 '--disable-dev-shm-usage',
 '--no-sandbox')

A custom tuple/list of arguments can be provided using the chromium_args argument in the scope constructor, and a tuple of the active chromium arguments can be accessed using the chromium_args property

from kaleido.scopes.plotly import PlotlyScope
scope = PlotlyScope(chromium_args=["--disable-gpu", "--single-process"])
scope.chromium_args
('--disable-gpu', '--single-process')

For an already constructed scope (as in the case of the scope that plotly.py constructs at plotly.io.kaleido.scope), the arguments can be set using the property setter. This will automatically shut down any running kaleido process so that the arguments are in effect the next time a transform is applied.

For example, to add the --single-process argument to the list of defaults for use by plotly.py:

import plotly.io as pio
pio.kaleido.scope.chromium_args = pio.kaleido.scope.chromium_args + ("--single-process",)
pio.kaleido.scope.chromium_args
('--disable-gpu',
 '--allow-file-access-from-files',
 '--disable-breakpad',
 '--disable-dev-shm-usage',
 '--no-sandbox',
 '--single-process')

cc @aschmied

aschmied commented 4 years ago

🎉

peterli110 commented 4 years ago

how to use this branch with pipenv? I've tried with kaleido = {git = "https://github.com/plotly/Kaleido.git", editable = true, ref = "chromium_args", subdirectory = "repos/kaleido/py"} but it throws an error on setup.py:line 26 that _version.py is not exist

jonmmease commented 4 years ago

There isn't a convenient way to install kaleido from a branch due to the need to compile Chromium. I'll publish a new alpha version with these changes to PyPI later today.

jonmmease commented 4 years ago

These changes are now released in 0.1.0a3 on PyPI (https://pypi.org/project/kaleido/0.1.0a3/). The final release probably won't happen until early November, so please let us know if you run any (especially new) issues.