CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pdm

A modern Python package and dependency manager supporting the latest PEP standards

Pending
Overview
Eval results
Files

core-management.mddocs/

Core Management

Central coordination system managing projects, plugins, configuration, and global PDM operations. The core module provides the main entry point for both CLI and programmatic usage.

Capabilities

Core Manager Class

The primary coordination class that manages PDM's global state, plugin system, and project creation.

class Core:
    """
    Main high-level manager and plugin coordinator.
    
    Attributes:
    - version: Current PDM version
    - ui: Terminal user interface 
    - state: Current core state
    - uv_cmd: UV command availability
    """
    
    def create_project(
        self,
        root_path: str | Path | None = None,
        is_global: bool = False,
        global_config: str | None = None,
    ) -> Project:
        """
        Create or load a PDM project from the specified path.
        
        Args:
            root_path: Path to project directory (default: auto-detect)
            is_global: Whether to create a global project
            global_config: Path to global config file
            
        Returns:
            Project instance for the specified path
        """
    
    def register_command(self, command: type[BaseCommand], name: str | None = None) -> None:
        """
        Register a custom CLI command.
        
        Args:
            command: Command class (not instance) implementing BaseCommand
            name: Optional custom name for the command
        """
    
    def add_config(self, name: str, config_item: ConfigItem) -> None:
        """
        Add a configuration option to PDM's global configuration.
        
        Args:
            name: Configuration option name
            config_item: Configuration item definition
        """
    
    def load_plugins(self) -> None:
        """
        Load and initialize all registered plugins.
        """
        
    @property
    def version(self) -> str:
        """Current PDM version string"""
        
    @property 
    def ui(self) -> UI:
        """Terminal user interface instance"""
        
    @property
    def state(self) -> State:
        """Current core state"""

Core State Management

State dataclass managing core configuration and operational flags.

@dataclass
class State:
    """
    State of the core object managing configuration and operational flags.
    
    Attributes:
    - config_settings: Global configuration overrides
    - exclude_newer: Exclude packages newer than timestamp
    - build_isolation: Use isolated build environments
    - enable_cache: Enable package caching
    - overrides: Dependency override specifications
    """
    config_settings: dict[str, str] = field(default_factory=dict)
    exclude_newer: str | None = None
    build_isolation: bool = True
    enable_cache: bool = True
    overrides: dict[str, str] = field(default_factory=dict)

Main Entry Point

Primary CLI entry function that coordinates command parsing and execution.

def main(args: list[str] | None = None) -> None:
    """
    Main CLI entry point for PDM commands.
    
    Args:
        args: Command line arguments (default: sys.argv[1:])
        
    Raises:
        PdmArgumentError: Invalid command line arguments
        PdmUsageError: Usage errors during command execution
    """

Plugin System

PDM's extensible plugin system allows custom commands, configuration options, and functionality extensions.

Plugin Registration

Plugins are registered via Python entry points:

# In setup.py or pyproject.toml
entry_points = {
    "pdm": [
        "my_plugin = my_package.plugin:plugin_function"
    ]
}

Plugin Function

def plugin_function(core: Core) -> None:
    """
    Plugin entry point function.
    
    Args:
        core: PDM Core instance for registration and configuration
        
    Example:
        def my_plugin(core: Core) -> None:
            # Register custom command
            core.register_command(MyCommand(), "mycmd")
            
            # Add configuration option
            from pdm.project.config import ConfigItem
            core.add_config("my_option", ConfigItem(
                "My custom option",
                "string",
                default="default_value"
            ))
    """

Usage Examples

Basic Core Usage

from pdm.core import Core

# Create core manager
core = Core()

# Create project
project = core.create_project("./my-project")

# Load plugins
core.load_plugins()

Custom Plugin Development

from pdm.core import Core
from pdm.cli.commands.base import BaseCommand
from pdm.project.config import ConfigItem

class MyCustomCommand(BaseCommand):
    """Custom PDM command"""
    
    def add_arguments(self, parser):
        parser.add_argument("--my-flag", action="store_true")
    
    def handle(self, project, options):
        print(f"Executing custom command in {project.root}")

def my_plugin(core: Core) -> None:
    """Plugin registration function"""
    # Register custom command
    core.register_command(MyCustomCommand(), "mycmd")
    
    # Add custom configuration
    core.add_config("my_setting", ConfigItem(
        "My custom setting",
        "string",
        default="value"
    ))

Programmatic Project Creation

from pdm.core import Core
import os

# Create core instance
core = Core()

# Create projects in different directories
projects = []
for project_dir in ["./app", "./lib", "./tools"]:
    os.makedirs(project_dir, exist_ok=True)
    project = core.create_project(project_dir)
    projects.append(project)

# Configure each project
for project in projects:
    # Project-specific configuration
    project.pyproject.setdefault("tool", {})["pdm"] = {
        "version": {"source": "scm"}
    }

Install with Tessl CLI

npx tessl i tessl/pypi-pdm

docs

cli-framework.md

core-management.md

dependency-resolution.md

environment-management.md

index.md

installation-sync.md

project-management.md

tile.json