From 3dbf10ce16847ed7b706984724a48fd05f49c2d1 Mon Sep 17 00:00:00 2001 From: Wolfgang Fahl Date: Wed, 19 Oct 2022 17:33:07 +0200 Subject: [PATCH] improves demo_browser --- examples/basedemo.py | 13 +++++++------ jpcore/demoapp.py | 15 +++++++++------ justpy/__init__.py | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/basedemo.py b/examples/basedemo.py index 50b75d86..d0171326 100644 --- a/examples/basedemo.py +++ b/examples/basedemo.py @@ -7,24 +7,25 @@ import socket import typing - class Demo(object): """ Base class for justpy demos to allow selecting host and port from commandline """ - testmode = False - def __init__(self, name: str, wp: typing.Callable, **kwargs): + def __init__(self, name: str, wp_func: typing.Callable, **kwargs): """ Constructor Args: name(str): the name of the demo - host(int): the port to runt he demo at (defaut:8000) - wp(callable): the webpage callback + host(int): the port to run the demo at (default:8000) + wp_func(callable): the webpage callback **kwargs: further keyword arguments """ + self.name=name + self.wp_func=wp_func + self.kwargs=kwargs # make sure Demo code may be tested without automatically starting if Demo.testmode: return @@ -34,4 +35,4 @@ def __init__(self, name: str, wp: typing.Callable, **kwargs): args = parser.parse_args() import justpy as jp - jp.justpy(wp, host=args.host, port=args.port, **kwargs) + jp.justpy(wp_func, host=args.host, port=args.port, **kwargs) diff --git a/jpcore/demoapp.py b/jpcore/demoapp.py index 652fe34f..d10192f5 100644 --- a/jpcore/demoapp.py +++ b/jpcore/demoapp.py @@ -52,24 +52,27 @@ def check_demo(self): """ self.is_demo = False if "Demo(" or "Demo (" in self.source: - if self.debug: - print(f"found Demo( in {self.pymodule_file}") + #if self.debug: + # print(f"found Demo( in {self.pymodule_file}") func_match = re.search( """Demo[ ]?[(]["'](.*)["'],\s*(.*?)(,.*)*[)]""", self.source ) if func_match: + #len_groups = len(func_match.groups()) self.description = func_match.group(1) self.wpfunc_name = func_match.group(2) + self.wpfunc_params=func_match.group(3) # jenkins could have /var/lib/jenkins/jobs/justpy/workspace/examples/charts_tutorial/pandas/women_majors2.py is not a demo module_match = re.search( - "justpy/(workspace/)?(examples/.*)[.]py", self.pymodule_file + "(examples/.*)[.]py", self.pymodule_file ) - if self.debug: - print(f"found {self.wpfunc_name}:{self.description} in {self.pymodule_file}") if module_match: - self.pymodule = module_match.group(2) + self.pymodule = module_match.group(1) self.pymodule = self.pymodule.replace("/", ".") self.is_demo = not "lambda" in self.wpfunc_name + if self.debug and self.is_demo: + print(f"found {self.wpfunc_name}:{self.description} in module {self.pymodule} {self.pymodule_file}") + print(f"with params {self.wpfunc_params}") return def video_link(self,target_url:str=None,alt:str=None,title:str=None,video_size=512): diff --git a/justpy/__init__.py b/justpy/__init__.py index 666eed42..1b6e35e1 100644 --- a/justpy/__init__.py +++ b/justpy/__init__.py @@ -1,4 +1,4 @@ """JustPy is an object-oriented, component based, high-level Python Web Framework that requires no front-end programming""" from .justpy import * -__version__ = "0.9.10" +__version__ = "0.9.11"