From 363dd5336034dbd9d5c5d03ce13ea242aa5f99c0 Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Tue, 14 Feb 2023 08:41:28 -0700 Subject: [PATCH] fix(www): Allow www tool to support either vue2 or vue3 fix #204 --- docs/api/source/tools.www.rst | 5 ++++- docs/content/docs/cheatsheet.md | 1 + setup.cfg | 2 +- trame/tools/www.py | 36 ++++++++++++++++++++++++++++----- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/api/source/tools.www.rst b/docs/api/source/tools.www.rst index c9c66c9a..9ff7c963 100644 --- a/docs/api/source/tools.www.rst +++ b/docs/api/source/tools.www.rst @@ -23,4 +23,7 @@ Or you can also do the following as only the pieces needed will be downloaded by cd www-all python -m trame.tools.www -Here is a list of known modules: deckgl, markdown, matplotlib, paraview, plotly, router, trame, vega, vtk, vuetify, www (main client) \ No newline at end of file +Here is a list of known modules: deckgl, markdown, matplotlib, paraview, plotly, router, trame, vega, vtk, vuetify, www (main client) + +With the add-on support of vue3 backend, you can now provide which client you want to enable by providing `--client-type vue2` or `--client-type vue3`. +Keep in mind that vue2 UI template are not 100% compatible with their vue3 counter part... \ No newline at end of file diff --git a/docs/content/docs/cheatsheet.md b/docs/content/docs/cheatsheet.md index 8c1a00d6..457ec7e6 100644 --- a/docs/content/docs/cheatsheet.md +++ b/docs/content/docs/cheatsheet.md @@ -8,6 +8,7 @@ from trame.ui.vuetify import SinglePageLayout # UI layout from trame.widgets import vuetify, vtk # UI widgets server = get_server() # Create/retrieve default server +server.client_type = "vue2" # Choose between vue2 and vue3 state, ctrl = server.state, server.controller # Extract server state and controller # Reset resolution variable to 6 diff --git a/setup.cfg b/setup.cfg index 6e58660d..fa2889d7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,13 +29,13 @@ install_requires = trame-server>=2.9.0 trame-client>=2.1.0 trame-router==2.0.1 - trame-vuetify==2.1.0 trame-components==2.1.0 trame-plotly==2.1.0 trame-markdown==2.0.2 trame-matplotlib==2.0.1 trame-deckgl==2.0.1 trame-vega==2.0.2 + trame-vuetify<3.0.0 trame-vtk<3.0.0 trame-simput<3.0.0 trame-rca<3.0.0 diff --git a/trame/tools/www.py b/trame/tools/www.py index 9bc2a2ba..07f9e380 100644 --- a/trame/tools/www.py +++ b/trame/tools/www.py @@ -12,6 +12,7 @@ class StaticContentGenerator: def __init__(self): self.www = None self.serve = {} + self.client_type = "vue2" def enable_all(self): import pkgutil @@ -19,6 +20,28 @@ def enable_all(self): root = importlib.import_module("trame.modules") self.enable_modules(*[m.name for m in pkgutil.iter_modules(root.__path__)]) + def add_protocol_to_configure(self, *args, **kwargs): + """Fake server""" + pass + + def enable_module(self, module, **kwargs): + load_remaining = False + if "setup" in module.__dict__: + try: + module.setup(self) + load_remaining = True + except TypeError: + pass # Skip incompatible modules + else: + load_remaining = True + + if load_remaining: + if "serve" in module.__dict__: + self.serve.update(module.serve) + + if "www" in module.__dict__: + self.www = module.www + def enable_modules(self, *names): for module_name in names: module = None @@ -35,11 +58,7 @@ def enable_modules(self, *names): print(f"Skipping module: {module_name}") continue - if "serve" in module.__dict__: - self.serve.update(module.serve) - - if "www" in module.__dict__: - self.www = module.www + self.enable_module(module) def write(self, output_directory=None): if output_directory is None: @@ -63,8 +82,15 @@ def main(): help="Directory to fill with trame client code", ) + parser.add_argument( + "--client-type", + default="vue2", + help="Type of client to use [vue2, vue3]", + ) + args, module_names = parser.parse_known_args() generator = StaticContentGenerator() + generator.client_type = args.client_type if len(module_names): generator.enable_modules(*module_names) else: