Skip to content

Commit

Permalink
Only copy source files if they are converted by the plugin (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasah authored Oct 14, 2024
1 parent d72a84a commit 177536a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/mkdocs_jupyter/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import pathlib

Expand All @@ -12,6 +13,8 @@

from . import convert

logger = logging.getLogger("mkdocs.plugins.mkdocs_jupyter")


class NotebookFile(File):
"""
Expand Down Expand Up @@ -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
Expand All @@ -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, [])
Expand All @@ -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):
Expand Down

0 comments on commit 177536a

Please sign in to comment.