Пример #1
0
    def test_get_project_streamlit_file_path(self):
        expected = os.path.join(
            os.getcwd(), file_util.CONFIG_FOLDER_NAME, "some/random/file"
        )

        self.assertEqual(
            expected, file_util.get_project_streamlit_file_path("some/random/file")
        )

        self.assertEqual(
            expected,
            file_util.get_project_streamlit_file_path("some", "random", "file"),
        )
Пример #2
0
def parse_config_file(force=False):
    """Parse the config file and update config parameters."""
    global _config_file_has_been_parsed

    if _config_file_has_been_parsed and force == False:
        return

    # Read ~/.streamlit/config.toml, and then overlay
    # $CWD/.streamlit/config.toml if it exists.
    config_filenames = [
        file_util.get_streamlit_file_path("config.toml"),
        file_util.get_project_streamlit_file_path("config.toml"),
    ]

    for filename in config_filenames:
        # Parse the config file.
        if not os.path.exists(filename):
            continue

        with open(filename, "r") as input:
            file_contents = input.read()

        _update_config_with_toml(file_contents, filename)

    _config_file_has_been_parsed = True
    _on_config_parsed.send()
Пример #3
0
    try:
        return float(v)
    except Exception:
        pass

    return v


# Allow outside modules to wait for the config file to be parsed before doing
# something.
_on_config_parsed = Signal(doc="Emitted when the config file is parsed.")

CONFIG_FILENAMES = [
    file_util.get_streamlit_file_path("config.toml"),
    file_util.get_project_streamlit_file_path("config.toml"),
]


def get_config_options(
    force_reparse=False, options_from_flags: Optional[Dict[str, Any]] = None
) -> Dict[str, ConfigOption]:
    """Create and return a dict mapping config option names to their values,
    returning a cached dict if possible.

    Config option values are sourced from the following locations. Values
    set in locations further down the list overwrite those set earlier.
      1. default values defined in this file
      2. the global `~/.streamlit/config.toml` file
      3. per-project `$CWD/.streamlit/config.toml` files
      4. environment variables such as `STREAMLIT_SERVER_PORT`