Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only copy source files if they are converted by the plugin #222

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading