from bento.common import logger, datautil logging = logger.fancy_logger(__name__) def load(): filename = "sample_covid_data.csv" data = { "df": datautil.df_loader(filename, parse_dates=["date"]), "keys": ["county", "state", "fips"], "types": { "date": "date", "cases": int, "deaths": int, }, } return data
import math from bento.common import logger, logutil # noqa logging = logger.fancy_logger(__name__, level=10) # @logutil.loginfo(level='debug') def apply_grid(page): gridsize = {"width": 12, "height": 8, "rowstart": 1} if page.get("sidebar"): gridsize["width"] = 9 gridsize["rowstart"] = 4 layout = page.get("layout") arr, bout = arrange(page["banks"], layout, gridsize) # TODO Handle more of the following outside the grid mechanics # The list of bank layout objects is the core piece (in "banks") return { "layout": arr, "banks": bout, "sidebar": page.get("sidebar"), "intro": page.get("intro"), "title": page.get("title", ""), "subtitle": page.get("subtitle", ""), } # TODO Figure out where and when we need this def _rescale_ref(ref_sizes, grid_width=12, def_width=12): new_sizes = {} for name, val in ref_sizes.items():
import black import cerberus import copy import importlib import pathlib import re from typing import Dict, List from jinja2 import Environment, PackageLoader from bento import util as butil from bento import banks, grid, schema, style from bento.common import logger, logutil, dictutil, codeutil # noqa logging = logger.fancy_logger(__name__, fmt="simple") class Bento: """Acts as the gateway to all Bento functionality. Initialization Parameters ------------------------- descriptor : dict The descriptor contains all of the user-supplied information defining the desired dashboard. See the user guide for creating a descriptor. init_only : bool Supply True in order to halt the automatic processing of the descriptor. This can be useful for debugging or modifying the standard app-creation process. Attributes
import importlib import os from bento import bento from bento.common import logger logging = logger.fancy_logger("entrypoint") logging.info(f"Loading descriptor from ./descriptor.py") desc_file = importlib.import_module(f"descriptor") # This generates the app from the descriptor app_def = bento.Bento(desc_file.descriptor) if app_def.valid: app_def.write(app_output="bento_app.py") # Gunicorn requires an object containing the server: app.server from bento_app import app # noqa bento_flask = app.server # When not deploying on the web, you can run the entrypoint without Gunicorn if __name__ == "__main__" and app_def.valid: logging.info("Running development server with hot-reload") app.run_server(port=8050, debug=True)
import flask import functools import inspect import os import traceback from bento.common import logger # logging = logger.fancy_logger(__name__) # We want to use a simple format here because we care about the wrapped function # Not the location and name of the wrapper logging = logger.fancy_logger(__name__, fmt="bare") def _parse_id(func): """Supplies the module name and functon name as a 2-tuple""" return (func.__module__.split(".")[-1], func.__name__) def loginfo(level="debug", log_route=False): def inner(func): """Wraps class methods to provide automatic log output on args/return value""" module, name = _parse_id(func) # Retrieves list of ordered arg names from the decorated function arg_names = list(inspect.signature(func).parameters.keys()) class_method = False # Removes class-related leading arg from consideration if arg_names and arg_names[0] in ("self", "cls"): class_method = True arg_names = arg_names[1:]
import re from bento.common import logutil # noqa from bento.common.logger import fancy_logger logging = fancy_logger(__name__) def pluck(input_dictionary): """Destructures a dictionary (vaguely like ES6 for JS) Results are SORTED by key alphabetically! You must sort your receiving vars """ items = sorted(input_dictionary.items()) return [item[1] for item in items] def _cid2c(cid): """Gets just the component portion of a cid string e.g. main_page/axis_controls|x_column.value => x_column """ return cid.split("|")[-1].split(".")[0] def process_inputs(input_dictionary): """Alters the keys of a dictionary by a helper function""" return {_cid2c(key): val for key, val in input_dictionary.items()} def strip_prefix(input_dictionary): """Alters the keys of a dictionary by a helper function""" return {key.split("|")[-1]: val for key, val in input_dictionary.items()}