API Reference#
pdm.core.Core
#
A high level object that manages all classes and configurations
install_manager_class
#
project_class
#
Core project class
config: dict[str, Any]
property
readonly
#
A read-only dict configuration, any modifications won't land in the file.
dev_dependencies: dict[str, Requirement]
property
readonly
#
All development dependencies
global_config: Config
cached
property
writable
#
Read-and-writable configuration dict for global settings
project_config: Config
cached
property
writable
#
Read-and-writable configuration dict for project settings
python_executable: str
property
readonly
#
For backward compatibility
find_interpreters(self, python_spec=None)
#
Return an iterable of interpreter paths that matches the given specifier, which can be: 1. a version specifier like 3.7 2. an absolute path 3. a short name like python3 4. None that returns all possible interpreters
get_environment(self)
#
Get the environment selected by this project
get_provider(self, strategy='all', tracked_names=None, for_install=False)
#
Build a provider class for resolver.
:param strategy: the resolve strategy :param tracked_names: the names of packages that needs to update :param for_install: if the provider is for install :returns: The provider object
get_pyproject_dependencies(self, group, dev=False)
#
Get the dependencies array in the pyproject.toml
get_reporter(self, requirements, tracked_names=None, spinner=None)
#
Return the reporter object to construct a resolver.
:param requirements: requirements to resolve :param tracked_names: the names of packages that needs to update :param spinner: optional spinner object :returns: a reporter
get_repository(self, cls=None)
#
Get the repository object
resolve_interpreter(self)
#
Get the Python interpreter path.
repository_class (BaseRepository)
#
Get package and metadata from PyPI source.
resolver_class (AbstractResolver)
#
The thing that performs the actual resolution work.
base_exception (Exception)
#
A base class for all exceptions raised by this module.
Exceptions derived by this class should all be handled in this module. Any bubbling pass the resolver should be treated as a bug.
resolve(self, requirements, max_rounds=100)
#
Take a collection of constraints, spit out the resolution result.
The return value is a representation to the final resolution result. It is a tuple subclass with three public members:
mapping
: A dict of resolved candidates. Each key is an identifier of a requirement (as returned by the provider'sidentify
method), and the value is the resolved candidate.graph
: ADirectedGraph
instance representing the dependency tree. The vertices are keys ofmapping
, and each edge represents why a particular package is included. A special vertexNone
is included to represent parents of user-supplied requirements.criteria
: A dict of "criteria" that hold detailed information on how edges in the graph are derived. Each key is an identifier of a requirement, and the value is aCriterion
instance.
The following exceptions may be raised if a resolution cannot be found:
ResolutionImpossible
: A resolution cannot be found for the given combination of requirements. Thecauses
attribute of the exception is a list of (requirement, parent), giving the requirements that could not be satisfied.ResolutionTooDeep
: The dependency tree is too deeply nested and the resolver gave up. This is usually caused by a circular dependency, but you can try to resolve this by increasing themax_rounds
argument.
synchronizer_class
#
Synchronize the working set with given installation candidates
compare_with_working_set(self)
#
Compares the candidates and return (to_add, to_update, to_remove)
install_candidate(self, key)
#
Install candidate
remove_distribution(self, key)
#
Remove distributions with given names.
synchronize(self)
#
Synchronize the working set with pinned candidates.
update_candidate(self, key)
#
Update candidate
add_config(name, config_item)
staticmethod
#
Add a config item to the configuration class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str |
The name of the config item |
required |
config_item |
pdm.project.config.ConfigItem |
The config item to add |
required |
create_project(self, root_path=None, is_global=False)
#
Create a new project object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_path |
PathLike |
The path to the project root directory |
None |
is_global |
bool |
Whether the project is a global project |
False |
Returns:
Type | Description |
---|---|
Project |
The project object |
load_plugins(self)
#
Import and load plugins under pdm.plugin
namespace
A plugin is a callable that accepts the core object as the only argument.
Examples:
1 2 |
|
main(self, args=None, prog_name=None, obj=None, **extra)
#
The main entry function
register_command(self, command, name=None)
#
Register a subcommand to the subparsers, with an optional name of the subcommand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
Type[pdm.cli.commands.base.BaseCommand] |
The command class to register |
required |
name |
str |
The name of the subcommand, if not given, |
None |
Signals#
New in version 1.12.0
The signal definition for PDM.
Examples:
1 2 3 4 5 6 7 8 9 10 |
|
post_init: NamedSignal
#
Called after a project is initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project |
The project object |
required |
post_install: NamedSignal
#
Called after a project is installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project |
The project object |
required |
candidates |
dict[str, Candidate] |
The candidates installed |
required |
dry_run |
bool |
If true, won't perform any actions |
required |
post_lock: NamedSignal
#
Called after a project is locked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project |
The project object |
required |
resolution |
dict[str, Candidate] |
The resolved candidates |
required |
dry_run |
bool |
If true, won't perform any actions |
required |
pre_install: NamedSignal
#
Called before a project is installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project |
The project object |
required |
candidates |
dict[str, Candidate] |
The candidates to install |
required |
dry_run |
bool |
If true, won't perform any actions |
required |
pre_lock: NamedSignal
#
Called before a project is locked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project |
The project object |
required |
requirements |
list[Requirement] |
The requirements to lock |
required |
dry_run |
bool |
If true, won't perform any actions |
required |