def test_existing_local_data_docs_urls_returns_single_url_from_customized_local_site( tmp_path_factory, ): empty_directory = str(tmp_path_factory.mktemp("yo_yo")) DataContext.create(empty_directory) ge_dir = os.path.join(empty_directory, DataContext.GE_DIR) context = DataContext(ge_dir) context._project_config["data_docs_sites"] = { "my_rad_site": { "class_name": "SiteBuilder", "store_backend": { "class_name": "TupleFilesystemStoreBackend", "base_directory": "uncommitted/data_docs/some/local/path/", }, } } # TODO Workaround project config programmatic config manipulation # statefulness issues by writing to disk and re-upping a new context context._save_project_config() context = DataContext(ge_dir) context.build_data_docs() expected_path = os.path.join( ge_dir, "uncommitted/data_docs/some/local/path/index.html") assert os.path.isfile(expected_path) obs = context.get_docs_sites_urls() assert obs == [{ "site_name": "my_rad_site", "site_url": "file://{}".format(expected_path) }]
def test_build_data_docs_skipping_index_does_not_build_index( tmp_path_factory, ): # TODO What's the latest and greatest way to use configs rather than my hackery? empty_directory = str(tmp_path_factory.mktemp("empty")) DataContext.create(empty_directory) ge_dir = os.path.join(empty_directory, DataContext.GE_DIR) context = DataContext(ge_dir) config = context.get_config() config.data_docs_sites = { "local_site": { "class_name": "SiteBuilder", "store_backend": { "class_name": "TupleFilesystemStoreBackend", "base_directory": os.path.join("uncommitted", "data_docs"), }, }, } context._project_config = config # TODO Workaround project config programmatic config manipulation # statefulness issues by writing to disk and re-upping a new context context._save_project_config() del context context = DataContext(ge_dir) data_docs_dir = os.path.join(ge_dir, "uncommitted", "data_docs") index_path = os.path.join(data_docs_dir, "index.html") assert not os.path.isfile(index_path) context.build_data_docs(build_index=False) assert os.path.isdir(os.path.join(data_docs_dir, "static")) assert not os.path.isfile(index_path)
def build_docs( context: DataContext, usage_stats_event: str, site_names: Optional[List[str]] = None, view: Optional[bool] = True, assume_yes: Optional[bool] = False, ): """Build documentation in a context""" logger.debug("Starting cli.datasource.build_docs") index_page_locator_infos: Dict[str, str] = context.build_data_docs( site_names=site_names, dry_run=True) msg: str = "\nThe following Data Docs sites will be built:\n\n" for site_name, index_page_locator_info in index_page_locator_infos.items(): msg += " - <cyan>{}:</cyan> ".format(site_name) msg += "{}\n".format(index_page_locator_info) cli_message(msg) if not assume_yes: toolkit.confirm_proceed_or_exit(data_context=context, usage_stats_event=usage_stats_event) cli_message("\nBuilding Data Docs...\n") context.build_data_docs(site_names=site_names) cli_message("Done building Data Docs") if view and site_names: for site_to_open in site_names: context.open_data_docs(site_name=site_to_open, only_if_exists=True)