Repository navigation
Warn when upstream mkdocs is installed alongside mkdocs-ng - #114
Closed
shenxianpeng wants to merge 1 commit into
Closed
shenxianpeng wants to merge 1 commit into
shenxianpeng wants to merge 1 commit into
Conversation
Plugins and themes depend on the 'mkdocs' distribution, so installing one also installs upstream MkDocs, which writes the same 'mkdocs/' files and makes 'pip uninstall mkdocs' delete MkDocs NG as well. The CLI, mkdocs.build() and mkdocs.serve() now log a warning (once per process, before the build, so strict mode isn't affected) when the upstream distribution is installed in the same location, with the commands to repair the environment. Document how to keep upstream MkDocs out with uv's override-dependencies or --overrides, and the pip workaround with its limitations.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Almost every plugin and theme (Material for MkDocs included) depends on the
mkdocsdistribution. MkDocs NG ships the samemkdocs/package under the namemkdocs-ng, sopip install mkdocs-ng mkdocs-materialalso installs upstream MkDocs 1.6.1. Both write the same files (169 of them overlap): whichever is installed last wins, andpip uninstall mkdocs, which the README recommended, deletes themkdocscommand and most of MkDocs NG along with it. The users affected most are the ones adopting MkDocs NG, and nothing tells them.This PR does the short-term part: detect it at runtime, and document installs that work.
Changes
Runtime warning (
mkdocs/utils/dist_conflict.py)mkdocsCLI group,mkdocs.build()andmkdocs.serve()look up themkdocsdistribution withimportlib.metadata. If its files are in the same place as the runningmkdocspackage, they log one WARNING with the upstream version, why it's a problem, and the repair command. The command isuv pip …when the upstream package'sINSTALLERis uv, otherwisepip …, plus a link to the new docs section.build()attaches its strict-mode counter, so the warning never aborts a--strictbuild. It runs once per process (functools.cache), somkdocs build(CLI + API) andserverebuilds report it once.mkdocs-nginstalled → no warning. Upstreammkdocsinstalled somewhere else (another site-packages, or this repo's ownhatch run docs:…, which puts the checkout first onPYTHONPATH) → no warning, since nothing is overwritten. A distribution whose metadata name isn'tmkdocsis ignored.__main__.py/__init__.pyare the ones running, and no check in MkDocs NG can run. The docs therefore tell users to checkmkdocs --version(1.6.x = overwritten).Docs
docs/user-guide/installation.md: new section Installing plugins and themes. It covers the uv approach ([tool.uv] override-dependencies = ["mkdocs; sys_platform == 'never'"],exclude-dependenciesfor uv ≥ 0.9.8, and--overridesforuv pip,uvxanduv tool install), the pip workaround with its limitations, CI with a pinned requirements file, and switching from upstream MkDocs.pip uninstall mkdocs && pip install -U mkdocs-nginstruction with a short callout and the working commands. The same one-liner infixed-upstream-issues.mdis updated too.Before / After
1. pip: plugin installed next to MkDocs NG
Before (
main, mkdocs-ng 1.8.0 from PyPI):After (this branch, wheel built from it):
With uv as the installer, the suggested command is
uv pip uninstall mkdocs && uv pip install --reinstall --no-deps mkdocs-ng. I ran that end to end as well.2. uv project: documented override
3. Behavior of the warning
mkdocs-ngmkdocs-ngfiles + upstreammkdocsmetadata (same site-packages)--strictmkdocsin a different locationmkdocs --versionmkdocs buildvia CLI (group +mkdocs.build()both check)How every documented command was tested
Each one ran in a fresh temporary venv (Python 3.12, macOS) against a Material +
minifysite built with--strict:override-dependenciesin a uv project:uv sync,uv run mkdocs build --strict, a lateruv add mkdocs-minify-plugin, anduv sync --lockedfrom an empty venv. The upstream package is never installed. Also checked with uv 0.4.0, 0.6.0 and 0.9.28.exclude-dependencies = ["mkdocs"]: works with uv 0.9.8 and 0.9.28. uv 0.9.7 and older warnunknown field exclude-dependenciesand install upstream anyway. That's why the docs recommendoverride-dependenciesand give the version.uv pip install -r requirements.txt --overrides overrides.txt,uvx --from mkdocs-ng --with mkdocs-material --overrides overrides.txt mkdocs build, anduv tool install mkdocs-ng --with mkdocs-material --overrides overrides.txt: no upstream package, and the strict build passes.mkdocs-ng): the three-step install, the CI variant withmkdocs-ng==1.8.0pinned inrequirements.txt, and switching from an existingmkdocs+ Material + minify environment. The limitations listed in the docs were reproduced:pip checkreportsmkdocs-material 9.7.7 requires mkdocs, which is not installed., and a laterpip install mkdocs-redirectsbrings upstream 1.6.1 back.hatch run docs:mkdocs build --strict. The new anchors (#installing-plugins-and-themes,#with-uv-recommended,#with-pip,#switching-from-upstream-mkdocs) match the links and the URL in the warning.mkdocs/tests/utils/dist_conflict_tests.py. They use real*.dist-infodirectories on a patchedsys.path, soimportlib.metadataname matching (mkdocsvsmkdocs_ng) is exercised for real. They cover: only NG, upstream at the same or another location, the name guard, the pip/uv/no-INSTALLERcommands, once per process,mkdocs.build()withstrict: true,mkdocs.serve(), andmkdocs build --strictthrough the CLI warning once with exit 0. Full suite: 918 tests OK on Python 3.10 and 3.14.uvx prek run -apasses.Research: should MkDocs NG move to its own import name, like ProperDocs?
I installed
properdocs1.6.7 and read how it works:properdocs/package and aproperdocscommand. It doesn't depend onmkdocs, but plugins still do, so upstreammkdocs1.6.1 is still installed next to it. The two just no longer share files.properdocs/replacement.py, imported by its CLI, inserts asys.meta_pathfinder that maps everymkdocs.*import toproperdocs.*and setssys.modules['mkdocs'] = properdocs. Checked: inside the process, Material'sBasePluginisproperdocs.plugins.BasePlugin. A plainpython -c "import mkdocs"still gets upstream 1.6.1.mkdocs.themes/mkdocs.pluginsandproperdocs.*entry point groups, skipping entries from themkdocsdistribution. It looks forproperdocs.ymlfirst, thenmkdocs.yml.Pros
pip uninstall mkdocsis harmless. No installer tricks needed.mkdocs2.0. PyPI already has2.0.dev2…2.0.dev6. Once a final release is out, plugins whosemkdocsrequirement has no upper bound will pull 2.0, which isn't compatible, over MkDocs NG's files. That's the strongest argument for a rename.Cons
mkdocs. The console script is a file too (bin/mkdocs), and upstream would still be installed for the plugins, so keeping the name brings the same last-writer-wins conflict back. A real fix needs a new command (mkdocs-ng build), and every CI script, Makefile,gh-deploydoc and tutorial has to change. That breaks the "drop-in, nothing changes" promise in the README.import mkdocs; mkdocs.build()outside our CLI gets upstream (or nothing). The only way to alias at interpreter start is a.pthfile, which runs in every Python process in the environment. That's widely disliked, and fragile.mkdocs. If something imports it first (a.pth, a test runner, a plugin's own tooling), there are twoConfig/BasePluginhierarchies, and theisinstancefailures are hard to debug.mkdocs.plugins.<name>(directly, or viaget_plugin_logger). Strict-mode counting and CLI output would have to cover both themkdocsand the new logger trees. I didn't check how ProperDocs handles loggers that plugins name directly.importlib.metadata.version("mkdocs")keeps returning the upstream version (1.6.1), so tools that check the installed distribution see the wrong thing. Upstream's dependencies (e.g.mergedeep) stay installed as dead weight.Effort estimate (rough): mechanical rename of the package plus ~120 internal import/logger references and ~530 test references, about 1 day. Alias finder, dual entry-point groups that ignore the upstream distribution's built-ins, logger bridging, strict-mode tests, about 2–3 days. New command name, deprecation path for the
mkdocscommand, migration docs, about 1–2 days. Compatibility runs against popular plugins (Material, mkdocstrings, awesome-nav, redirects, minify, macros…), about 2 days. Total ≈ 1–1.5 weeks, plus ongoing support for alias edge cases.Recommendation: not now. With this PR, users have a warning plus installs that work (uv override is clean, pip is workable), and the drop-in promise holds. Revisit when upstream publishes a non-pre-release
mkdocs2.0 on PyPI. At that point, a pip-only user's next plugin install could replace MkDocs NG with an incompatible release, and an own import name + compatibility layer becomes worth its cost. Until then, a cheaper follow-up is asking major plugins to add an upper bound (mkdocs<2), which limits the damage either way.