Skip to content
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

Extract chart studio functionality, optimized imports #1476

Merged
merged 89 commits into from
Apr 12, 2019
Merged

Conversation

jonmmease
Copy link
Contributor

@jonmmease jonmmease commented Mar 23, 2019

Overview

This PR is an important step towards the version 4 goal of removing all of the chart studio (i.e. cloud-service related) functionality from plotly.py, and putting it in a separate optional package.

chart studio extraction

For the time being, I've done this by creating a new top-level chart_studio package next to the top-level plotly package. I've moved all of the cloud-related functionality to the chart_studio package, following the same structure as in the current plotly package. For example, the plotly.plotly module was moved to chart_studio.plotly.

This PR takes advantage of the _future_plotly_ system introduced in #1474 to make this refactor backward compatible.

  • By default all of the old entry points are still usable and they are aliased to the chart_studio package.
  • If the extract_chart_studio future flag is set, then deprecation warnings are raised whenever the chart_studio modules/functions are used from their legacy locations under the plotly package.
  • If the remove_deprecations future flag is set then the chart studio functions are fully removed from the plotly package and are accessible only under chart_studio. When remove_deprecations is set, plotly has no dependency on the chart_studio package.

Usage

To remove the chart_studio functionality from the main plotly module, use the

from _plotly_future_ import remove_deprecations

This will further speed up imports, and will allow for testing code to make sure it will be compatible with the package structure of plotly.py version 4.

Import optimization

This PR also makes a relatively minor change to the code generation logic for graph_objs and validator that yields an import time reduction of ~10-20% . Rather that creating a single file for each datatype and validator class, all of the classes in a graph_obj or validator module are specified directly in the __init__.py file. This reduces the number of files significantly, which seems to yield a modest but consistent speedup while being 100% backward compatible.

What's next

For version 4, the chart_studio module will be published in a separate PyPI/conda package and all of the aliases to chart_studio will be removed from the plotly PyPI package.

Avoids writing out tmp file by create single use web server to serve
the html content to the browser.
'notebook_connected+plotly_mimetype'

This renderer combination  will work automatically in the
classic notebook, jupyterlab, nteract, vscode, and nbconvert HTML
export. We use 'notebook_connected' rather than 'notebook' to avoid
bloating notebook size.  This comes at the cost of requiring internet
connectivity, but that is a preferable trade-off to adding ~3MB to each
saved notebook.
Updated tests only slightly to reflect the change in how resizing is
handled now. Before there was a custom callback resize script, now
we rely on the plotly.js 'responsive' config option
Use include_plotlyjs='directory' for iframe renderer.
Now there is a post_script argument to the HTML functions that allows
a user to specify some custom JavaScript to run after plot creation.
This can be used by plot/iplot to implement the previous save image
behavior without needing to add explicit save image options to the HTML
functions.
that is false by default.

Now the behavior of figure display, init_notebook_mode, iplot, and plot
are all backward compatible by default.
it easy to preview v4 behavior and revert to v3 behavior.
default renderer settings and default template.

Get all of v4 settings with:

```python
from _plotly_future_ import v4
```
Docstrings for to_html and write_html
@jonmmease jonmmease changed the title WIP: Extract chart studio functionality, optimized non-recursive imports WIP: Extract chart studio functionality, optimized imports Apr 9, 2019
Conflicts:
	_plotly_future_/__init__.py
	_plotly_future_/v4.py
	plotly/__init__.py
	plotly/files.py
	plotly/io/_base_renderers.py
	plotly/io/_html.py
	plotly/io/_renderers.py
	plotly/offline/offline.py
	plotly/tests/test_core/test_offline/test_offline.py
	plotly/tests/test_io/test_renderers.py
	plotly/tests/test_optional/test_offline/test_offline.py
	plotly/tests/test_orca/test_image_renderers.py
	plotly/utils.py
	setup.py
@jonmmease jonmmease changed the title WIP: Extract chart studio functionality, optimized imports Extract chart studio functionality, optimized imports Apr 12, 2019
@jonmmease jonmmease merged commit 3678aa9 into master Apr 12, 2019
@jonmmease jonmmease added this to the v3.8.0 milestone Apr 12, 2019
@kmactavish
Copy link

@jonmmease FYI I believe this refactor broke holoviews integration (It imports plotly.offline.offline.utils, which has moved to _plotly_utils.utils).

@jonmmease
Copy link
Contributor Author

Thanks for the heads up @kmactavish. I created an issue at holoviz/holoviews#3643.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants