### Installing PDM via Scoop (Windows) Source: https://github.com/pdm-project/pdm/blob/main/README.md On Windows, PDM can be installed using the Scoop command-line installer. This requires adding the 'frostming' bucket first, then installing PDM from it. ```cli scoop bucket add frostming https://github.com/frostming/scoop-frostming.git scoop install pdm ``` -------------------------------- ### Installing PDM via asdf-vm Source: https://github.com/pdm-project/pdm/blob/main/README.md This set of commands installs PDM using `asdf-vm`, a version manager. First, it adds the PDM plugin, then installs the latest available version of PDM through `asdf`. ```bash asdf plugin add pdm asdf install pdm latest ``` -------------------------------- ### Installing PDM via Script (Linux/Mac) Source: https://github.com/pdm-project/pdm/blob/main/README.md This command installs PDM on Linux and macOS by downloading and executing the official installation script using `curl` and `python3`. It sets up PDM in an isolated environment. ```bash curl -sSL https://pdm-project.org/install-pdm.py | python3 - ``` -------------------------------- ### Creating a New PDM Project Source: https://github.com/pdm-project/pdm/blob/main/README.md This command initializes a new PDM project in a specified directory (e.g., 'my-project'). It guides the user through setting up the project and creates a `pyproject.toml` file. ```bash pdm new my-project ``` -------------------------------- ### PDM Installation Script Command-Line Options Source: https://github.com/pdm-project/pdm/blob/main/README.md This snippet details the command-line arguments and environment variables available for the PDM installation script. Options include specifying the PDM version, allowing prereleases, removing an installation, and defining custom installation paths or additional dependencies. ```cli usage: install-pdm.py [-h] [-v VERSION] [--prerelease] [--remove] [-p PATH] [-d DEP] optional arguments: -h, --help show this help message and exit -v VERSION, --version VERSION | envvar: PDM_VERSION Specify the version to be installed, or HEAD to install from the main branch --prerelease | envvar: PDM_PRERELEASE Allow prereleases to be installed --remove | envvar: PDM_REMOVE Remove the PDM installation -p PATH, --path PATH | envvar: PDM_HOME Specify the location to install PDM -d DEP, --dep DEP | envvar: PDM_DEPS Specify additional dependencies, can be given multiple times ``` -------------------------------- ### Installing PDM via Script (Windows) Source: https://github.com/pdm-project/pdm/blob/main/README.md This PowerShell command installs PDM on Windows by downloading and executing the official installation script. The `-ExecutionPolicy ByPass` allows script execution, and `irm` (Invoke-RestMethod) downloads the script. ```powershell powershell -ExecutionPolicy ByPass -c "irm https://pdm-project.org/install-pdm.py | py -" ``` -------------------------------- ### Installing PDM Project Dependencies Source: https://github.com/pdm-project/pdm/blob/main/README.md This command adds and installs specified dependencies (e.g., 'requests', 'flask') to the current PDM project. PDM automatically resolves and locks these dependencies in the `pdm.lock` file. ```bash pdm add requests flask ``` -------------------------------- ### Installing PDM via pipx Source: https://github.com/pdm-project/pdm/blob/main/README.md This command installs PDM using `pipx`, which is recommended for installing Python applications in isolated environments. This prevents dependency conflicts with other Python projects. ```bash pipx install pdm ``` -------------------------------- ### Installing PDM via pip (User Site) Source: https://github.com/pdm-project/pdm/blob/main/README.md This command installs PDM directly into the user's Python site-packages directory using `pip` with the `--user` flag. This is a common method for installing packages without root privileges. ```bash pip install --user pdm ``` -------------------------------- ### Installing PDM via Homebrew (macOS) Source: https://github.com/pdm-project/pdm/blob/main/README.md For macOS users, PDM can be conveniently installed using the Homebrew package manager. This command adds PDM to your system via Homebrew's package repository. ```bash brew install pdm ``` -------------------------------- ### PDM Project Badge Markdown Source: https://github.com/pdm-project/pdm/blob/main/README.md This Markdown snippet provides the code to embed a 'pdm-managed' badge into a `README.md` file. The badge links to the PDM project website, indicating that the repository uses PDM for dependency management. ```markdown [![pdm-managed](https://img.shields.io/endpoint?url=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2Fpdm-project%2F.github%2Fbadge.json)](https://pdm-project.org) ``` -------------------------------- ### Installing Documentation Dependencies (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to install 'libffi-dev' using 'sudo apt install'. This is a system-level dependency required for building PDM's documentation on Debian/Ubuntu-based systems. ```bash sudo apt install libffi-dev ``` -------------------------------- ### Listing Installed Python Interpreters with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command displays a list of all Python interpreters that have been installed and are managed by PDM. It helps users keep track of available Python versions. ```bash pdm python list ``` -------------------------------- ### Configuring PDM Python Installation Root to Share with Rye (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command configures PDM to use the same Python installation root directory as Rye, allowing both tools to share and manage the same set of installed Python interpreters. This avoids redundant installations. ```bash pdm config python.install_root ~/.rye/py ``` -------------------------------- ### Installing pre-commit with pipx (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to install the 'pre-commit' tool using 'pipx', which installs Python applications in isolated environments. This is an alternative to direct pip installation. ```bash pipx install pre-commit ``` -------------------------------- ### Installing PDM on Windows Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md This PowerShell command downloads the PDM installation script using `Invoke-RestMethod` (`irm`) and executes it with the `py` launcher. It bypasses the execution policy to allow script execution, providing the recommended installation method for Windows. ```powershell powershell -ExecutionPolicy ByPass -c "irm https://pdm-project.org/install-pdm.py | py -" ``` -------------------------------- ### Adding Version Control System Dependencies with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md Illustrates various ways to add dependencies directly from Git repositories using `pdm add`. Examples include specifying a tag, providing credentials in the URL, assigning a custom name, using the `#egg` fragment, and installing from a subdirectory within the repository. ```bash pdm add "git+https://github.com/pypa/pip.git@22.0" pdm add "git+https://username:password@github.com/username/private-repo.git@master" pdm add "pip @ git+https://github.com/pypa/pip.git@22.0" pdm add "git+https://github.com/pypa/pip.git@22.0#egg=pip" pdm add "git+https://github.com/owner/repo.git@master#egg=pkg&subdirectory=subpackage" ``` -------------------------------- ### Installing PDM on Linux/Mac Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md This command downloads and executes the PDM installation script directly from the project's website using `curl` and pipes it to `python3`. This is the recommended method for installing PDM on Unix-like systems. ```bash curl -sSL https://pdm-project.org/install-pdm.py | python3 - ``` -------------------------------- ### Installing PDM with Scoop (PowerShell) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Adds the 'frostming' bucket to Scoop, a command-line installer for Windows, and then proceeds to install PDM. This method ensures PDM is managed through the Scoop ecosystem. ```powershell scoop bucket add frostming https://github.com/frostming/scoop-frostming.git ``` ```powershell scoop install pdm ``` -------------------------------- ### Installing Production and Specific Optional Dependencies with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs production dependencies along with the specified 'extra1' optional group. It allows for a production-like installation while including specific optional features. ```bash pdm install --prod -G extra1 ``` -------------------------------- ### Verifying PDM Installer Checksum and Running on Linux/Mac Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md This sequence of commands first downloads the PDM installation script and its SHA256 checksum file. It then verifies the integrity of the downloaded script against its checksum using `shasum`. Finally, it demonstrates how to execute the installer script with optional arguments. ```bash curl -sSLO https://pdm-project.org/install-pdm.py curl -sSL https://pdm-project.org/install-pdm.py.sha256 | shasum -a 256 -c - # Run the installer python3 install-pdm.py [options] ``` -------------------------------- ### Installing Minimum Required Python Interpreter with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command instructs PDM to install the minimum Python interpreter version that satisfies the `requires-python` specification in `pyproject.toml`. If `requires-python` is not specified, it considers all installable interpreters. ```bash pdm python install --min ``` -------------------------------- ### Installing a Specific Python Interpreter with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command uses PDM to install a specific Python interpreter version (e.g., CPython 3.9.8) from `indygreg's python-build-standalone`. The interpreter will be installed into the location configured by `python.install_root`. ```bash pdm python install 3.9.8 ``` -------------------------------- ### Installing All Optional Dependency Groups with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs production dependencies, all development dependencies, and all defined optional groups (e.g., 'extra1', 'extra2'). The '-G:all' flag ensures a complete installation including all optional components. ```bash pdm install -G:all ``` -------------------------------- ### Installing a Free-Threaded Python Interpreter with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command installs a specific free-threaded Python interpreter version (e.g., 3.13t) using PDM. Free-threaded interpreters are optimized for concurrency. ```bash pdm python install 3.13t ``` -------------------------------- ### Installing tox-pdm via PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This command installs the `tox-pdm` plugin using PDM's `add` command, adding it as a development dependency to the current project. This is an alternative to `pip install` for managing the plugin. ```Bash pdm add --dev tox-pdm ``` -------------------------------- ### PDM Installer Command-Line Options Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md This snippet displays the command-line usage and available options for the `install-pdm.py` script. It details arguments for specifying the PDM version, allowing prereleases, removing an installation, custom installation paths, and adding extra dependencies, many of which can also be set via environment variables. ```bash usage: install-pdm.py [-h] [-v VERSION] [--prerelease] [--remove] [-p PATH] [-d DEP] optional arguments: -h, --help show this help message and exit -v VERSION, --version VERSION | envvar: PDM_VERSION Specify the version to be installed, or HEAD to install from the main branch --prerelease | envvar: PDM_PRERELEASE Allow prereleases to be installed --remove | envvar: PDM_REMOVE Remove the PDM installation -p PATH, --path PATH | envvar: PDM_HOME Specify the location to install PDM -d DEP, --dep DEP | envvar: PDM_DEPS Specify additional dependencies, can be given multiple times ``` -------------------------------- ### Flowchart for PDM Installation (pdm install) in Mermaid Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/hooks.md This Mermaid flowchart details the `pdm install` command's workflow, which orchestrates `pdm lock` and `pdm sync`. It shows the `pre_lock`, `post_lock`, `pre_install`, and `post_install` signals emitted at various stages of the locking and synchronization processes. ```Mermaid flowchart LR subgraph pdm-install [pdm install] direction LR subgraph pdm-lock [pdm lock] direction TB pre-lock{{Emit pre_lock}} post-lock{{Emit post_lock}} pre-lock --> lock --> post-lock end subgraph pdm-sync [pdm sync] direction TB pre-install{{Emit pre_install}} post-install{{Emit post_install}} pre-install --> sync --> post-install end pdm-lock --> pdm-sync end ``` -------------------------------- ### Installing Python Dependencies with PDM Run Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/venv.md This command uses PDM to execute a Python `pip install` command, installing the `coverage` package. It's noted that dependencies installed this way are not checked for conflicts against the lockfile. This method is suitable for direct package installation within the PDM project context. ```bash pdm run python -m pip install coverage ``` -------------------------------- ### Creating a New PDM Project (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command initializes a new PDM project in a directory named `my-project`. It prompts the user for information to generate a `pyproject.toml` file, setting up the project's metadata and dependencies. ```bash pdm new my-project ``` -------------------------------- ### Installing PDM with uv (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs PDM using the `uv` tool, a fast Python package installer and resolver. This command leverages `uv`'s capability to manage and install Python tools. ```bash uv tool install pdm ``` -------------------------------- ### Initializing pyproject.toml for an Existing PDM Project (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This sequence of commands navigates into an existing project directory and then initializes a `pyproject.toml` file within it using `pdm init`. This is used when a project already exists but lacks PDM's configuration file. ```bash cd my-project pdm init ``` -------------------------------- ### Using an Activated PDM Plugin Command (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This bash command demonstrates the execution of a newly activated PDM plugin's command. After installing `pdm-hello`, the `hello` subcommand becomes available, allowing users to interact with the plugin's functionality directly via the PDM CLI. ```bash $ pdm hello Jack ``` -------------------------------- ### Defining Project Dependencies (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This TOML example demonstrates how to specify various types of project dependencies within the `project.dependencies` array, adhering to PEP 440 and PEP 508. It includes examples for named requirements, version specifiers, environment markers, and URL-based requirements. ```TOML [project] ... dependencies = [ # Named requirement "requests", # Named requirement with version specifier "flask >= 1.1.0", # Requirement with environment marker "pywin32; sys_platform == 'win32'", # URL requirement "pip @ git+https://github.com/pypa/pip.git@20.3.1" ] ``` -------------------------------- ### Initializing pre-commit Hooks (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to install 'pre-commit' hooks into the Git repository. Once installed, these hooks automatically run checks (like linting) before each commit. ```bash pre-commit install ``` -------------------------------- ### Defining Optional Dependencies (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This TOML snippet illustrates how to define groups of optional dependencies under `project.optional-dependencies`, similar to `setuptools`' `extras_require`. This allows users to install specific sets of dependencies only when needed, such as for testing or specific features. ```TOML [project.optional-dependencies] socks = [ 'PySocks >= 1.5.6, != 1.5.7, < 2' ] tests = [ 'ddt >= 1.2.2, < 2', 'pytest < 6', 'mock >= 1.0.1, < 4; python_version < "3.4"', ] ``` -------------------------------- ### Adding Standard Python Dependencies with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md Demonstrates how to add Python package dependencies using `pdm add`. Examples include adding a package, specifying a version constraint, including extra dependencies, and adding multiple packages with different specifiers. This command resolves and installs dependencies. ```bash pdm add requests # add requests pdm add requests==2.25.1 # add requests with version constraint pdm add requests[socks] # add requests with extra dependency pdm add "flask>=1.0" flask-sqlalchemy # add multiple dependencies with different specifiers ``` -------------------------------- ### Installing PDM with pip (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs PDM for the current user using pip, Python's standard package installer. The `--user` flag ensures that PDM is installed in the user's home directory, avoiding system-wide modifications. ```bash pip install --user pdm ``` -------------------------------- ### Testing Python Projects with PDM in GitHub Actions Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This YAML snippet demonstrates a GitHub Actions workflow for testing Python projects using PDM. It sets up PDM across multiple Python versions and operating systems, installs project dependencies, and runs tests, ensuring compatibility and proper setup for CI. ```YAML Testing: runs-on: ${{ matrix.os }} strategy: matrix: python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] os: [ubuntu-latest, macOS-latest, windows-latest] steps: - uses: actions/checkout@v4 - name: Set up PDM uses: pdm-project/setup-pdm@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pdm sync -d -G testing - name: Run Tests run: | pdm run -v pytest tests ``` -------------------------------- ### Configuring PDM Scripts with {pdm} Placeholder Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/scripts.md Explains how to use the `{pdm}` placeholder in PDM scripts to ensure the correct PDM entrypoint is used, especially in environments with multiple PDM installations or custom names. It expands to `{sys.executable} -m pdm`. ```TOML [tool.pdm.scripts] whoami = { shell = "echo `{pdm} -V` was called as '{pdm} -V'" } ``` -------------------------------- ### Installing PDM Project Plugins (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This bash command instructs PDM to install all plugins specified in the project's `pyproject.toml` file. It ensures that both declared and editable plugins are available within the project's plugin library. ```bash pdm install --plugins ``` -------------------------------- ### Installing PDM with pipx (All Features) (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs PDM with all its optional features and dependencies using pipx. This ensures a full-featured PDM installation, providing access to all available functionalities. ```bash pipx install pdm[all] ``` -------------------------------- ### Installing pre-commit with pip (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to install the 'pre-commit' tool using Python's package installer, pip. Pre-commit is used for linting and enforcing code style. ```bash python -m pip install pre-commit ``` -------------------------------- ### Enabling uv as Resolver and Installer in PDM (Shell) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/uv.md This command configures PDM to use 'uv' as its experimental resolver and installer. It requires 'uv' to be pre-installed on the system for PDM to detect and utilize it, leveraging 'uv' for improved performance. ```Shell pdm config use_uv true ``` -------------------------------- ### Installing All Locked Dependency Groups with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs all dependency groups that are currently locked in the 'pdm.lock' file. It's the default behavior for 'pdm install' when no specific groups are provided. ```bash pdm install ``` -------------------------------- ### Initializing PDM Project with External Generators Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/template.md This snippet demonstrates how to initialize a PDM project using external project generators like Cookiecutter and Copier. It shows the `pdm init` command with the `--cookiecutter` and `--copier` options, specifying the template source. Users must install `cookiecutter` and `copier` separately via `pdm self add ` before using these options. ```bash pdm init --cookiecutter gh:cjolowicz/cookiecutter-hypermodern-python # or pdm init --copier gh:pawamoy/copier-pdm --UNSAFE ``` -------------------------------- ### Installing tox-pdm via pip Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This command installs the `tox-pdm` plugin using `pip`. This plugin simplifies the integration of PDM with Tox, reducing the complexity of `tox.ini` configurations. ```Bash pip install tox-pdm ``` -------------------------------- ### Default PDM Virtualenv Prompt Example Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/venv.md This snippet demonstrates the default virtual environment prompt format, showing `{project_name}-{python_version}` after activating a PDM virtual environment. In this example, the project is 'test-project' and Python version is '3.10'. ```bash $ eval $(pdm venv activate for-test) (test-project-3.10) $ # {project_name} == test-project and {python_version} == 3.10 ``` -------------------------------- ### Installing Truststore for System CA Certificates in PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md Explains how to install the truststore package into PDM's environment. This enables PDM to use the system's trust store for verifying HTTPS certificates, which is useful for corporate proxies and avoids manual CA bundle configuration. Requires Python 3.10+. ```bash pdm self add truststore ``` -------------------------------- ### Installing PDM with pipx (Standard) (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs PDM into an isolated environment using pipx, which ensures Python applications are installed in their own virtual environments to avoid dependency conflicts. This is the standard way to install PDM via pipx. ```bash pipx install pdm ``` -------------------------------- ### Defining User Script Shortcut in pyproject.toml (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/scripts.md This TOML snippet demonstrates how to define a custom script shortcut, `start`, within the `[tool.pdm.scripts]` section of `pyproject.toml`. This allows users to run complex commands like `flask run -p 54321` with a simple `pdm run start`. ```toml [tool.pdm.scripts] start = "flask run -p 54321" ``` -------------------------------- ### Installing PDM with asdf (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Adds the PDM plugin to asdf, a version manager, then installs the latest PDM version, and finally sets it as the local default. This requires asdf to be pre-installed on the system. ```bash asdf plugin add pdm asdf install pdm latest asdf local pdm latest ``` -------------------------------- ### Adding Direct URL Dependencies with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md Demonstrates how to add packages directly from a web address using `pdm add`. This supports installing gzipped tarballs or wheel files by providing their direct HTTP/HTTPS URLs, allowing installation of packages not available in standard repositories. ```bash pdm add "https://github.com/numpy/numpy/releases/download/v1.20.0/numpy-1.20.0.tar.gz" pdm add "https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.5.0/en_core_web_trf-3.5.0-py3-none-any.whl" ``` -------------------------------- ### Illustrating {pdm} Placeholder Interpolation in Shell Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/scripts.md Demonstrates the runtime expansion of the `{pdm}` placeholder, showing how it resolves to the specific PDM executable path and version. This ensures script robustness across different PDM installations. ```Shell $ pdm whoami PDM, version 0.1.dev2501+g73651b7.d20231115 was called as /usr/bin/python3 -m pdm -V $ pdm2.8 whoami PDM, version 2.8.0 was called as /venvs/pdm2-8/bin/python -m pdm -V ``` -------------------------------- ### Installing Specific Optional Dependency Group with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs production dependencies, development dependencies, and the specified 'extra1' optional group. It's useful for installing only the necessary optional components for a specific environment or feature. ```bash pdm install -G extra1 ``` -------------------------------- ### Installing PDM with pipx (Head Version) (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs the latest development version of PDM directly from the 'main' branch of its GitHub repository using pipx. This method is suitable for users who want to test the most recent features and requires Git LFS to be installed on the system. ```bash pipx install git+https://github.com/pdm-project/pdm.git@main#egg=pdm ``` -------------------------------- ### Installing Multiple Specific Dependency Groups with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs production dependencies, the 'extra1' optional group, and the 'dev1' development group. Multiple '-G' flags can be used to combine specific optional and development groups for installation. ```bash pdm install -G extra1 -G dev1 ``` -------------------------------- ### Installing PDM with Homebrew (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Installs PDM using the Homebrew package manager, a popular choice for macOS and Linux. This command fetches and installs the latest stable version of PDM available through Homebrew. ```bash brew install pdm ``` -------------------------------- ### Displaying PDM Project and Environment Information (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command displays detailed information about the current PDM project and its associated Python environment. It shows the PDM version, Python interpreter path, project root, and package location. Using the --env flag provides a JSON output of the environment's system and Python implementation details, useful for checking the project's operational mode (virtualenv or PEP 582). ```bash $ pdm info PDM version: 2.0.0 Python Interpreter: /opt/homebrew/opt/python@3.9/bin/python3.9 (3.9) Project Root: /Users/fming/wkspace/github/test-pdm Project Packages: /Users/fming/wkspace/github/test-pdm/__pypackages__/3.9 # Show environment info $ pdm info --env { "implementation_name": "cpython", "implementation_version": "3.9.0", "os_name": "nt", "platform_machine": "AMD64", "platform_release": "10", "platform_system": "Windows", "platform_version": "10.0.18362", "python_full_version": "3.9.0", "platform_python_implementation": "CPython", "python_version": "3.9", "sys_platform": "win32" } ``` -------------------------------- ### Setuptools Entry Points for Console Scripts (Python) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This Python dictionary demonstrates the `setuptools` format for defining console scripts via `entry_points`. It shows how a `pyproject.toml` definition like `mycli = "mycli.__main__:main"` is translated into a `console_scripts` list, allowing the `mycli` command to be executed from the system's command line. ```python entry_points = { 'console_scripts': [ 'mycli=mycli.__main__:main' ] } ``` -------------------------------- ### Creating PDM Virtual Environments with Specific Python Versions and Backends Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/venv.md These commands demonstrate how to manually create virtual environments using PDM. You can specify a Python version (e.g., `3.9`, `3.10`), assign a custom name using `--name`, and choose a backend (`virtualenv`, `venv`, or `conda`) with `--with`. This allows for flexible environment setup tailored to project needs. ```Bash # Create a virtualenv based on 3.9 interpreter pdm venv create 3.9 # Assign a different name other than the version string pdm venv create --name for-test 3.9 # Use venv as the backend to create, support 3 backends: virtualenv(default), venv, conda pdm venv create --with venv 3.10 ``` -------------------------------- ### Installing Pyright as a Development Dependency with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/pep582.md This Bash command uses PDM to install `pyright` as a development dependency. The `--dev` flag indicates it's a development tool, and `--group devel` places it within the 'devel' dependency group, making it available for linting and type checking within the PDM project. ```bash pdm add --dev --group devel pyright ``` -------------------------------- ### Configuring setuptools for PDM Build System (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/build.md This snippet illustrates the `pyproject.toml` configuration for using `setuptools` as the build backend with PDM. It includes `setuptools` and `wheel` in the build requirements and sets `setuptools.build_meta` as the build backend, leveraging the widely used setuptools ecosystem. ```TOML [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" ``` -------------------------------- ### Listing All Installed PDM Packages (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md Lists all packages currently installed in the PDM project's packages directory, similar to `pip list`. ```bash pdm list ``` -------------------------------- ### Installing Production Dependencies Only with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs only the production dependencies defined in the 'pyproject.toml' file, excluding all development and optional groups. The '--prod' flag is essential for deploying applications to production environments. ```bash pdm install --prod ``` -------------------------------- ### Simplified Tox Configuration with tox-pdm Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This `tox.ini` demonstrates a tidier configuration when the `tox-pdm` plugin is installed. It leverages PDM's group feature to manage dependencies, simplifying the `deps` and `commands` sections for test and lint environments. ```INI [tox] env_list = py{36,37,38},lint [testenv] groups = dev commands = pytest tests [testenv:lint] groups = lint commands = flake8 src/ ``` -------------------------------- ### Defining PDM Plugin Entry Point with Setuptools (Python) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This Python snippet demonstrates how to define a PDM plugin entry point using `setuptools` in `setup.py`. It registers a plugin named 'hello' that points to the `hello_plugin` callable within the `my_plugin` module, enabling PDM to discover and load it. ```python # setup.py setup( ... entry_points={"pdm": ["hello = my_plugin:hello_plugin"]} ... ) ``` -------------------------------- ### Configuring hatchling for PDM Build System (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/build.md This snippet details the `pyproject.toml` setup for using `hatchling` as the build backend with PDM. It specifies `hatchling` as a build requirement and `hatchling.build` as the build backend, enabling the use of Hatch's modern build system. ```TOML [build-system] requires = ["hatchling"] build-backend = "hatchling.build" ``` -------------------------------- ### Installing Optional Dependency Group (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This bash command shows how to install a specific group of optional dependencies defined in `pyproject.toml` using PDM. The `-G` option specifies the group name, and it can be used multiple times to include more than one group. ```Bash pdm install -G socks ``` -------------------------------- ### Installing PDM Development Dependencies (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to install all necessary development dependencies for the PDM project into the chosen Python environment. This ensures all tools and libraries required for development are available. ```bash pdm install ``` -------------------------------- ### Installing Dependencies Using a Specific PDM Lock File Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/lock-targets.md This Bash command instructs PDM to install dependencies using a previously generated, environment-specific lock file (`py38-linux.lock`). The `--lockfile` option ensures that the exact dependency versions and resolutions defined in that specific lock file are used for the installation, ensuring consistency across environments. ```Bash pdm install --lockfile=py38-linux.lock ``` -------------------------------- ### Adding a Published PDM Plugin (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This bash command uses `pdm self add` to install a published PDM plugin, `pdm-hello`, into the PDM's self-managed environment. This makes the plugin globally available for all PDM projects on the system. ```bash pdm self add pdm-hello ``` -------------------------------- ### Configuring Editable Plugin Installation in PDM (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This TOML snippet configures PDM to install a plugin in editable mode by specifying its path in the `tool.pdm.plugins` array within `pyproject.toml`. This allows immediate reflection of code changes without re-installation, facilitating rapid development and testing. ```toml [tool.pdm] plugins = [ "-e file:///${PROJECT_ROOT}" ] ``` -------------------------------- ### Specifying Project-Level PDM Plugins (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This TOML snippet configures `pyproject.toml` to declare `pdm-packer` as a required plugin for the current project. When `pdm install --plugins` is run, this plugin will be installed into the project's local plugin library, ensuring consistent plugin availability for all contributors. ```toml # pyproject.toml [tool.pdm] plugins = [ "pdm-packer" ] ``` -------------------------------- ### Removing a Specific Python Interpreter with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/project.md This command uninstalls a previously installed Python interpreter of a specified version (e.g., 3.9.8) from the PDM-managed installation root. ```bash pdm python remove 3.9.8 ``` -------------------------------- ### Adding Local Package Dependencies with PDM (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md Shows how to add local packages, either a directory or a wheel file, as dependencies using `pdm add`. Paths must start with `./` to be recognized as local. These dependencies are written to `pyproject.toml` with a `file://` URL format. ```bash pdm add ./sub-package pdm add ./first-1.0.0-py2.py3-none-any.whl ``` -------------------------------- ### Defining Console Scripts in pyproject.toml for PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This TOML snippet defines a console script named `mycli` within the `[project.scripts]` section of `pyproject.toml`. It maps the script name to the entry point `mycli.__main__:main`, which PDM translates into a `setuptools`-compatible `console_scripts` entry point for executable command-line applications. ```toml [project.scripts] mycli = "mycli.__main__:main" ``` -------------------------------- ### Enabling Keyring for PDM Password Management - Bash Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md This command adds the `keyring` package to PDM's isolated environment, enabling secure password storage and retrieval for indexes and repositories. It's an alternative to a global keyring installation. ```bash pdm self add keyring ``` -------------------------------- ### Executing User-Defined Script Shortcut (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/scripts.md This Bash command shows how to invoke a user-defined script, `start`, configured in `pyproject.toml` using `pdm run`. PDM executes the associated command (`flask run -p 54321`) within the project's environment. ```bash $ pdm run start ``` -------------------------------- ### Configuring PDM Binary Preferences via Environment Variables (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/lockfile.md This snippet demonstrates how to control PDM's preference for binary distributions during installation using environment variables. `PDM_NO_BINARY=:all:` prevents all binary installations, while `PDM_PREFER_BINARY=flask` prioritizes binary distributions for the 'flask' package. ```bash # No binaries will be used for installation PDM_NO_BINARY=:all: pdm install # Prefer binary distributions and even if sdist with higher version is available PDM_PREFER_BINARY=flask pdm install ``` -------------------------------- ### Configuring PDM Shell Completion (Zsh - Standard) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Generates and installs the PDM shell completion script for Zsh. It requires `~/.zfunc` to be added to `fpath` before `compinit` in the Zsh configuration for the completion to load correctly. ```bash # Make sure ~/.zfunc is added to fpath, before compinit. pdm completion zsh > ~/.zfunc/_pdm ``` -------------------------------- ### Configuring Pyright Extra Paths for Emacs LSP Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/pep582.md This `pyproject.toml` configuration, identical to the Neovim setup, adds the PDM `__pypackages__` directory to Pyright's `extraPaths`. This allows Emacs LSP clients to correctly resolve imports and provide language features for PDM-managed packages. ```toml [tool.pyright] extraPaths = ["__pypackages__//lib/"] ``` -------------------------------- ### Configuring PDM Shell Completion (Bash - System-wide) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Generates and installs the PDM shell completion script for Bash system-wide. This requires root (sudo) privileges to write the completion file to `/etc/bash_completion.d/`. ```bash pdm completion bash > /etc/bash_completion.d/pdm.bash-completion # Requires root (sudo). For an alternative, see next ``` -------------------------------- ### Publishing PDM Package with GitLab CI Trusted Publishers (YAML) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/publish.md This GitLab CI configuration demonstrates how to publish a PDM package using trusted publishers. It sets up the Python environment, installs PDM, configures an ID token for PyPI, and then publishes the package. ```yaml image: python:3.12-bookworm before_script: - pip install pdm publish-package: stage: release environment: production id_tokens: PYPI_ID_TOKEN: # for testpypi: TESTPYPI_ID_TOKEN aud: "pypi" # testpypi script: - pdm publish ``` -------------------------------- ### Building Python Applications with PDM in Multi-stage Dockerfile Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This Dockerfile illustrates a multi-stage build process for Python applications using PDM. It efficiently installs project dependencies into a local package directory in a builder stage, then copies only the necessary artifacts to a leaner final stage, optimizing image size and build times. ```Dockerfile ARG PYTHON_BASE=3.10-slim # build stage FROM python:$PYTHON_BASE AS builder # install PDM RUN pip install -U pdm # disable update check ENV PDM_CHECK_UPDATE=false # copy files COPY pyproject.toml pdm.lock README.md /project/ COPY src/ /project/src # install dependencies and project into the local packages directory WORKDIR /project RUN pdm install --check --prod --no-editable # run stage FROM python:$PYTHON_BASE # retrieve packages from build stage COPY --from=builder /project/.venv/ /project/.venv ENV PATH="/project/.venv/bin:$PATH" # set command/entrypoint, adapt to fit your needs COPY src /project/src CMD ["python", "src/__main__.py"] ``` -------------------------------- ### Publishing PDM Package to PyPI (Bash) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/publish.md This command builds a wheel and source distribution, then uploads them to the default PyPI index. It's the simplest way to publish a package. ```bash pdm publish ``` -------------------------------- ### Expanding Environment Variables with pdm-backend (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/reference/pep621.md This TOML example demonstrates how `pdm-backend` expands environment variables within dependency strings. This feature allows for dynamic resolution of credentials or paths from environment variables, ensuring sensitive information is not hardcoded and remains untouched in the lock file. ```TOML [project] dependencies = ["flask @ https://${USERNAME}:${PASSWORD}/artifacts.io/Flask-1.1.2.tar.gz"] ``` -------------------------------- ### Configuring Pyright Extra Paths for Neovim LSP Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/pep582.md This `pyproject.toml` configuration adds the PDM `__pypackages__` directory to Pyright's `extraPaths`. This is crucial for Neovim's LSP client (nvim-lspconfig) to correctly resolve imports and provide language features for packages installed by PDM. ```toml [tool.pyright] extraPaths = ["__pypackages__//lib/"] ``` -------------------------------- ### Cloning PDM Repository (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Instructions for cloning the PDM project repository from GitHub using either HTTPS or SSH protocols. This is the initial step to get a local copy of the project for development. ```bash git clone https://github.com/pdm-project/pdm.git ``` ```bash git clone git@github.com:pdm-project/pdm.git ``` -------------------------------- ### Defining PDM Plugin Entry Point with PEP 621 (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/dev/write.md This TOML configuration, adhering to PEP 621, defines a PDM plugin entry point named 'hello' within `pyproject.toml`. It maps the plugin to a callable `hello_plugin` located in the `my_plugin` module, making it discoverable by PDM. ```toml # pyproject.toml [project.entry-points.pdm] hello = "my_plugin:hello_plugin" ``` -------------------------------- ### Configuring Nox for PDM-based Testing Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/advanced.md This `noxfile.py` example shows how to integrate PDM with Nox for automated testing. It sets the `PDM_IGNORE_SAVED_PYTHON` environment variable to ensure PDM correctly picks up the Python interpreter within the Nox session's virtual environment. It then uses `pdm install` to manage dependencies for both testing and linting sessions. ```Python import os import nox os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"}) @nox.session def tests(session): session.run_always('pdm', 'install', '-G', 'test', external=True) session.run('pytest') @nox.session def lint(session): session.run_always('pdm', 'install', '-G', 'lint', external=True) session.run('flake8', '--import-order-style', 'google') ``` -------------------------------- ### Exposing Global Keyring CLI to PDM - Bash Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md This command modifies the `PATH` environment variable to include the directory where a globally installed `keyring`'s CLI executable resides, making it discoverable by PDM for password management. ```bash export PATH=$PATH:path/to/keyring/bin ``` -------------------------------- ### Previewing PDM Documentation (Bash) Source: https://github.com/pdm-project/pdm/blob/main/CONTRIBUTING.md Command to build and preview the PDM documentation locally. This allows contributors to see the rendered output of their documentation changes before committing. ```bash pdm run doc ``` -------------------------------- ### Installing Specific Development Dependency Group with PDM Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/dependency.md This command installs production dependencies and only the 'dev1' development group. It allows developers to install only the relevant development tools for their current task, reducing installation time and footprint. ```bash pdm install -G dev1 ``` -------------------------------- ### Customizing PDM Virtualenv Prompt Format Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/venv.md This example shows how to customize the virtual environment prompt using the `PDM_VENV_PROMPT` environment variable before creating the venv. It sets the prompt to include the project name and Python version in a custom format, then activates it to show the effect. ```bash $ PDM_VENV_PROMPT='{project_name}-py{python_version}' pdm venv create --name test-prompt $ eval $(pdm venv activate test-prompt) (test-project-py3.10) $ ``` -------------------------------- ### Running PDM Commands via Pyprojectx Wrapper (Shell) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Executes PDM commands through the `pw` wrapper script when PDM is installed as a project-local dependency via Pyprojectx. This ensures the correct PDM version is used for the specific project. ```bash ./pw pdm install ``` -------------------------------- ### Configuring PDM Repositories for Package Uploads (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md Presents a TOML configuration example for defining package repositories used by pdm publish. This snippet shows how to specify usernames, passwords, URLs, and custom CA certificates for different repositories (e.g., pypi, company) in the global config.toml file. ```toml [repository.pypi] username = "frostming" password = "" [repository.company] url = "https://pypi.company.org/legacy/" username = "frostming" password = "" ca_certs = "/path/to/custom-cacerts.pem" ``` -------------------------------- ### Passing Constant Arguments to PDM Commands - TOML Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md This TOML configuration in `pyproject.toml` allows defining constant arguments that PDM will automatically append to specific commands (e.g., `add`, `install`, `lock`). This streamlines workflows by applying common options without manual input. ```toml [tool.pdm.options] add = ["--no-isolation", "--no-self"] install = ["--no-self"] lock = ["--no-cross-platform"] ``` -------------------------------- ### Configuring VSCode Python Extra Paths Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/pep582.md This configuration adds the PDM `__pypackages__` directory to VSCode's Python auto-completion and analysis paths, allowing the language server to correctly find installed packages. This is typically placed in `.vscode/settings.json`. ```json { "python.autoComplete.extraPaths": ["__pypackages__//lib"], "python.analysis.extraPaths": ["__pypackages__//lib"] } ``` -------------------------------- ### Switching PDM Project to a Named Virtualenv Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/venv.md These commands illustrate how to switch the PDM project's active environment to a specific named virtual environment using `pdm use --venv`. It shows examples for switching to a venv named 'test' and to the default in-project venv. ```bash # Switch to a virtualenv named test $ pdm use --venv test # Switch to the in-project venv located at $PROJECT_ROOT/.venv $ pdm use --venv in-project ``` -------------------------------- ### Configuring Local Directory as PDM Package Source (TOML) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/config.md This TOML snippet configures a local directory as a package source for PDM, using the `find_links` type. It specifies a local path relative to the project root, enabling PDM to install packages directly from a local file system. ```TOML [[tool.pdm.source]] name = "local" url = "file:///${PROJECT_ROOT}/packages" type = "find_links" ``` -------------------------------- ### Configuring PDM Shell Completion (Fish) Source: https://github.com/pdm-project/pdm/blob/main/docs/index.md Generates and installs the PDM shell completion script for Fish shell. The script is saved to the standard Fish completions directory, enabling auto-completion for PDM commands. ```bash pdm completion fish > ~/.config/fish/completions/pdm.fish ``` -------------------------------- ### Configuring PDM for Single-File Scripts with Custom Index (Python) Source: https://github.com/pdm-project/pdm/blob/main/docs/usage/scripts.md This example extends the single-file script concept by adding a `[tool.pdm]` section within the inline metadata. This allows configuring PDM-specific settings, such as using a custom package index (`https://mypypi.org/simple`), directly within the script file. ```python # test_script.py # /// script # requires-python = ">=3.11" # dependencies = [ # "requests<3", # "rich", # ] # # [[tool.pdm.source]] # Use a custom index # url = "https://mypypi.org/simple" # name = "pypi" # /// ```