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

feat: Add plotly-express JsPlugin implementation and registration #150

Merged
merged 8 commits into from
Dec 20, 2023

Conversation

devinrsmith
Copy link
Member

@devinrsmith devinrsmith commented Dec 8, 2023

This plumbs automatic JsPlugin registration - the server side depends on deephaven/deephaven-core#4925.

@devinrsmith devinrsmith self-assigned this Dec 8, 2023
Comment on lines 47 to 48
with root_provider() as root, (root / "package.json").open("rb") as f:
package_json = json.load(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something here? You're trying to use root_provider() as a context manager, but it returns a Generator so this is just going to be an error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this code "works" - I don't think it's just an artifact of python duck typing; I think the code is technically correct, but the typing may be more general than we need it to be. I think when I was originally writing this code, I saw a suggestion somewhere that ContextManager should use typing.Generator typing. I'll look to see if there is more explicit typing suggestions for ContextManager...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least the "technically correct", which may have lead me or others to using Generator typeing, https://docs.python.org/3.11/library/contextlib.html#contextlib.contextmanager:

The function being decorated must return a generator-iterator when called. This iterator must yield exactly one value, which will be bound to the targets in the with statement’s as clause, if any.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why the official suggestion isn't typing.ContextManager - maybe b/c it was only introduced in 3.6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea strange, seems like that's what is returned from .as_file and such: https://github.com/python/typeshed/blob/cff2b3db0ca291e153a8bd407f48ac220a381dd8/stdlib/importlib/resources/__init__.pyi#L37
It is returning an AbstractContextManager vs. ContextManager, but seems like those two match anyway (AbstractContextManager, ContextManager)

package_json = json.load(f)
return ExpressJsPlugin(
package_json["name"],
package_json["version"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we discuss getting the version from python instead of from the package.json? So that package.json has a dummy version, and we always pull from the python version so they always match

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is for @jnumainville to discuss and move forward if desired. Also, questions around editable installs and potentially re-pointing the Path for development use-cases.

@@ -103,20 +103,21 @@ def create_client_connection(
return figure_connection


class ChartRegistration(Registration):
class ExpressRegistration(Registration):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bigger refactor than originally planned, but I'm not sure this belongs here (nor does the new import create_js_plugin).

The expectation (and documentation) is that users start with:

import deephaven.plot.express as dx

but with code as it stands, dx. will now include ExpressRegistration and create_js_plugin.

As long as the registration is being renamed (an internal type, won't affect any downstream users), I'd suggest it belongs in its own file to avoid this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough - should be "internal" code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored so JS / registration are internal. It might be reasonable to refacter DeephavenFigureType in the same way.

Copy link
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove a couple of extra new lines in doc strings, but whatever.

Also wanted to note for posterity we're switching away from __version__ defined in __init__.py as that was a rejected PEP standard: https://peps.python.org/pep-0396/
Now you should use importlib.metadata.version() to get the version from a module, and the core metadata specs are here: https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata

class ExpressRegistration(Registration):
"""
Register the DeephavenFigureType and a JsPlugin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Args:
callback: Registration.Callback:
A function to call after registration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@devinrsmith devinrsmith merged commit d6d0416 into deephaven:main Dec 20, 2023
11 checks passed
@devinrsmith devinrsmith deleted the plotly-express-js-plugin branch December 20, 2023 21:11
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.

4 participants