Example #1
0
def _convert_config_option_to_click_option(config_option):
    """Composes given config option options as options for click lib."""
    option = "--{}".format(config_option.key)
    param = config_option.key.replace(".", "_")
    description = config_option.description
    if config_option.deprecated:
        description += "\n {} - {}".format(config_option.deprecation_text,
                                           config_option.deprecation_date)
    envvar = "STREAMLIT_{}".format(to_snake_case(param).upper())

    return {
        "param": param,
        "description": description,
        "type": config_option.type,
        "option": option,
        "envvar": envvar,
    }
Example #2
0
def _populate_theme_msg(msg: CustomThemeConfig) -> None:
    enum_encoded_options = {"base", "font"}
    theme_opts = config.get_options_for_section("theme")

    if not any(theme_opts.values()):
        return

    for option_name, option_val in theme_opts.items():
        if option_name not in enum_encoded_options and option_val is not None:
            setattr(msg, to_snake_case(option_name), option_val)

    # NOTE: If unset, base and font will default to the protobuf enum zero
    # values, which are BaseTheme.LIGHT and FontFamily.SANS_SERIF,
    # respectively. This is why we both don't handle the cases explicitly and
    # also only log a warning when receiving invalid base/font options.
    base_map = {
        "light": msg.BaseTheme.LIGHT,
        "dark": msg.BaseTheme.DARK,
    }
    base = theme_opts["base"]
    if base is not None:
        if base not in base_map:
            LOGGER.warning(
                f'"{base}" is an invalid value for theme.base.'
                f" Allowed values include {list(base_map.keys())}."
                ' Setting theme.base to "light".'
            )
        else:
            msg.base = base_map[base]

    font_map = {
        "sans serif": msg.FontFamily.SANS_SERIF,
        "serif": msg.FontFamily.SERIF,
        "monospace": msg.FontFamily.MONOSPACE,
    }
    font = theme_opts["font"]
    if font is not None:
        if font not in font_map:
            LOGGER.warning(
                f'"{font}" is an invalid value for theme.font.'
                f" Allowed values include {list(font_map.keys())}."
                ' Setting theme.font to "sans serif".'
            )
        else:
            msg.font = font_map[font]
Example #3
0
def register_type_builder(chart_type):
    """Add a builder function to this module to build a specific chart type.

    These sugary builders also set up some nice defaults from the
    DEFAULT_COMPONENTS dict, that can be overriden after the instance is built.

    Parameters
    ----------
    chart_type : str
        A string with the upper-camel-case name of the chart type to add.

    """
    chart_type_snake = case_converters.to_snake_case(chart_type)

    def type_builder(data, **kwargs):
        kwargs.pop("type", None)  # Ignore 'type' key from kwargs, if exists.
        return Chart(data, type=chart_type_snake, **kwargs)

    setattr(current_module, chart_type, type_builder)
Example #4
0
def _populate_theme_msg(msg: CustomThemeConfig) -> None:
    theme_opts = config.get_options_for_section("theme")

    if (theme.check_theme_completeness(theme_opts) !=
            theme.ThemeCompleteness.FULLY_DEFINED):
        return

    for option_name, option_val in theme_opts.items():
        # We don't set the "font" option here as it needs to be converted
        # from string -> enum.
        if option_name != "font" and option_val is not None:
            setattr(msg, to_snake_case(option_name), option_val)

    font_map = {
        "sans serif": msg.FontFamily.SANS_SERIF,
        "serif": msg.FontFamily.SERIF,
        "monospace": msg.FontFamily.MONOSPACE,
    }
    msg.font = font_map.get(
        config.get_option("theme.font"),
        msg.FontFamily.SANS_SERIF,
    )
Example #5
0
    c = Chart(myData, 'line_chart').foo_bar(stuff='yes!').baz()

    """
    def append_component_method(self, **props):
        if implemented:
            self.append_component(component_name, props)
        else:
            raise NotImplementedError(component_name + " not implemented.")
        return self  # For builder-style chaining.

    setattr(Chart, component_name, append_component_method)


# Add methods to Chart class, for each component in CHART_COMPONENTS.
for component_name, implemented in chart_config.CHART_COMPONENTS.items():
    register_component(case_converters.to_snake_case(component_name),
                       implemented)


def register_type_builder(chart_type):
    """Add a builder function to this module to build a specific chart type.

    These sugary builders also set up some nice defaults from the
    DEFAULT_COMPONENTS dict, that can be overriden after the instance is built.

    Parameters
    ----------
    chart_type : str
        A string with the upper-camel-case name of the chart type to add.

    """