diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eff0d16..fab9da1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,14 +23,12 @@ repos: entry: flake8 language: system types: [python] - args: [--max-line-length=120, --docstring-convention=google, "--ignore=D100,D103,D104,D212,D200,E203,W293,D412,W503,E501"] + args: [--max-line-length=120, --docstring-convention=google, "--ignore=D100,D104,D212,D200,E203,W293,D412,W503"] # D100 requires all Python files (modules) to have a "public" docstring even if all functions within have a docstring. # D104 requires __init__ files to have a docstring # D212 # D200 # D412 No blank lines allowed between a section header and its content # E203 -# E501 line too long (122 > 120 characters) -# D103 Missing docstring in public function # W293 blank line contains whitespace # W503 line break before binary operator (for compatibility with black) \ No newline at end of file diff --git a/mkdocs_print_site_plugin/plugin.py b/mkdocs_print_site_plugin/plugin.py index 42fd258..01f5404 100644 --- a/mkdocs_print_site_plugin/plugin.py +++ b/mkdocs_print_site_plugin/plugin.py @@ -6,7 +6,6 @@ from mkdocs.structure.files import File from mkdocs.structure.pages import Page from mkdocs.utils import write_file, copy_file, get_relative_url, warning_filter -from mkdocs.exceptions import ConfigurationError from mkdocs_print_site_plugin.renderer import Renderer from mkdocs_print_site_plugin.utils import get_theme_name @@ -60,17 +59,6 @@ def on_config(self, config, **kwargs): msg += "Please update the 'plugins:' section in your mkdocs.yml" logger.warning(msg) - # There is a bug with mkdocs-material theme and - # the pymdownx.details markdown extension. Detect + raise error. - # Details: https://github.com/squidfunk/mkdocs-material/issues/2655 - if "pymdownx.details" in config.get("markdown_extensions", []): - if get_theme_name(config) == "material": - msg = "[mkdocs-print-site-plugin]: Using 'mkdocs-material' theme with " - msg += "the 'pymdownx.details' markdown extension will break printing.\n" - msg += "Please remove 'pymdownx.details' or use a different theme." - msg += "Details: https://github.com/squidfunk/mkdocs-material/issues/2655." - raise ConfigurationError(msg) - # Get abs path to cover_page_template self.cover_page_template_path = "" if self.config.get("add_cover_page"): diff --git a/tests/fixtures/projects/with_markdown_ext/mkdocs.yml b/tests/fixtures/projects/with_markdown_ext/mkdocs.yml index fab3294..a40568a 100644 --- a/tests/fixtures/projects/with_markdown_ext/mkdocs.yml +++ b/tests/fixtures/projects/with_markdown_ext/mkdocs.yml @@ -40,6 +40,7 @@ markdown_extensions: smart_enable: all - pymdownx.caret - pymdownx.critic + - pymdownx.details - pymdownx.emoji: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg diff --git a/tests/fixtures/projects/with_markdown_ext/mkdocs_details.yml b/tests/fixtures/projects/with_markdown_ext/mkdocs_details.yml deleted file mode 100644 index e8652a1..0000000 --- a/tests/fixtures/projects/with_markdown_ext/mkdocs_details.yml +++ /dev/null @@ -1,29 +0,0 @@ -site_name: Test - -theme: - name: material - custom_dir: docs/overrides - -plugins: - - print-site - -nav: - - Home: index.md - - Two: two.md - - Folder: - - Subpage: folder/subpage.md - - Duplicate_entry: folder/subfolder/nested_file.md - - Extensions: - - Admonition: extensions/admonition.md - - CodeHilite: extensions/codehilite.md - - Footnotes: extensions/footnotes.md - - Metadata: extensions/metadata.md - - Permalinks: extensions/permalinks.md - - Folder: folder/subfolder/nested_file.md - - PyMdown: extensions/pymdown.md - - Images: images.md - - -# This should raise an error -markdown_extensions: - - pymdownx.details diff --git a/tests/fixtures/projects/with_markdown_ext/mkdocs_diff_cover_page.yml b/tests/fixtures/projects/with_markdown_ext/mkdocs_diff_cover_page.yml index c5f8498..4bbf655 100644 --- a/tests/fixtures/projects/with_markdown_ext/mkdocs_diff_cover_page.yml +++ b/tests/fixtures/projects/with_markdown_ext/mkdocs_diff_cover_page.yml @@ -42,6 +42,7 @@ markdown_extensions: smart_enable: all - pymdownx.caret - pymdownx.critic + - pymdownx.details - pymdownx.emoji: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg diff --git a/tests/fixtures/projects/with_markdown_ext/mkdocs_img2fig.yml b/tests/fixtures/projects/with_markdown_ext/mkdocs_img2fig.yml index 6eb5b1c..e0e5f73 100644 --- a/tests/fixtures/projects/with_markdown_ext/mkdocs_img2fig.yml +++ b/tests/fixtures/projects/with_markdown_ext/mkdocs_img2fig.yml @@ -41,6 +41,7 @@ markdown_extensions: smart_enable: all - pymdownx.caret - pymdownx.critic + - pymdownx.details - pymdownx.emoji: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg diff --git a/tests/fixtures/projects/with_markdown_ext/mkdocs_with_toc.yml b/tests/fixtures/projects/with_markdown_ext/mkdocs_with_toc.yml index 00771a1..cf05cac 100644 --- a/tests/fixtures/projects/with_markdown_ext/mkdocs_with_toc.yml +++ b/tests/fixtures/projects/with_markdown_ext/mkdocs_with_toc.yml @@ -43,6 +43,7 @@ markdown_extensions: smart_enable: all - pymdownx.caret - pymdownx.critic + - pymdownx.details - pymdownx.emoji: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg diff --git a/tests/test_building.py b/tests/test_building.py index fe86c2a..290396d 100644 --- a/tests/test_building.py +++ b/tests/test_building.py @@ -30,19 +30,20 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path): """ - Sets up a clean mkdocs directory. - + Sets up a clean mkdocs directory + outputpath/testproject ├── docs/ └── mkdocs.yml - + Args: mkdocs_yml_path (Path): Path of mkdocs.yml file to use output_path (Path): Path of folder in which to create mkdocs project - + Returns: testproject_path (Path): Path to test project """ + assert os.path.exists(mkdocs_yml_path) testproject_path = output_path / "testproject" @@ -50,7 +51,7 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path): # Create empty 'testproject' folder if os.path.exists(str(testproject_path)): logging.warning( - """This command does not work on windows. + """This command does not work on windows. Refactor your test to use setup_clean_mkdocs_folder() only once""" ) shutil.rmtree(str(testproject_path)) @@ -66,14 +67,15 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path): def build_docs_setup(testproject_path): """ - Runs the `mkdocs build` command. - + Runs the `mkdocs build` command + Args: testproject_path (Path): Path to test project - + Returns: command: Object with results of command """ + cwd = os.getcwd() os.chdir(str(testproject_path)) @@ -81,13 +83,15 @@ def build_docs_setup(testproject_path): run = CliRunner().invoke(build_command, catch_exceptions=True) os.chdir(cwd) return run - except Exception: + except: os.chdir(cwd) raise def check_build(tmp_path, project_mkdocs, exit_code=0): - tmp_proj = setup_clean_mkdocs_folder("tests/fixtures/projects/%s" % project_mkdocs, tmp_path) + tmp_proj = setup_clean_mkdocs_folder( + "tests/fixtures/projects/%s" % project_mkdocs, tmp_path + ) result = build_docs_setup(tmp_proj) msg = "cwd: %s, result: %s, exception: %s, exc_info: %s" % ( @@ -107,7 +111,7 @@ def text_in_page(tmp_proj, page_path, text): return re.search(text, contents) -# Tests +#### Tests #### def test_windmill(tmp_path): @@ -118,11 +122,9 @@ def test_no_toc(tmp_path): prj_path = check_build(tmp_path, "basic/mkdocs_no_toc.yml") # Table of contents should NOT be there - assert not text_in_page(prj_path, "print_page/index.html", '