RepoPeft-data / oracle_context_cache /MartenBE__mkslides.json
nanigock's picture
Upload folder using huggingface_hub
cd15502 verified
{"repo": "MartenBE/mkslides", "n_pairs": 67, "version": "v2_function_scoped", "contexts": {"tests/utils.py::41": {"resolved_imports": [], "used_names": ["Path", "subprocess"], "enclosing_function": "__run_build_generic", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/utils.py::76": {"resolved_imports": [], "used_names": ["Path"], "enclosing_function": "assert_html_contains", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/baseline/test_baseline.py::31": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/baseline/test_baseline.py::35": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/baseline/test_baseline.py::32": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/baseline/test_baseline.py::37": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/baseline/test_baseline.py::36": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/favicons/test_favicons.py::67": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_favicon_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/favicons/test_favicons.py::45": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_index_favicon_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/favicons/test_favicons.py::62": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_favicon_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/favicons/test_favicons.py::72": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_favicon_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/favicons/test_favicons.py::16": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_absolute_url_index_favicon_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::162": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_frontmatter_paths_are_relative_to_mdfile", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::136": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_frontmatter_paths_are_relative_to_mdfile", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::166": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_frontmatter_paths_are_relative_to_mdfile", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::149": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_frontmatter_paths_are_relative_to_mdfile", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_frontmatter_overrides_default", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::140": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_frontmatter_paths_are_relative_to_mdfile", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::29": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_frontmatter_overrides_default", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::26": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_frontmatter_overrides_default", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::35": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_frontmatter_overrides_default", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/frontmatter/test_frontmatter.py::31": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_frontmatter_overrides_default", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/images/test_images.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/images/test_images.py::18": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/images/test_images.py::19": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/images/test_images.py::20": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "run_build_strict"], "enclosing_function": "test_process_directory_without_config", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/index/test_index.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_index_title", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/index/test_index.py::20": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_index_title", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/index/test_index.py::32": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_index_banner", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/markdown_data_options/test_markdown_data_options.py::19": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_revealjs_markdown_data_options", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/navtree/test_navtree.py::91": {"resolved_imports": ["src/mkslides/config.py", "src/mkslides/markupgenerator.py", "src/mkslides/navtree.py"], "used_names": ["Any", "DeepDiff", "MarkupGenerator", "NavTree", "get_config", "json"], "enclosing_function": "test_navtree_from_md_files", "extracted_code": "# Source: src/mkslides/config.py\ndef get_config(config_file: Path | None = None) -> DictConfig:\n config = OmegaConf.structured(Config)\n\n if not config_file and DEFAULT_CONFIG_LOCATION.exists():\n config_file = DEFAULT_CONFIG_LOCATION.resolve(strict=True).absolute()\n\n config.internal.config_path = config_file\n if config_file:\n try:\n loaded_config = OmegaConf.load(config_file)\n config = OmegaConf.merge(config, loaded_config)\n\n logger.info(f\"Loaded config from '{config_file}'\")\n except Exception:\n logger.exception(f\"Failed to load config from {config_file}\")\n raise\n\n assert OmegaConf.is_dict(config)\n\n logger.debug(f\"Used config:\\n\\n{OmegaConf.to_yaml(config, resolve=True)}\")\n\n return config\n\n\n# Source: src/mkslides/markupgenerator.py\nclass MarkupGenerator:\n def __init__(\n self,\n global_config: DictConfig,\n md_root_path: Path,\n output_directory_path: Path,\n strict: bool,\n ) -> None:\n self.global_config = global_config\n self.md_root_path = md_root_path.resolve(strict=True)\n self.output_directory_path = output_directory_path.resolve(strict=False)\n logger.info(\n f\"Output directory: '{self.output_directory_path.absolute()}'\",\n )\n\n self.output_assets_path = self.output_directory_path / OUTPUT_ASSETS_DIRNAME\n self.output_revealjs_path = self.output_assets_path / \"reveal-js\"\n self.output_highlightjs_themes_path = (\n self.output_assets_path / \"highlight-js-themes\"\n )\n\n self.strict = strict\n\n def process_markdown(self) -> None:\n \"\"\"Process the markdown files and generate HTML slideshows.\"\"\"\n logger.debug(\"Processing markdown\")\n start_time = time.perf_counter()\n\n self.__create_or_clear_output_directory()\n\n if self.md_root_path.is_file():\n assert self.md_root_path.suffix == \".md\", (\n \"md_root_path must be a markdown file\"\n )\n self.__process_markdown_file()\n else:\n self.__process_markdown_directory()\n\n end_time = time.perf_counter()\n logger.info(\n f\"Finished processing markdown in {end_time - start_time:.2f} seconds\",\n )\n\n def __create_or_clear_output_directory(self) -> None:\n \"\"\"Clear or create the output directory and copy reveal.js.\"\"\"\n if self.output_directory_path.exists():\n shutil.rmtree(self.output_directory_path)\n logger.debug(\"Output directory already exists, deleted\")\n\n self.output_directory_path.mkdir(parents=True, exist_ok=True)\n logger.debug(\"Output directory created\")\n\n with resources.as_file(REVEALJS_RESOURCE) as revealjs_path:\n self.__copy(revealjs_path, self.output_revealjs_path)\n\n with resources.as_file(HIGHLIGHTJS_THEMES_RESOURCE) as highlightjs_themes_path:\n self.__copy(highlightjs_themes_path, self.output_highlightjs_themes_path)\n\n def scan_files(self) -> tuple[list[MdFileToProcess], list[Path]]:\n \"\"\"Scan the markdown directory for markdown files and other files.\"\"\"\n md_files: list[MdFileToProcess] = []\n non_md_files: list[Path] = []\n\n for file in self.md_root_path.rglob(\"*\"):\n if file.is_file():\n resolved_file = file.resolve(strict=True)\n if resolved_file.suffix.lower() == \".md\":\n destination_path = (\n self.output_directory_path\n / resolved_file.relative_to(self.md_root_path).with_suffix(\n \".html\",\n )\n )\n\n md_files.append(\n self.__create_md_file_to_process(\n resolved_file,\n destination_path,\n ),\n )\n\n else:\n non_md_files.append(resolved_file)\n\n return md_files, non_md_files\n\n def __create_md_file_to_process(\n self,\n source_path: Path,\n destination_path: Path,\n ) -> MdFileToProcess:\n \"\"\"Create an MdFileToProcess instance from a markdown file.\"\"\"\n content = source_path.read_text(encoding=\"utf-8-sig\")\n frontmatter_metadata, markdown_content = frontmatter.parse(content)\n\n slide_config = self.__generate_slide_config(\n source_path,\n destination_path,\n frontmatter_metadata,\n )\n assert slide_config\n\n markdown_content = emojize(markdown_content, language=\"alias\")\n\n if preprocess_script := slide_config.slides.preprocess_script:\n preprocess_function = load_preprocessing_function(preprocess_script)\n if not preprocess_function:\n msg = (\n f\"Preprocessing function '{preprocess_script}' could not be loaded\"\n )\n raise ImportError(msg)\n markdown_content = preprocess_function(markdown_content)\n logger.debug(\n f\"Applied preprocessing function '{preprocess_script}' to markdown content of '{source_path}'\",\n )\n\n return MdFileToProcess(\n source_path=source_path,\n destination_path=destination_path,\n slide_config=slide_config,\n markdown_content=markdown_content,\n )\n\n def __process_markdown_file(self) -> None:\n \"\"\"Process the detected markdown file.\"\"\"\n absolute_input_path = self.md_root_path.absolute()\n logger.debug(f\"Processing markdown file at '{absolute_input_path}'\")\n logger.warning(\n f\"When you use a single file like '{absolute_input_path}' as `PATH`, only default static assets will be copied to the output folder. If you want to include images or other files, create a folder instead and pass that as `PATH`. Using a file as `PATH` is more meant for a quick slideshow in a pinch using only text.\",\n )\n\n destination_path = self.output_directory_path / \"index.html\"\n md_file_data = self.__create_md_file_to_process(\n self.md_root_path,\n destination_path,\n )\n\n self.__process_detected_markdown_files([md_file_data])\n\n def __process_markdown_directory(self) -> None:\n \"\"\"Process the detected markdown files in a directory.\"\"\"\n logger.debug(\n f\"Processing markdown directory at '{self.md_root_path.absolute()}'\",\n )\n\n md_files, non_md_files = self.scan_files()\n\n self.__process_detected_markdown_files(md_files, non_md_files)\n\n def __process_detected_markdown_files(\n self,\n md_files: list,\n non_md_files: list | None = None,\n ) -> None:\n \"\"\"Process the detected markdown files and copy non-markdown files.\"\"\"\n if non_md_files:\n for file in non_md_files:\n destination_path = self.output_directory_path / file.relative_to(\n self.md_root_path,\n )\n self.__copy(file, destination_path)\n\n self.__handle_relative_links(md_files)\n\n templates = self.__load_templates(md_files)\n\n if len(md_files) == 1:\n md_files[0].destination_path = self.output_directory_path / \"index.html\"\n else:\n self.__generate_index(md_files)\n\n self.__render_slideshows(md_files, templates)\n\n def __render_slideshows(\n self,\n md_files: list[MdFileToProcess],\n templates: dict[str, Template],\n ) -> None:\n \"\"\"Render all markdown files to HTML slideshows.\"\"\"\n for md_file_data in md_files:\n slide_config = md_file_data.slide_config\n\n slideshow_template = None\n if template_config := slide_config.slides.template:\n slideshow_template = templates[template_config]\n else:\n slideshow_template = DEFAULT_SLIDESHOW_TEMPLATE\n\n revealjs_path = self.output_revealjs_path.relative_to(\n md_file_data.destination_path.parent,\n walk_up=True,\n )\n\n # https://revealjs.com/markdown/#external-markdown\n markdown_data_options = {\n key: value\n for key, value in {\n \"data-separator\": slide_config.slides.separator,\n \"data-separator-vertical\": slide_config.slides.separator_vertical,\n \"data-separator-notes\": slide_config.slides.separator_notes,\n \"data-charset\": slide_config.slides.charset,\n }.items()\n if value\n }\n\n markup = slideshow_template.render(\n favicon=slide_config.slides.favicon,\n theme=slide_config.slides.theme,\n highlight_theme=slide_config.slides.highlight_theme,\n revealjs_path=revealjs_path,\n markdown_data_options=markdown_data_options,\n markdown=md_file_data.markdown_content,\n revealjs_config=OmegaConf.to_container(slide_config.revealjs),\n plugins=slide_config.plugins,\n )\n\n self.__create_or_overwrite_file(\n md_file_data.destination_path,\n markup,\n )\n\n def __load_templates(\n self,\n md_files: list[MdFileToProcess],\n ) -> dict[str, Template]:\n \"\"\"Load Jinja2 templates from the markdown files.\"\"\"\n templates: dict[str, Template] = {}\n\n for md_file_data in md_files:\n template = md_file_data.slide_config.slides.template\n if template and template not in templates:\n templates[template] = LOCAL_JINJA2_ENVIRONMENT.get_template(template)\n logger.debug(f\"Loaded custom template '{template}'\")\n\n return templates\n\n def __generate_theme_url(\n self,\n destination_path: Path,\n slide_config: DictConfig,\n frontmatter_metadata: dict[str, object],\n ) -> str | None:\n \"\"\"Generate the reveal.js theme URL.\"\"\"\n theme = slide_config.slides.theme\n\n if theme is None:\n return None\n\n if theme in REVEALJS_THEMES_LIST:\n return str(\n (\n self.output_revealjs_path / \"dist\" / \"theme\" / f\"{theme}.css\"\n ).relative_to(destination_path.parent, walk_up=True),\n )\n\n if get_url_type(theme) != URLType.RELATIVE or (\n \"slides\" in frontmatter_metadata\n and isinstance(frontmatter_metadata[\"slides\"], dict)\n and frontmatter_metadata[\"slides\"].get(\"theme\")\n ):\n return theme\n\n return str(\n (self.output_directory_path / theme).relative_to(\n destination_path.parent,\n walk_up=True,\n ),\n )\n\n def __generate_highlight_theme_url(\n self,\n destination_path: Path,\n slide_config: DictConfig,\n frontmatter_metadata: dict[str, object],\n ) -> str | None:\n \"\"\"Generate the highlight.js theme URL.\"\"\"\n highlight_theme = slide_config.slides.highlight_theme\n\n if highlight_theme is None:\n return None\n\n if highlight_theme in HIGHLIGHTJS_THEMES_LIST:\n return str(\n (\n self.output_highlightjs_themes_path / f\"{highlight_theme}.css\"\n ).relative_to(destination_path.parent, walk_up=True),\n )\n\n if get_url_type(highlight_theme) != URLType.RELATIVE or (\n \"slides\" in frontmatter_metadata\n and isinstance(frontmatter_metadata[\"slides\"], dict)\n and frontmatter_metadata[\"slides\"].get(\"highlight_theme\")\n ):\n return highlight_theme\n\n return str(\n (self.output_directory_path / highlight_theme).relative_to(\n destination_path.parent,\n walk_up=True,\n ),\n )\n\n def __generate_favicon_url(\n self,\n destination_path: Path,\n slide_config: DictConfig,\n frontmatter_metadata: dict[str, object],\n ) -> str | None:\n favicon = slide_config.slides.favicon\n\n if favicon is None:\n return None\n\n if get_url_type(favicon) != URLType.RELATIVE or (\n \"slides\" in frontmatter_metadata\n and isinstance(frontmatter_metadata[\"slides\"], dict)\n and frontmatter_metadata[\"slides\"].get(\"favicon\")\n ):\n return favicon\n\n return str(\n (self.output_directory_path / favicon).relative_to(\n destination_path.parent,\n walk_up=True,\n ),\n )\n\n def __generate_preprocess_script_absolute_path(\n self,\n source_path: Path,\n slide_config: DictConfig,\n frontmatter_metadata: dict[str, object],\n ) -> str | None:\n \"\"\"Generate the absolute path for the preprocess script if it is a relative URL.\"\"\"\n preprocess_script = slide_config.slides.preprocess_script\n\n if slide_config.slides.preprocess_script is None:\n return None\n\n if get_url_type(preprocess_script) != URLType.RELATIVE:\n return preprocess_script\n\n if (\n \"slides\" in frontmatter_metadata\n and isinstance(frontmatter_metadata[\"slides\"], dict)\n and frontmatter_metadata[\"slides\"].get(\"preprocess_script\")\n ):\n return str(\n (source_path.parent / preprocess_script).resolve(strict=True),\n )\n\n return str(\n (\n self.global_config.internal.config_path.parent / preprocess_script\n ).resolve(strict=True),\n )\n\n def __generate_slide_config(\n self,\n source_path: Path,\n destination_path: Path,\n frontmatter_metadata: dict[str, object],\n ) -> DictConfig:\n \"\"\"Generate the slide configuration by merging the metadata retrieved from the frontmatter of the markdown and the global configuration.\"\"\"\n slide_config: DictConfig = deepcopy(self.global_config)\n\n if frontmatter_metadata:\n for key in FRONTMATTER_ALLOWED_KEYS:\n if key in frontmatter_metadata:\n OmegaConf.update(slide_config, key, frontmatter_metadata[key])\n\n slide_config.slides.theme = self.__generate_theme_url(\n destination_path,\n slide_config,\n frontmatter_metadata,\n )\n\n slide_config.slides.highlight_theme = self.__generate_highlight_theme_url(\n destination_path,\n slide_config,\n frontmatter_metadata,\n )\n\n slide_config.slides.favicon = self.__generate_favicon_url(\n destination_path,\n slide_config,\n frontmatter_metadata,\n )\n\n slide_config.slides.preprocess_script = (\n self.__generate_preprocess_script_absolute_path(\n source_path,\n slide_config,\n frontmatter_metadata,\n )\n )\n\n return slide_config\n\n def __generate_index(self, md_files: list[MdFileToProcess]) -> None:\n \"\"\"Generate an index.html file in the output directory.\"\"\"\n logger.debug(\"Generating index\")\n\n navtree = NavTree(self.md_root_path, self.output_directory_path)\n if self.global_config.index.nav:\n nav_from_config = OmegaConf.to_container(self.global_config.index.nav)\n assert isinstance(nav_from_config, list), \"nav must be a list\"\n logger.debug(\"Generating navigation tree from config\")\n navtree.from_config_json(nav_from_config)\n navtree.validate_with_md_files(md_files, strict=self.strict)\n else:\n logger.debug(\"Generating navigation tree from markdown files\")\n navtree.from_md_files(md_files)\n\n logger.debug(\n f\"Generated navigation tree with input root path {navtree.input_root_path.absolute()} and output root path {navtree.output_root_path.absolute()}\",\n )\n\n if logger.isEnabledFor(logging.DEBUG):\n navtree_json = json.dumps(json.loads(navtree.to_json()), indent=4)\n logger.debug(f\"Navigation tree:\\n\\n{navtree_json}\\n\")\n\n # Refresh the templates here, so they have effect when live reloading\n index_template = None\n if template_config := self.global_config.index.template:\n index_template = LOCAL_JINJA2_ENVIRONMENT.get_template(template_config)\n else:\n index_template = DEFAULT_INDEX_TEMPLATE\n\n content = index_template.render(\n favicon=self.global_config.index.favicon,\n title=self.global_config.index.title,\n theme=self.global_config.index.theme,\n navtree=navtree,\n build_datetime=datetime.datetime.now(tz=datetime.UTC),\n enable_footer=self.global_config.index.enable_footer,\n )\n self.__create_or_overwrite_file(\n self.output_directory_path / \"index.html\",\n content,\n )\n\n def __create_or_overwrite_file(self, destination_path: Path, content: Any) -> None:\n \"\"\"Create or overwrite a file with the given content.\"\"\"\n is_overwrite = destination_path.exists()\n\n destination_path.parent.mkdir(parents=True, exist_ok=True)\n destination_path.write_text(content, encoding=\"utf-8\")\n\n action = \"Overwritten\" if is_overwrite else \"Created\"\n logger.debug(f\"{action} file '{destination_path}'\")\n\n def __copy(self, source_path: Path, destination_path: Path) -> None:\n \"\"\"Copy a file or directory from the source path to the destination path.\"\"\"\n is_overwrite = destination_path.exists()\n is_directory = source_path.is_dir()\n\n destination_path.parent.mkdir(parents=True, exist_ok=True)\n\n if is_directory:\n shutil.copytree(source_path, destination_path, dirs_exist_ok=True)\n else:\n shutil.copy(source_path, destination_path)\n\n action = \"Overwritten\" if is_overwrite else \"Copied\"\n file_or_directory = \"directory\" if is_directory else \"file\"\n logger.debug(\n f\"{action} {file_or_directory} '{source_path.absolute()}' to '{destination_path.absolute()}'\",\n )\n\n def __handle_relative_links(\n self,\n md_file_data: list[MdFileToProcess],\n ) -> None:\n \"\"\"Check if all relative link targets are present and normalize .md links.\"\"\"\n for md_file in md_file_data:\n content = md_file.markdown_content\n\n for link in self.__find_all_relative_links(content):\n link_path = md_file.source_path.parent / link\n relative_source_path = md_file.source_path.relative_to(\n self.md_root_path,\n )\n\n if not link_path.exists():\n msg = f\"File '{relative_source_path}' contains a link '{link}', but the target is not found among slide files.\"\n if self.strict:\n raise FileNotFoundError(msg)\n logger.warning(msg)\n elif link.lower().endswith(\".md\"):\n content = self.__replace_md_link_target(content, link)\n\n md_file.markdown_content = content\n\n def __find_all_relative_links(self, markdown_content: str) -> set[str]:\n \"\"\"Find all relative links in the given markdown content.\"\"\"\n html_content = markdown.markdown(markdown_content, extensions=[\"extra\"])\n soup = BeautifulSoup(html_content, \"html.parser\")\n\n found_links = set()\n\n for link in soup.find_all(\"a\", href=True):\n if not link.find_parents([\"code\", \"pre\"]):\n found_links.add(link[\"href\"])\n\n for link in soup.find_all(\"img\", src=True):\n if not link.find_parents([\"code\", \"pre\"]):\n found_links.add(link[\"src\"])\n\n for link in soup.find_all(\"source\", src=True):\n if not link.find_parents([\"code\", \"pre\"]):\n found_links.add(link[\"src\"])\n\n for comment in soup.find_all(string=lambda text: isinstance(text, Comment)):\n if match := HTML_BACKGROUND_IMAGE_REGEX.search(comment):\n found_links.add(match.group(\"location\"))\n\n relative_links = {\n link for link in found_links if get_url_type(link) == URLType.RELATIVE\n }\n\n return relative_links\n\n def __replace_md_link_target(self, content: str, link: str) -> str:\n \"\"\"Replace a specific .md link target with .html in markdown and HTML links.\"\"\"\n\n def _replacer(match: re.Match, *, link: str) -> str:\n matched_location = match.group(\"location\")\n\n # Only touch matches that correspond exactly to this link\n if matched_location != link:\n return match.group(0)\n\n new_location = MD_EXTENSION_REGEX.sub(\".html\", matched_location)\n return match.group(0).replace(matched_location, new_location)\n\n for regex in (MD_RELATIVE_LINK_REGEX, HTML_RELATIVE_LINK_REGEX):\n bound_replacer = partial(_replacer, link=link)\n content = regex.sub(bound_replacer, content)\n\n return content\n\n\n# Source: src/mkslides/navtree.py\nclass NavTree:\n def __init__(self, input_root_path: Path, output_root_path: Path) -> None:\n self.input_root_path = input_root_path\n self.output_root_path = output_root_path\n\n # Relative path as str is the index, title as str the data.\n self.tree = Tree()\n self.tree.create_node(identifier=\"root\")\n\n def from_md_files(self, md_files: list[MdFileToProcess]) -> None:\n for md_file in md_files:\n relative_source_path = md_file.source_path.relative_to(\n self.input_root_path,\n )\n parts = relative_source_path.parts\n\n current_relative_source_path = Path()\n parent_node_id = str(self.tree.root)\n for part in parts:\n current_relative_source_path /= part\n\n node_id = None\n if (self.input_root_path / current_relative_source_path).is_dir():\n node_id = str(current_relative_source_path)\n else:\n node_id = str(current_relative_source_path.with_suffix(\".html\"))\n\n node_data = None\n if md_file.slide_config.slides.title:\n node_data = md_file.slide_config.slides.title\n else:\n node_data = current_relative_source_path.stem\n\n if node_id not in self.tree:\n self.tree.create_node(\n identifier=node_id,\n parent=parent_node_id,\n data=node_data,\n )\n\n parent_node_id = node_id\n\n def from_config_json(self, json_data: list) -> None:\n assert isinstance(json_data, list), \"json data must be a list\"\n\n for item in json_data:\n self.__node_from_config_json(\n item,\n self.output_root_path,\n str(self.tree.root),\n )\n\n def __node_from_config_json(\n self,\n json_data: dict | str,\n current_path: Path,\n parent_node_id: str,\n ) -> None:\n # leaf node\n #\n # - filename.md\n #\n if isinstance(json_data, str):\n destination_path = (current_path / json_data).with_suffix(\".html\")\n node_id = str(destination_path.relative_to(self.output_root_path))\n node_data = destination_path.stem\n\n self.tree.create_node(\n identifier=node_id,\n parent=parent_node_id,\n data=node_data,\n )\n\n # category or leaf node with custom file name\n elif isinstance(json_data, dict):\n assert len(json_data.keys()) == 1, \"json dict must have one key\"\n\n title, content = next(iter(json_data.items()))\n\n # leaf node with custom name\n #\n # - custom-file-name: filename.md\n #\n if isinstance(content, str):\n destination_path = (current_path / content).with_suffix(\".html\")\n node_id = str(destination_path.relative_to(self.output_root_path))\n node_data = title\n\n self.tree.create_node(\n identifier=node_id,\n parent=parent_node_id,\n data=node_data,\n )\n\n # category node\n #\n # - category:\n # - ...\n #\n elif isinstance(content, list):\n destination_path = current_path / title\n node_id = str(f\"{destination_path.relative_to(self.output_root_path)}\")\n node_data = title\n\n self.tree.create_node(\n identifier=node_id,\n parent=parent_node_id,\n data=node_data,\n )\n\n for item in content:\n self.__node_from_config_json(item, destination_path, node_id)\n\n else:\n msg = f\"json dict must have a string or list as value, but value is of {type(content)}\"\n raise TypeError(msg)\n\n else:\n msg = (\n f\"json data must be a string or dict, but is of type {type(json_data)}\"\n )\n\n raise TypeError(msg)\n\n def is_node_leaf(self, node_id: str) -> bool:\n return self.tree[node_id].is_leaf(self.tree.identifier)\n\n def get_node_children(self, node_id: str) -> list:\n return sorted(self.tree.children(node_id), key=lambda n: n.identifier)\n\n def to_json(self) -> str:\n if not self.tree:\n return \"{}\"\n\n return self.tree.to_json(with_data=True)\n\n def validate_with_md_files(\n self,\n md_files: list[MdFileToProcess],\n strict: bool,\n ) -> None:\n md_file_relative_destination_paths = [\n str(md_file.destination_path.relative_to(self.output_root_path))\n for md_file in md_files\n ]\n\n files_not_in_navtree = []\n for md_file_relative_destination_path in md_file_relative_destination_paths:\n if md_file_relative_destination_path not in self.tree:\n source_file_name = str(\n Path(md_file_relative_destination_path).with_suffix(\".md\"),\n )\n files_not_in_navtree.append(source_file_name)\n\n if files_not_in_navtree:\n logger.info(\n \"The following pages exist in the slides directory, but are not included in the 'nav' configuration:\",\n )\n\n for file_name in files_not_in_navtree:\n logger.info(f\"\\t- {file_name}\")\n\n for node_id in self.tree.expand_tree():\n node = self.tree.get_node(node_id)\n assert node\n if (\n node.is_leaf(self.tree.identifier)\n and node.identifier not in md_file_relative_destination_paths\n ):\n source_file_name = Path(node.identifier).with_suffix(\".md\").name\n msg = f\"A reference to '{source_file_name}' is included in the 'nav' configuration, which is not found in the slideshow files.\"\n if strict:\n raise FileNotFoundError(msg)\n logger.warning(msg)", "n_imports_parsed": 9, "n_files_resolved": 3, "n_chars_extracted": 27622}, "tests/navtree/test_navtree.py::194": {"resolved_imports": ["src/mkslides/config.py", "src/mkslides/markupgenerator.py", "src/mkslides/navtree.py"], "used_names": ["Any", "re", "subprocess"], "enclosing_function": "test_files_not_in_folder_without_strict", "extracted_code": "", "n_imports_parsed": 9, "n_files_resolved": 3, "n_chars_extracted": 0}, "tests/plugins/test_plugins.py::25": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_plugins", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/plugins/test_plugins.py::29": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_plugins", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/plugins/test_plugins.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_plugins", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/plugins/test_plugins.py::37": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_plugins", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/plugins/test_plugins.py::33": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_plugins", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/preprocessing/test_preprocessing.py::17": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_preprocessing", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/preprocessing/test_preprocessing.py::31": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_preprocessing", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_links/test_relative_links.py::43": {"resolved_imports": [], "used_names": ["Any", "re", "subprocess"], "enclosing_function": "test_non_existing_relative_links_without_strict", "extracted_code": "", "n_imports_parsed": 4, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_slideshow_links/test_relative_slideshow_links.py::94": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_relative_slideshow_links", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_slideshow_links/test_relative_slideshow_links.py::18": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_relative_slideshow_links", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_slideshow_links/test_relative_slideshow_links.py::19": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_relative_slideshow_links", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_slideshow_links/test_relative_slideshow_links.py::98": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_relative_slideshow_links", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/relative_slideshow_links/test_relative_slideshow_links.py::20": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_relative_slideshow_links", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/revealjs_options/test_revealjs_options.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_revealjs_default_options", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/revealjs_options/test_revealjs_options.py::53": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_revealjs_string_options", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/revealjs_options/test_revealjs_options.py::30": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains_regexp", "re", "run_build_strict"], "enclosing_function": "test_revealjs_integer_options", "extracted_code": "", "n_imports_parsed": 3, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/single_md_in_folder/test_single_md_in_folder.py::33": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_multiple_md_files_in_folder", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/single_md_in_folder/test_single_md_in_folder.py::20": {"resolved_imports": [], "used_names": ["Any", "assert_file_does_not_exist", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_single_md_files_in_folder", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/single_md_in_folder/test_single_md_in_folder.py::21": {"resolved_imports": [], "used_names": ["Any", "assert_file_does_not_exist", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_single_md_files_in_folder", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/single_md_in_folder/test_single_md_in_folder.py::23": {"resolved_imports": [], "used_names": ["Any", "assert_file_does_not_exist", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_single_md_files_in_folder", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/single_md_in_folder/test_single_md_in_folder.py::24": {"resolved_imports": [], "used_names": ["Any", "assert_file_does_not_exist", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_single_md_files_in_folder", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/text/test_emojis.py::23": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_emojize", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/text/test_emojis.py::22": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_emojize", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::46": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::20": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::33": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::50": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::59": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_local_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::108": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_builtin_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::79": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_absolute_url_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::83": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_absolute_url_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::75": {"resolved_imports": [], "used_names": ["Any", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_absolute_url_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::118": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_builtin_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::123": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_builtin_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}, "tests/themes/test_themes.py::132": {"resolved_imports": [], "used_names": ["Any", "assert_file_exist", "assert_html_contains", "run_build_strict"], "enclosing_function": "test_builtin_slideshow_theme_path", "extracted_code": "", "n_imports_parsed": 2, "n_files_resolved": 0, "n_chars_extracted": 0}}}