Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mondeja/mkdocs-include-markdown-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.0.6
Choose a base ref
...
head repository: mondeja/mkdocs-include-markdown-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.7
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on May 29, 2024

  1. Fix error message on Windows (#210)

    mondeja authored May 29, 2024
    Copy the full SHA
    eb65645 View commit details
Showing with 22 additions and 6 deletions.
  1. +2 −2 .pre-commit-config.yaml
  2. +1 −1 pyproject.toml
  3. +19 −3 src/mkdocs_include_markdown_plugin/event.py
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ repos:
- id: end-of-file-fixer
name: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
rev: v0.4.6
hooks:
- id: ruff
args:
@@ -99,7 +99,7 @@ repos:
- platformdirs
- wcmatch
- repo: https://github.com/tcort/markdown-link-check
rev: v3.12.1
rev: v3.12.2
hooks:
- id: markdown-link-check
name: markdown-link-check
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mkdocs-include-markdown-plugin"
version = "6.0.6"
version = "6.0.7"
description = "Mkdocs Markdown includer plugin."
readme = "README.md"
license = "Apache-2.0"
22 changes: 19 additions & 3 deletions src/mkdocs_include_markdown_plugin/event.py
Original file line number Diff line number Diff line change
@@ -58,6 +58,22 @@ def lineno_from_content_start(content: str, start: int) -> int:
return content[:start].count('\n') + 1


def safe_os_path_relpath(path: str, start: str) -> str:
"""Return the relative path of a file from a start directory.
Safe version of `os.path.relpath` that catches `ValueError` exceptions
on Windows and returns the original path in case of error.
On Windows, `ValueError` is raised when `path` and `start` are on
different drives.
"""
if os.name != 'nt': # pragma: nt no cover
return os.path.relpath(path, start)
try: # pragma: nt cover
return os.path.relpath(path, start)
except ValueError: # pragma: no cover
return path


def file_lineno_message(
page_src_path: str | None,
docs_dir: str,
@@ -67,7 +83,7 @@ def file_lineno_message(
if page_src_path is None: # pragma: no cover
return f'generated page content (line {lineno})'
return (
f'{os.path.relpath(page_src_path, docs_dir)}'
f'{safe_os_path_relpath(page_src_path, docs_dir)}'
f':{lineno}'
)

@@ -287,7 +303,7 @@ def found_include_tag( # noqa: PLR0912, PLR0915
if expected_but_any_found[i]:
delimiter_value = locals()[delimiter_name]
readable_files_to_include = ', '.join([
os.path.relpath(fpath, docs_dir)
safe_os_path_relpath(fpath, docs_dir)
for fpath in file_paths_to_include
])
plural_suffix = 's' if len(file_paths_to_include) > 1 else ''
@@ -593,7 +609,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915
if expected_but_any_found[i]:
delimiter_value = locals()[delimiter_name]
readable_files_to_include = ', '.join([
os.path.relpath(fpath, docs_dir)
safe_os_path_relpath(fpath, docs_dir)
for fpath in file_paths_to_include
])
plural_suffix = 's' if len(file_paths_to_include) > 1 else ''