Fix PDM settings ignoring PDM's config layers (#609, #566) - #611
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Agent mode decided whether a PDM project uses PEP 582 (__pypackages__) from the project's pdm.toml alone, and only when use_venv was a TOML bool. PDM 2.27+ writes `use_venv = "false"`, and plain `pdm config python.use_venv false` writes the user config, so socket-patch patched an activated or stray venv instead of the copy `pdm run` imports (#609). Global mode likewise skipped PDM's site config (/etc/xdg/pdm/config.toml and the macOS/Windows equivalents), so a global project relocated there was never crawled and `get -g` could patch a different copy (#566). Settings now resolve in PDM's order: environment, project config, user config ($PDM_CONFIG_FILE or the per-user file), then the site config, with string values parsed like PDM's ensure_boolean. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
PDM reads a single user config file: the most specific per-user config dir platformdirs picks. A use_venv missing from $XDG_CONFIG_HOME/pdm/config.toml no longer falls through to ~/.config/pdm, which PDM never reads in that setup. A leading empty or relative $XDG_CONFIG_DIRS entry (e.g. from "$XDG_CONFIG_DIRS:/other" with the variable unset) no longer drops the site config layer. The first absolute entry is used, falling back to /etc/xdg. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
|
[burn-down agent] Labeled Ready for review at
Generated by Claude Code |
|
Review updated for
All 77 focused Python crawler tests and 18 native runtime controls passed. The native controls cover uv and spaced-path Homebrew PDM installations plus a HOME-based user-site platformdirs fixture under six inherited-environment scenarios; no planted code ran. Native PDM layer controls also passed with platformdirs 4.9.6 and 4.12.2. Formatting/diff checks and targeted clippy passed, with existing baseline formatting and macOS warning allowances documented in the PR. Two independent reviews found no remaining actionable issue. The committed files match the tested sources and merge cleanly with current main. Unrecognized macOS launchers or a failed runtime probe leave the implicit site layer undiscovered; explicit XDG configuration still works, and this limitation is documented. No remaining code finding from this review. The Ready label has been restored after all checks completed on the corrected commit. |
Honor XDG_CONFIG_DIRS for macOS site defaults and preserve native root/whitespace handling. Overlay legacy project settings before modern pdm.toml, while retaining environment priority and missing-key fallback. Enable site-layer tests on macOS and cover both legacy/string directions. Validation: 68 Python crawler tests passed; native PDM 2.29.2 controls with platformdirs 4.9.6 and 4.12.2. The legacy regression also passes on main and fails with the original PR lookup.
|
BugBot review Please review the corrected commit |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3226a8f. Configure here.
Final-head CI is complete: 335 successful checks, 6 skipped; no failures or pending checks. Bugbot passed, there are no unresolved review threads, and the PR is mergeable.
Fixes #609 and #566. PDM environment discovery previously missed string-valued and user/site
python.use_venvsettings, so a project configured for__pypackages__could select an activated or stray venv. Global discovery also missed site-level project, venv and interpreter locations.The crawler now resolves project settings through PDM's layers:
PDM_USE_VENV, legacy.pdm.tomloverrides overpdm.toml, the selected user config, then site config. It accepts TOML booleans and the strings PDM writes, while preserving missing-key fallback. Global discovery also reads the site layer while retaining its existing user-directory inventory.Site configuration follows the first absolute, trimmed
XDG_CONFIG_DIRSentry on Linux and macOS. Empty and relative entries are skipped, and/remains a valid root. Linux and Windows retain their platform defaults.On macOS, the implicit site directory comes from the Python runtime used by the installed PDM launcher. This distinguishes Homebrew's
<prefix>/share/pdmfrom runtimes using/Library/Application Support/pdm. A bounded probe importsplatformdirsdirectly without invoking PDM or its plugin loader. It uses a private working directory, null stdin, a five-second timeout, bounded output and child cleanup, and removes Python import/bootstrap environment overrides. Higher-priority project/user settings and explicit XDG paths bypass the probe.Unknown launchers, a missing
platformdirs, or a failed probe leave the implicit macOS site layer undiscovered. Ordinary HOME-based user-site installs are supported; installs available only through a customPYTHONUSERBASEare not discovered by this probe. These limits are documented indocs/testing/pdm-compatibility.md.Validation on
3226a8f2:unused_variableswarning allowed; three pre-existing formatting deviations were retained. The final Git objects match the tested files, two independent reviews found no remaining issue, and the commit merges cleanly with current main045d7ec7.3226a8f2.Note
Medium Risk
Changes which Python site-packages paths are selected for patching; macOS adds a subprocess probe with mitigations but still depends on launcher parsing and PATH.
Overview
Fixes PDM environment discovery so
python.use_venvand global install paths follow PDM’s real config stack instead of only projectpdm.toml/.pdm.toml.python.use_venvis now resolved in order:PDM_USE_VENV, legacy.pdm.tomloverpdm.toml, then the single user config file ($PDM_CONFIG_FILEor platformdirs’ chosenconfig.toml), then siteconfig.toml. Values match PDM 2.27+ by accepting TOML bools and string forms like"false". That fixes PEP 582 (__pypackages__) vs stray.venvwhen users setuse_venvin user or site config (#609).Global PDM paths (
global_project.path,venv.location,python.install_root) also merge in the site config layer, not just user config (#566). Site dirs use the first absolute$XDG_CONFIG_DIRSsegment (with Linux/Windows defaults); user config no longer falls through multiple candidate directories.On macOS, when XDG doesn’t pin site config, a new
pdm_sitemodule parses thepdmlauncher’s shebang, runs a boundedplatformdirsprobe in that interpreter (nopdmCLI), with timeouts, output limits, and strippedPYTHON*env vars. Higher-priority settings or explicitXDG_CONFIG_DIRSskip the probe. Docs inpdm-compatibility.mddescribe these limits.Large test additions cover precedence, string booleans, site/user/global layers, and macOS launcher/probe safety.
Reviewed by Cursor Bugbot for commit 3226a8f. Configure here.