From 177536a20b03afb5353ab832d4455b1d6f4483c9 Mon Sep 17 00:00:00 2001 From: Tobias Ahrens <73690588+tobiasah@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:20:33 +0200 Subject: [PATCH] Only copy source files if they are converted by the plugin (#222) --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 5 +++++ src/mkdocs_jupyter/plugin.py | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8382406..2179511 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,7 +85,7 @@ jobs: file: ./coverage.xml - name: Upload test results to GitHub - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: test-results-py${{ matrix.python-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index f448c91..3683f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # mkdocs-jupyter Change Log +## 0.25.1 + +- Fix issue which caused unrelated source files from being copied into the output directory. +- Replace print statements with logging. + ## 0.24.3 - Fix theme selection diff --git a/src/mkdocs_jupyter/plugin.py b/src/mkdocs_jupyter/plugin.py index 85fa529..c92b1fa 100644 --- a/src/mkdocs_jupyter/plugin.py +++ b/src/mkdocs_jupyter/plugin.py @@ -1,3 +1,4 @@ +import logging import os import pathlib @@ -12,6 +13,8 @@ from . import convert +logger = logging.getLogger("mkdocs.plugins.mkdocs_jupyter") + class NotebookFile(File): """ @@ -150,7 +153,7 @@ def _set_nb_url(self, page): def on_post_page(self, output_content, page, config): # Include source - if self.config["include_source"]: + if self.config["include_source"] and self.should_include(page.file): from shutil import copyfile nb_source = page.file.abs_src_path @@ -160,7 +163,7 @@ def on_post_page(self, output_content, page, config): os.makedirs(nb_target_dir, exist_ok=True) copyfile(nb_source, nb_target) - print(f"Copied jupyter file: {nb_source} to {nb_target}") + logger.info("Copied jupyter file: %s to %s", nb_source, nb_target) # Include data files data_files = self.config["data_files"].get(page.file.src_path, []) @@ -175,7 +178,7 @@ def on_post_page(self, output_content, page, config): os.makedirs(data_target_dir, exist_ok=True) copyfile(data_source, data_target) - print(page.data_files) + logger.info("Copied data files: %s to %s", data_files, data_target_dir) def _get_markdown_toc(markdown_source, toc_depth):