A simple pyproject.toml can cause pdm add to fail with:
[NonExistentKey]: 'Key "pdm" does not exist.'
To reproduce
Run pdm init, then replace the contents of pyproject.toml with:
[project]
name = "pdmtest"
version = "0.1.0"
description = "Default template for PDM package"
authors = []
dependencies = []
requires-python = "==3.12.*"
readme = "README.md"
license = {text = "MIT"}
[tool.pdm.scripts]
[tool.pdm]
distribution = false
[dependency-groups]
[tool.ruff]
Then run pdm add -e . --dev.
Expected Behavior
INFO: Adding group dev to lockfile
Adding packages to dev dev-dependencies: -e file:///${PROJECT_ROOT}/#egg=pdmtest
/ 0:00:00 Resolve for environment (==3.12.*) None
...
What actually happens is:
INFO: Adding group dev to lockfile
Adding packages to dev dev-dependencies: -e file:///${PROJECT_ROOT}/#egg=pdmtest
[NonExistentKey]: 'Key "pdm" does not exist.'
WARNING: Add '-v' to see the detailed traceback
Making random changes to pyproject.toml, such as reordering sections or removing the [tool.ruff] section, makes it work.
Usage: pdm [-h] [-V] [-c CONFIG] [-v | -q] [--no-cache] [-I] [--pep582 [SHELL]] [-n] ...
____ ____ __ ___
/ __ \/ __ \/ |/ /
/ /_/ / / / / /|_/ /
/ ____/ /_/ / / / /
/_/ /_____/_/ /_/
Options:
-h, --help Show this help message and exit.
-V, --version Show the version and exit
-c CONFIG, --config CONFIG
Specify another config file path [env var: PDM_CONFIG_FILE]
-v, --verbose Use `-v` for detailed output and `-vv` for more detailed
-q, --quiet Suppress output
--no-cache Disable the cache for the current command. [env var: PDM_NO_CACHE]
-I, --ignore-python Ignore the Python path saved in .pdm-python. [env var: PDM_IGNORE_SAVED_PYTHON]
--pep582 [SHELL] Print the command line to be eval'd by the shell for PEP 582
-n, --non-interactive
Don't show interactive prompts but use defaults. [env var: PDM_NON_INTERACTIVE]
Commands:
add Add package(s) to pyproject.toml and install them
build Build artifacts for distribution
cache Control the caches of PDM
completion Generate completion scripts for the given shell
config Display the current configuration
export Export the locked packages set to other formats
fix Fix the project problems according to the latest version of PDM
import Import project metadata from other formats
info Show the project information
init Initialize a pyproject.toml for PDM. Built-in templates: - default: `pdm init`, A simple template with
a basic structure. - minimal: `pdm init minimal`, A minimal template with only `pyproject.toml`.
install Install dependencies from lock file
list List packages installed in the current working set
lock Resolve and lock dependencies
outdated Check for outdated packages and list the latest versions on indexes.
publish Build and publish the project to PyPI
python (py) Manage installed Python interpreters
remove Remove packages from pyproject.toml
run Run commands or scripts with local packages loaded
search Search for PyPI packages
self (plugin) Manage the PDM program itself (previously known as plugin)
show Show the package information
sync Synchronize the current working set with lock file
update Update package(s) in pyproject.toml
use Use the given python version or path as base interpreter. If not found, PDM will try to install one.
venv Virtualenv management
Adding an empty [tool.pdm] entry appears to fix it (have no idea why). Presumably something in those keys triggers a codepath which then looks for that key.
Describe the bug
A simple
pyproject.toml
can causepdm add
to fail with:To reproduce
Run
pdm init
, then replace the contents ofpyproject.toml
with:Then run
pdm add -e . --dev
.Expected Behavior
What actually happens is:
Making random changes to
pyproject.toml
, such as reordering sections or removing the[tool.ruff]
section, makes it work.Environment Information
PDM version: 2.20.1 Python Interpreter: C:\Users...\Documents\pdmtest.venv\Scripts\python.exe (3.12) Project Root: C:/Users/.../Documents/pdmtest Local Packages:
{ "implementation_name": "cpython", "implementation_version": "3.12.3", "os_name": "nt", "platform_machine": "AMD64", "platform_release": "10", "platform_system": "Windows", "platform_version": "10.0.19045", "python_full_version": "3.12.3", "platform_python_implementation": "CPython", "python_version": "3.12", "sys_platform": "win32" }
pdm -v output
Additional Context
No response
Are you willing to submit a PR to fix this bug?