From 50abbe71fd29440cb03bd4a11c6aebc4c15bbdc8 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Wed, 22 Apr 2026 04:30:40 +0300 Subject: [PATCH 1/5] Fix CLI livereload option and update Python version support in CI --- mkdocs/__main__.py | 2 +- mkdocs/config/config_options.py | 3 ++- pyproject.toml | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py index c8d40969..394ca272 100644 --- a/mkdocs/__main__.py +++ b/mkdocs/__main__.py @@ -253,8 +253,8 @@ def cli(): @cli.command(name="serve") @click.option('-a', '--dev-addr', help=dev_addr_help, metavar='') @click.option('-o', '--open', 'open_in_browser', help=serve_open_help, is_flag=True) -@click.option('--no-livereload', 'livereload', flag_value=False, help=no_reload_help) @click.option('--livereload', 'livereload', flag_value=True, default=True, hidden=True) +@click.option('--no-livereload', 'livereload', flag_value=False, help=no_reload_help) @click.option('--dirtyreload', 'build_type', flag_value='dirty', hidden=True) @click.option('--dirty', 'build_type', flag_value='dirty', help=serve_dirty_help) @click.option('-c', '--clean', 'build_type', flag_value='clean', help=serve_clean_help) diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py index 94171c45..37078b04 100644 --- a/mkdocs/config/config_options.py +++ b/mkdocs/config/config_options.py @@ -6,6 +6,7 @@ import os import string import sys +import textwrap import traceback import types import warnings @@ -1221,6 +1222,6 @@ def run_validation(self, value: object) -> pathspec.gitignore.GitIgnoreSpec: if not isinstance(value, str): raise ValidationError(f'Expected a multiline string, but a {type(value)} was given.') try: - return pathspec.gitignore.GitIgnoreSpec.from_lines(lines=value.splitlines()) + return pathspec.gitignore.GitIgnoreSpec.from_lines(lines=textwrap.dedent(value).splitlines()) except ValueError as e: raise ValidationError(str(e)) diff --git a/pyproject.toml b/pyproject.toml index 87cb1f67..f2489d95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,7 @@ artifacts = ["/mkdocs/**/*.mo"] [tool.hatch.build.targets.sdist] include = ["/mkdocs"] [tool.hatch.build.targets.wheel] +packages = ["mkdocs"] exclude = ["/mkdocs/tests", "*.po", "*.pot", "babel.cfg"] [tool.hatch.build.hooks.custom] dependencies = [ @@ -129,7 +130,7 @@ _coverage = [ ] with-coverage = "test" [[tool.hatch.envs.test.matrix]] -python = ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3"] +python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy3"] type = ["default", "min-req"] [tool.hatch.envs.test.overrides] matrix.type.features = [ @@ -146,7 +147,7 @@ detached = false [tool.hatch.envs.integration.scripts] test = "python -m mkdocs.tests.integration" [[tool.hatch.envs.integration.matrix]] -python = ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3"] +python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy3"] type = ["default", "no-babel"] [tool.hatch.envs.integration.overrides] matrix.type.features = [ From 0b63e0fb28a3cd2bc87d541d53ea33e8a48ed819 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Wed, 22 Apr 2026 04:40:39 +0300 Subject: [PATCH 2/5] Fix test failures by updating package naming and livereload option in CLI --- .github/workflows/ci.yml | 4 ++-- mkdocs/__main__.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4a293ac..656142ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,5 +102,5 @@ jobs: run: | expected_wheel=(-emkdocs/{templates/sitemap.xml,config/base.py,py.typed,contrib/search/lunr-language/lunr.nl.js,themes/{mkdocs,readthedocs}/{base.html,locales/{de,es}/LC_MESSAGES/messages.mo}}) expected_sdist=("${expected_wheel[@]}" -e{pyproject.toml,hatch_build.py}) - test "$(tar -ztf dist/mkdocs-*.tar.gz | grep -F "${expected_sdist[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_sdist[@]}" - test "$(unzip -l dist/mkdocs-*any.whl | grep -F "${expected_wheel[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_wheel[@]}" + test "$(tar -ztf dist/mkdocs_ng-*.tar.gz | grep -F "${expected_sdist[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_sdist[@]}" + test "$(unzip -l dist/mkdocs_ng-*any.whl | grep -F "${expected_wheel[@]}" | tee /dev/stderr | wc -l)" -eq "${#expected_wheel[@]}" diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py index 394ca272..f1933e13 100644 --- a/mkdocs/__main__.py +++ b/mkdocs/__main__.py @@ -253,8 +253,7 @@ def cli(): @cli.command(name="serve") @click.option('-a', '--dev-addr', help=dev_addr_help, metavar='') @click.option('-o', '--open', 'open_in_browser', help=serve_open_help, is_flag=True) -@click.option('--livereload', 'livereload', flag_value=True, default=True, hidden=True) -@click.option('--no-livereload', 'livereload', flag_value=False, help=no_reload_help) +@click.option('--livereload/--no-livereload', default=True, help=no_reload_help) @click.option('--dirtyreload', 'build_type', flag_value='dirty', hidden=True) @click.option('--dirty', 'build_type', flag_value='dirty', help=serve_dirty_help) @click.option('-c', '--clean', 'build_type', flag_value='clean', help=serve_clean_help) From a04c4b2a47f03ba2d2ad69b5752fc3647a1293d7 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Wed, 22 Apr 2026 04:47:42 +0300 Subject: [PATCH 3/5] Fix style: apply ruff and black auto-fixes - toc.py: simplify 'if len(toc):' to 'if toc:' (PLC1802) - tests/base.py: use dict.fromkeys() instead of dict comprehension (C420) - config_options.py: reformat PathSpec.run_validation() to fit line length (black) --- mkdocs/config/config_options.py | 4 +++- mkdocs/structure/toc.py | 2 +- mkdocs/tests/base.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py index 37078b04..2d08b92e 100644 --- a/mkdocs/config/config_options.py +++ b/mkdocs/config/config_options.py @@ -1222,6 +1222,8 @@ def run_validation(self, value: object) -> pathspec.gitignore.GitIgnoreSpec: if not isinstance(value, str): raise ValidationError(f'Expected a multiline string, but a {type(value)} was given.') try: - return pathspec.gitignore.GitIgnoreSpec.from_lines(lines=textwrap.dedent(value).splitlines()) + return pathspec.gitignore.GitIgnoreSpec.from_lines( + lines=textwrap.dedent(value).splitlines() + ) except ValueError as e: raise ValidationError(str(e)) diff --git a/mkdocs/structure/toc.py b/mkdocs/structure/toc.py index e1df40be..7b4870bc 100644 --- a/mkdocs/structure/toc.py +++ b/mkdocs/structure/toc.py @@ -20,7 +20,7 @@ class _TocToken(TypedDict): def get_toc(toc_tokens: list[_TocToken]) -> TableOfContents: toc = [_parse_toc_token(i) for i in toc_tokens] # For the table of contents, always mark the first element as active - if len(toc): + if toc: toc[0].active = True # type: ignore[attr-defined] return TableOfContents(toc) diff --git a/mkdocs/tests/base.py b/mkdocs/tests/base.py index 96ca4f81..bfc250f2 100644 --- a/mkdocs/tests/base.py +++ b/mkdocs/tests/base.py @@ -66,7 +66,7 @@ def example(self, tdir): with open(pth, 'r', encoding='utf-8') as f: assert f.read() == 'bar content' """ - files = {f: '' for f in files} if isinstance(files, (list, tuple)) else files or {} + files = dict.fromkeys(files, '') if isinstance(files, (list, tuple)) else files or {} kw['prefix'] = 'mkdocs_test-' + kw.get('prefix', '') From 4b2757c6b2e0c240c81f08e3615bac0fc8d4d0c7 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Wed, 22 Apr 2026 04:51:49 +0300 Subject: [PATCH 4/5] CI: exclude pypy-3.9 on windows-latest from test matrix PyPy 3.9 on Windows fails to install hatch because hatch's zstandard dependency requires CFFI compilation which needs distutils.msvc9compiler, a module removed in newer Python versions and unavailable on PyPy 3.9 for Windows. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 656142ce..e05d243c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,10 @@ jobs: os: macos-latest - python-version: '3.11' os: windows-latest + # PyPy 3.9 on Windows fails to build zstandard (hatch dep) due to + # missing distutils.msvc9compiler in cffi on PyPy; no value in testing this combo + - python-version: 'pypy-3.9-v7.x' + os: windows-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From 6c3b19c5dda8e672bcd57b4710605f80d8f12866 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Wed, 22 Apr 2026 04:58:21 +0300 Subject: [PATCH 5/5] Update mkdocs/__main__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- mkdocs/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py index f1933e13..a2f7594c 100644 --- a/mkdocs/__main__.py +++ b/mkdocs/__main__.py @@ -253,7 +253,7 @@ def cli(): @cli.command(name="serve") @click.option('-a', '--dev-addr', help=dev_addr_help, metavar='') @click.option('-o', '--open', 'open_in_browser', help=serve_open_help, is_flag=True) -@click.option('--livereload/--no-livereload', default=True, help=no_reload_help) +@click.option('--livereload/--no-livereload', default=True, help='Enable/disable live reloading.') @click.option('--dirtyreload', 'build_type', flag_value='dirty', hidden=True) @click.option('--dirty', 'build_type', flag_value='dirty', help=serve_dirty_help) @click.option('-c', '--clean', 'build_type', flag_value='clean', help=serve_clean_help)