def test_tsplit(self): import importlib import liquer.ext.lq_pandas # register pandas commands and state type import liquer.ext.basic from liquer.commands import reset_command_registry reset_command_registry() # prevent double-registration # Hack to enforce registering of the commands importlib.reload(liquer.ext.lq_pandas) importlib.reload(liquer.ext.basic) set_var("server", "http://localhost") set_var("api_path", "/q/") filename = encode_token( os.path.dirname(inspect.getfile(self.__class__)) + "/test_hxl.csv") df = evaluate(f"df_from-{filename}/tsplit_df-a").get() assert "a" in df.columns assert "b" not in df.columns assert list(df.a) == ["#indicator +num +aaa", "1", "3"] assert list(df["query"])[1:] == [ f"df_from-{filename}/teq-a-1", f"df_from-{filename}/teq-a-3", ] assert list(df["link"])[1:] == [ f"http://localhost/q/df_from-{filename}/teq-a-1", f"http://localhost/q/df_from-{filename}/teq-a-3", ]
def test_vars_context(self): reset_command_registry() set_var("test_var", "INITIAL") @first_command def varcommand(context=None): is_initial = context.vars.test_var == "INITIAL" context.vars.test_var = "MODIFIED" return is_initial @command def varcommand_state(state,context=None): is_initial = state.vars.get("test_var") == "INITIAL" state.vars["test_var"] = "MODIFIED" return is_initial @command def check1(state, context=None): print(f"Check1: ", state.vars["test_var"]) return state.vars["test_var"] == "MODIFIED" @command def check2(state, context=None): print(f"Check2: ", context.vars.test_var) return context.vars.test_var == "MODIFIED" assert get_context().evaluate("varcommand").get() == True assert get_context().evaluate("varcommand_state").get() == True assert get_context().evaluate("check1").get() == False assert get_context().evaluate("check2").get() == False assert get_context().evaluate("varcommand/check1").get() == True assert get_context().evaluate("varcommand/check2").get() == True assert get_context().evaluate("varcommand_state/check1").get() == True assert get_context().evaluate("varcommand_state/check2").get() == True
def test_vars(self): import liquer.ext.basic assert evaluate("state_variable-abc").get() is None assert evaluate("let-abc-1/state_variable-abc").get() == "1" assert evaluate("state_variable-abc").get() is None set_var("abc", "123") assert evaluate("state_variable-abc").get() == "123" assert evaluate("let-abc-1/state_variable-abc").get() == "1"
def add_menuitem(title, subtitle, link): "Convinience function for creating menus" menu = get_vars().get("menu", []) try: item_number = [i for i, item in enumerate(menu) if item["title"] == title][0] except: menu.append(dict(title=title, items=[])) item_number = len(menu) - 1 menu[item_number]["items"].append(dict(title=subtitle, link=link)) set_var("menu", menu)
def load_jupyter_server_extension(nb_server_app): """ Called when the extension is loaded. Args: nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance. """ import liquer.ext.basic import liquer.ext.meta import liquer.ext.lq_pandas # import liquer.ext.lq_hxl import liquer.ext.lq_python import liquer.ext.lq_pygments from liquer.state import set_var, get_vars import liquer.commands liquer.commands.enable_remote_registration() web_app = nb_server_app.web_app host_pattern = ".*$" url_prefix = "/liquer" route_pattern = url_path_join(web_app.settings["base_url"], url_prefix) set_var("api_path", "/q/") set_var("server", route_pattern) web_app.add_handlers( host_pattern, [ (route_pattern, LiquerIndexHandler), (url_path_join(route_pattern, "/index.html"), LiquerIndexHandler), (url_path_join(route_pattern, "/liquer.js"), LiquerJsHandler), (url_path_join(route_pattern, "/static/index.html"), LiquerIndexHandler), (url_path_join(route_pattern, "/static/liquer.js"), LiquerJsHandler), (url_path_join(route_pattern, "/api/commands.json"), CommandsHandler), (url_path_join(route_pattern, "/api/debug-json/(.*)"), DebugQueryHandler), (url_path_join(route_pattern, "/api/build"), BuildHandler), ( url_path_join(route_pattern, "/api/register_command/(.*)"), RegisterCommandHandler, ), (url_path_join(route_pattern, "/q/(.*)"), QueryHandler), ], )
def test_link(self): import liquer.ext.basic assert evaluate("let-hello-world/state_variable-hello/link").get( ) == "let-hello-world/state_variable-hello" assert evaluate("let-hello-world/state_variable-hello/link-dataurl" ).get() == "data:text/plain;base64,d29ybGQ=" assert evaluate("let-hello-world/state_variable-hello/link-path").get( ) == "/q/let-hello-world/state_variable-hello" assert evaluate("let-hello-world/state_variable-hello/link-url").get( ) == "http://localhost/q/let-hello-world/state_variable-hello" set_var("server", "http://localhost:1234") set_var("api_path", "/liquer/q/") assert evaluate("let-hello-world/state_variable-hello/link-path").get( ) == "/liquer/q/let-hello-world/state_variable-hello" assert evaluate("let-hello-world/state_variable-hello/link-url").get( ) == "http://localhost:1234/liquer/q/let-hello-world/state_variable-hello" set_var("server", "http://localhost") set_var("api_path", "/q/")
import liquer.ext.basic import liquer.ext.meta import liquer.ext.lq_pandas import liquer.ext.lq_hxl import liquer.ext.lq_python import liquer.ext.lq_pygments app = Flask(__name__) logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) werkzeug_logger = logging.getLogger('werkzeug') werkzeug_logger.setLevel(logging.INFO) url_prefix = '/liquer' app.register_blueprint(bp.app, url_prefix=url_prefix) set_var("api_path", url_prefix + "/q/") set_var("server", "http://localhost:5000") #set_var("menu",[ # dict(title="Test", items=[ # dict(title="Hello, world - html", link="hello_html/hello.html"), # dict(title="Hello, world - text", link="hello_text"), # dict(title="Logo", link="logo/logo.png"), # ]), # dict(title="Help", items=[ # dict(title="Commands", link="ns-meta/flat_commands_nodoc/to_df"), # dict(title="Homepage", link="https://orest-d.github.io/liquer/"), # ]) #]) def add_menuitem(title, subtitle, link):
# Make it run from the examples directory import sys sys.path.append("..") from liquer import * from liquer.state import set_var import liquer.ext.basic @command def hello(state, who=None): if who is None: who = state.vars.get("greet","???") return f"Hello, {who}!" set_var("greet","world") print (evaluate("hello").get()) # Hello, world! : uses state variable defined above print (evaluate("state_variable-greet").get()) # world : shows the content of the state variable print (evaluate("hello-everybody").get()) # Hello, everybody! : uses the argument print (evaluate("let-greet-variable/hello").get()) # Hello, variable! : defines the variable in the query print (evaluate("hello").get()) # Hello, world! : let is local to a query
import liquer.ext.lq_hxl import liquer.ext.lq_python import liquer.ext.lq_pygments from time import sleep from liquer.pool import set_central_cache app = Flask(__name__) logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) werkzeug_logger = logging.getLogger("werkzeug") werkzeug_logger.setLevel(logging.INFO) url_prefix = "/liquer" app.register_blueprint(bp.app, url_prefix=url_prefix) set_var("api_path", url_prefix + "/q/") set_var("server", "http://*****:*****@app.route("/", methods=["GET", "POST"]) @app.route("/index.html", methods=["GET", "POST"]) def index(): """Link to a LiQuer main service page""" return redirect("/liquer/static/index.html") set_var( "menu", [ dict( title="Progress Demo",