-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Package matplotlib and ui JS with wheel (#343)
Fixes #194, fixes #316 Packages matplotlib and ui JS with wheel using new util packages. I also took the opportunity to refactor those two a bit to match the plotly express package by moving registration out of the `__init__.py` files. Also refactored plotly express. I've verified the installed wheels work properly with basic examples. --------- Co-authored-by: Mike Bender <[email protected]>
- Loading branch information
1 parent
bca3880
commit 7724e55
Showing
21 changed files
with
187 additions
and
124 deletions.
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools>=43.0.0", "wheel"] | ||
requires = ["setuptools>=43.0.0", "wheel", "deephaven-plugin-packaging"] | ||
build-backend = "setuptools.build_meta" |
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,16 @@ | ||
from setuptools import setup | ||
import os | ||
|
||
from deephaven.plugin.packaging import package_js | ||
|
||
js_dir = "src/js/" | ||
dest_dir = os.path.join("src/deephaven/plugin/matplotlib/_js") | ||
|
||
package_js(js_dir, dest_dir) | ||
|
||
setup( | ||
package_data={ | ||
"deephaven.plugin.matplotlib._js": ["**"], | ||
"deephaven.plugin.matplotlib": ["deephaven.mplstyle"], | ||
} | ||
) |
23 changes: 0 additions & 23 deletions
23
plugins/matplotlib/src/deephaven/plugin/matplotlib/__init__.py
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
32 changes: 32 additions & 0 deletions
32
plugins/matplotlib/src/deephaven/plugin/matplotlib/_js_plugin.py
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,32 @@ | ||
import pathlib | ||
|
||
from deephaven.plugin.js import JsPlugin | ||
|
||
|
||
class MatplotlibJsPlugin(JsPlugin): | ||
def __init__( | ||
self, | ||
name: str, | ||
version: str, | ||
main: str, | ||
path: pathlib.Path, | ||
) -> None: | ||
self._name = name | ||
self._version = version | ||
self._main = main | ||
self._path = path | ||
|
||
@property | ||
def name(self) -> str: | ||
return self._name | ||
|
||
@property | ||
def version(self) -> str: | ||
return self._version | ||
|
||
@property | ||
def main(self) -> str: | ||
return self._main | ||
|
||
def path(self) -> pathlib.Path: | ||
return self._path |
39 changes: 39 additions & 0 deletions
39
plugins/matplotlib/src/deephaven/plugin/matplotlib/_register.py
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,39 @@ | ||
from importlib import resources | ||
import matplotlib.pyplot as plt | ||
from deephaven.plugin import Registration, Callback | ||
from deephaven.plugin.utilities import create_js_plugin, DheSafeCallbackWrapper | ||
from ._js_plugin import MatplotlibJsPlugin | ||
|
||
PACKAGE_NAMESPACE = "deephaven.plugin.matplotlib" | ||
JS_NAME = "_js" | ||
PLUGIN_CLASS = MatplotlibJsPlugin | ||
|
||
|
||
def _init_theme(): | ||
# Set the Deephaven style globally. | ||
# We use the savefig function to export the Figure, and that uses the Figure's properties for colours rather than temporary styling. | ||
# The Figure's properties are set on creation time of the Figure, rather than when the Figure is exported | ||
# We do not have hooks into when a user creates a new Figure, so we set the theme globally ahead of time | ||
# https://github.com/matplotlib/matplotlib/issues/6592/ | ||
with resources.path(__package__, "deephaven.mplstyle") as p: | ||
plt.style.use(["dark_background", p]) | ||
|
||
|
||
class MatplotlibRegistration(Registration): | ||
@classmethod | ||
def register_into(cls, callback: Callback) -> None: | ||
_init_theme() | ||
plt.switch_backend("AGG") | ||
from . import figure_type | ||
|
||
callback = DheSafeCallbackWrapper(callback) | ||
|
||
callback.register(figure_type.FigureType) | ||
|
||
js_plugin = create_js_plugin( | ||
PACKAGE_NAMESPACE, | ||
JS_NAME, | ||
PLUGIN_CLASS, | ||
) | ||
|
||
callback.register(js_plugin) |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools>=43.0.0", "wheel"] | ||
requires = ["setuptools>=43.0.0", "wheel", "deephaven-plugin-packaging"] | ||
build-backend = "setuptools.build_meta" |
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 |
---|---|---|
@@ -1,38 +1,10 @@ | ||
import shutil | ||
from setuptools import setup | ||
import os | ||
import subprocess | ||
|
||
# Uses npm pack to create a tarball of the package and unpacks it into a build directory | ||
# Then uses that to add to the wheel | ||
from deephaven.plugin.packaging import package_js | ||
|
||
js_dir = "src/js/" | ||
dist_dir = os.path.join(js_dir, "dist") | ||
build_dir = os.path.join(js_dir, "build") | ||
dest_dir = os.path.join("src/deephaven/plot/express/_js") | ||
package_dir = os.path.join(build_dir, "package") | ||
|
||
# copy the bundle to the plotly-express directory | ||
# the path may not exist (e.g. when running tests) | ||
# so it is not strictly necessary to copy the bundle | ||
if os.path.exists(dist_dir): | ||
# ignore errors as the directory may not exist | ||
shutil.rmtree(build_dir, ignore_errors=True) | ||
shutil.rmtree(dest_dir, ignore_errors=True) | ||
|
||
os.makedirs(build_dir, exist_ok=True) | ||
|
||
# pack and unpack into the js plotly-express directory | ||
subprocess.run( | ||
["npm", "pack", "--pack-destination", "build"], cwd=js_dir, check=True | ||
) | ||
# it is assumed that there is only one tarball in the directory | ||
files = os.listdir(build_dir) | ||
for file in files: | ||
subprocess.run(["tar", "-xzf", file], cwd=build_dir, check=True) | ||
os.remove(os.path.join(build_dir, file)) | ||
|
||
# move the package directory to the expected package location | ||
shutil.move(package_dir, dest_dir) | ||
package_js(js_dir, dest_dir) | ||
|
||
setup(package_data={"deephaven.plot.express._js": ["**"]}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools>=43.0.0", "wheel"] | ||
requires = ["setuptools>=43.0.0", "wheel", "deephaven-plugin-packaging"] | ||
build-backend = "setuptools.build_meta" |
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,10 @@ | ||
from setuptools import setup | ||
import os | ||
from deephaven.plugin.packaging import package_js | ||
|
||
js_dir = "src/js/" | ||
dest_dir = os.path.join("src/deephaven/ui/_js") | ||
|
||
package_js(js_dir, dest_dir) | ||
|
||
setup(package_data={"deephaven.ui._js": ["**"]}) |
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.