Skip to content

Commit

Permalink
improves demo_browser
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Oct 19, 2022
1 parent 3dcaf3e commit 3dbf10c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions examples/basedemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
15 changes: 9 additions & 6 deletions jpcore/demoapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion justpy/__init__.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3dbf10c

Please sign in to comment.