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

Fix errors when using Mkdocs>=1.6.0 generated files #205

Merged
merged 4 commits into from
May 2, 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
61 changes: 23 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,36 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- platform: ubuntu-latest
python-version: 3.8
py: py38
- platform: ubuntu-latest
python-version: 3.9
py: py39
- platform: ubuntu-latest
python-version: "3.10"
py: py310
- platform: ubuntu-latest
python-version: "3.11"
py: py311
- platform: ubuntu-latest
python-version: "3.12"
py: py312
- platform: macos-latest
python-version: 3.8
py: py38
- platform: macos-latest
python-version: "3.11"
py: py311
- platform: macos-latest
python-version: "3.12"
py: py312
- platform: windows-latest
python-version: 3.8
py: py38
- platform: windows-latest
python-version: "3.11"
py: py311
- platform: windows-latest
python-version: "3.12"
py: py312
py:
- 3.8
- 3.9
- "3.10"
- "3.11"
- "3.12"
platform:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python v${{ matrix.python-version }}
- name: Set up Python v${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.py }}
- name: Pick environment to run
id: env
shell: python
run: |
import codecs, os, sys
env = f"py=py3{sys.version_info[1]}\n"
print(f"Picked {env.split('=')[1].strip()} for {sys.version}")
with codecs.open(os.environ["GITHUB_OUTPUT"], "a", "utf-8") as file_handler:
file_handler.write(env)
- name: Install dependencies
run: pip install -U hatch
- name: Run tests
run: |
hatch run +py=${{ matrix.py }} tests:all
hatch run +py=${{ steps.env.outputs.py }} tests:all
- name: Convert coverage to XML
run: |
pip install coverage covdefaults
Expand All @@ -97,7 +82,7 @@ jobs:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.10"
python-version: "3.11"
- name: Install build dependencies
run: pip install -U hatch
- name: Build package
Expand Down
23 changes: 17 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ repos:
- id: check-useless-excludes
name: check-useless-excludes
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
name: trailing-whitespace
- id: end-of-file-fixer
name: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.4.2
hooks:
- id: ruff
args:
Expand All @@ -44,7 +44,7 @@ repos:
hooks:
- id: autopep8
- repo: https://github.com/mondeja/mdpo
rev: v2.0.0
rev: v2.0.1
hooks:
- id: md2po2md
files: ^README\.md
Expand All @@ -67,7 +67,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.12.1
rev: v0.13.0
hooks:
- id: markdownlint-cli2
name: markdownlint-readme
Expand All @@ -79,12 +79,23 @@ repos:
name: editorconfig-checker
alias: ec
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
name: mypy-mkdocs-1.5.0
files: ^src
additional_dependencies:
- mkdocs
- mkdocs>=1.5.0,<1.6.0
- platformdirs
- wcmatch
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
name: mypy-mkdocs-1.6.0
files: ^src
additional_dependencies:
- mkdocs>=1.6.0,<1.7.0
- platformdirs
- wcmatch
- repo: https://github.com/tcort/markdown-link-check
Expand Down
5 changes: 3 additions & 2 deletions 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.5"
version = "6.0.6"
description = "Mkdocs Markdown includer plugin."
readme = "README.md"
license = "Apache-2.0"
Expand Down Expand Up @@ -74,7 +74,7 @@ dependencies = ["pytest~=7.0", "coverage~=6.4", "covdefaults"]

[[tool.hatch.envs.tests.matrix]]
python = ["py38", "py39", "py310", "py311", "py312"]
mkdocs = ["1.4.0", "1.4.3", "1.5.0", "1.5.3"]
mkdocs = ["1.4.0", "1.4.3", "1.5.0", "1.5.3", "1.6.0"]
cache = ["yes", "no"]

[tool.hatch.envs.tests.overrides]
Expand All @@ -83,6 +83,7 @@ matrix.mkdocs.dependencies = [
{ value = "mkdocs==1.4.3", if = ["1.4.3"] },
{ value = "mkdocs==1.5.0", if = ["1.5.0"] },
{ value = "mkdocs==1.5.3", if = ["1.5.3"] },
{ value = "mkdocs==1.6.0", if = ["1.6.0"] },
]
matrix.cache.dependencies = [{ value = "platformdirs", if = ["yes"] }]

Expand Down
35 changes: 24 additions & 11 deletions src/mkdocs_include_markdown_plugin/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from mkdocs.exceptions import PluginError
from wcmatch import glob

from mkdocs_include_markdown_plugin import process
Expand Down Expand Up @@ -174,19 +175,19 @@


def resolve_file_paths_to_include(
filename_or_url: str,
includer_page_src_path: str,
include_string: str,
includer_page_src_path: str | None,
docs_dir: str,
ignore_paths: list[str],
) -> tuple[list[str], bool]:
"""Resolve the file paths to include for a directive."""
if process.is_url(filename_or_url):
return [filename_or_url], True
if process.is_url(include_string):
return [include_string], True

if process.is_absolute_path(filename_or_url):
if process.is_absolute_path(include_string):
if os.name == 'nt': # pragma: nt cover
# Windows
fpath = os.path.normpath(filename_or_url)
fpath = os.path.normpath(include_string)

Check warning on line 190 in src/mkdocs_include_markdown_plugin/directive.py

View check run for this annotation

Codecov / codecov/patch

src/mkdocs_include_markdown_plugin/directive.py#L190

Added line #L190 was not covered by tests
if not os.path.isfile(fpath):
return [], False

Expand All @@ -195,21 +196,27 @@
), False
return process.filter_paths(
glob.iglob(
os.path.normpath(filename_or_url),
os.path.normpath(include_string),
flags=GLOB_FLAGS,
),
ignore_paths,
), False

if process.is_relative_path(filename_or_url):
if process.is_relative_path(include_string):
if includer_page_src_path is None: # pragma: no cover
raise PluginError(
'Relative paths are not allowed when the includer page'
' source path is not provided. The include string'
f" '{include_string}' is located inside a generated page.",
)
root_dir = os.path.abspath(
os.path.dirname(includer_page_src_path),
)
return process.filter_paths(
(
os.path.normpath(os.path.join(root_dir, fp))
for fp in glob.iglob(
filename_or_url,
include_string,
flags=GLOB_FLAGS,
root_dir=root_dir,
)
Expand All @@ -221,7 +228,7 @@
(
os.path.normpath(os.path.join(docs_dir, fp))
for fp in glob.iglob(
filename_or_url,
include_string,
flags=GLOB_FLAGS,
root_dir=docs_dir,
)
Expand All @@ -232,7 +239,7 @@

def resolve_file_paths_to_exclude(
exclude_string: str,
includer_page_src_path: str,
includer_page_src_path: str | None,
docs_dir: str,
) -> list[str]:
"""Resolve the file paths to exclude for a directive."""
Expand All @@ -241,6 +248,12 @@
return glob.glob(exclude_string, flags=GLOB_FLAGS)

if process.is_relative_path(exclude_string):
if includer_page_src_path is None: # pragma: no cover
raise PluginError(
'Relative paths are not allowed when the includer page'
' source path is not provided. The exclude string'
f" '{exclude_string}' is located inside a generated page.",
)
root_dir = os.path.abspath(
os.path.dirname(includer_page_src_path),
)
Expand Down
Loading
Loading