Parsers#

File format detection, parsing, and normalization.

Task file parser registry and auto-detection.

class conda_tasks.parsers.TaskFileParser[source]#

Interface that every task file parser must implement.

abstractmethod add_task(path: Path, name: str, task: Task) None[source]#

Persist a new task definition into path.

abstractmethod can_handle(path: Path) bool[source]#

Return True if this parser knows how to read path.

abstractmethod parse(path: Path) dict[str, Task][source]#

Parse path and return a mapping of task-name -> Task.

abstractmethod remove_task(path: Path, name: str) None[source]#

Remove the task named name from path.

conda_tasks.parsers.detect_and_parse(file_path: Path | None = None, start_dir: Path | None = None) tuple[Path, dict[str, Task]][source]#

Detect (or use file_path) a task file and parse it.

Returns (resolved_path, {task_name: Task}). Raises NoTaskFileError when no file is found.

conda_tasks.parsers.detect_task_file(start_dir: Path | None = None) Path | None[source]#

Walk up from start_dir looking for a known task file.

Returns the first match according to _SEARCH_ORDER, or None.

conda_tasks.parsers.get_parser(path: Path) TaskFileParser | None[source]#

Return the first parser that can handle path, or None.

Abstract base class for task file parsers.

class conda_tasks.parsers.base.TaskFileParser[source]#

Interface that every task file parser must implement.

abstractmethod add_task(path: Path, name: str, task: Task) None[source]#

Persist a new task definition into path.

abstractmethod can_handle(path: Path) bool[source]#

Return True if this parser knows how to read path.

abstractmethod parse(path: Path) dict[str, Task][source]#

Parse path and return a mapping of task-name -> Task.

abstractmethod remove_task(path: Path, name: str) None[source]#

Remove the task named name from path.

Parser for the conda.toml canonical TOML format.

Uses the same structure as pixi.toml tasks:

[tasks]
build = "make build"
test = { cmd = "pytest", depends-on = ["build"] }

[target.win-64.tasks]
build = "nmake build"
class conda_tasks.parsers.toml.CondaTomlParser[source]#

Reads and writes conda.toml files.

Structure is identical to pixi.toml task tables: [tasks] for definitions, [target.<platform>.tasks] for overrides.

add_task(path: Path, name: str, task: Task) None[source]#

Add or update a task in the TOML file, creating it if needed.

can_handle(path: Path) bool[source]#

Return True if path is a recognized conda.toml filename.

parse(path: Path) dict[str, Task][source]#

Parse a conda.toml file including platform overrides.

remove_task(path: Path, name: str) None[source]#

Remove a task from the TOML file by name.

conda_tasks.parsers.toml.tasks_to_toml(tasks: dict[str, Task]) str[source]#

Serialize a full task dict to conda.toml TOML string.

Parser for pixi.toml [tasks] and [target.<platform>.tasks] tables.

class conda_tasks.parsers.pixi_toml.PixiTomlParser[source]#

Reads pixi.toml task definitions.

Supports: - [tasks] top-level table - [target.<platform>.tasks] per-platform overrides

add_task(path: Path, name: str, task: Task) None[source]#

Not supported — pixi.toml is read-only.

can_handle(path: Path) bool[source]#

Return True if path is named pixi.toml.

parse(path: Path) dict[str, Task][source]#

Parse a pixi.toml file including platform overrides.

remove_task(path: Path, name: str) None[source]#

Not supported — pixi.toml is read-only.

Parser for pyproject.toml task definitions.

Reads from: - [tool.conda.tasks] (preferred) - [tool.conda-tasks.tasks] (legacy alias) - [tool.pixi.tasks] (fallback for pixi compatibility)

Platform overrides: - [tool.conda.target.<platform>.tasks] - [tool.conda-tasks.target.<platform>.tasks] - [tool.pixi.target.<platform>.tasks]

class conda_tasks.parsers.pyproject_toml.PyprojectTomlParser[source]#

Reads task definitions from pyproject.toml.

add_task(path: Path, name: str, task: Task) None[source]#

Not supported — pyproject.toml is read-only.

can_handle(path: Path) bool[source]#

Return True if path is a pyproject.toml with task definitions.

parse(path: Path) dict[str, Task][source]#

Parse tasks from conda, conda-tasks, or pixi tool tables.

remove_task(path: Path, name: str) None[source]#

Not supported — pyproject.toml is read-only.

Parser for .condarc task definitions.

Reads task definitions from the plugins.conda_tasks.tasks section of .condarc using conda’s configuration loading API. This means tasks defined in any condarc source (user, system, environment) are automatically discovered.

Writing (add/remove) still uses direct YAML manipulation since the config API is read-only.

class conda_tasks.parsers.condarc.CondaRCParser[source]#

Reads task definitions from .condarc via conda’s config API.

add_task(path: Path, name: str, task: Task) None[source]#

Add or update a task under plugins.conda_tasks.tasks in .condarc.

can_handle(path: Path) bool[source]#

Return True if path is a .condarc with task definitions.

parse(path: Path) dict[str, Task][source]#

Parse tasks from condarc via the config API, falling back to direct YAML.

remove_task(path: Path, name: str) None[source]#

Remove a task from the .condarc file by name.

Shared logic for normalizing raw task dicts into Task model objects.

conda_tasks.parsers.normalize.normalize_args(raw: list[Any] | None) list[TaskArg][source]#

Convert raw arg definitions into TaskArg objects.

Accepted shapes: - ["name"] (required arg, no default) - [{"arg": "name", "default": "value"}]

conda_tasks.parsers.normalize.normalize_depends_on(raw: list[Any] | str | None) list[TaskDependency][source]#

Convert the various depends-on formats into TaskDependency objects.

Accepted shapes: - ["foo", "bar"] (simple list of task names) - [{"task": "foo", "args": ["x"]}, ...] (full dict form) - [{"task": "foo"}, {"task": "bar"}] (pixi alias shorthand)

conda_tasks.parsers.normalize.normalize_override(raw: dict[str, Any]) TaskOverride[source]#

Parse a raw dict into a TaskOverride.

conda_tasks.parsers.normalize.normalize_task(name: str, raw: str | list[Any] | dict[str, Any]) Task[source]#

Convert a single raw task value into a Task object.

Handles all the shorthand forms: - "command string" (simple string command) - ["dep1", "dep2"] or [{"task": ...}] (alias / dependency-only) - {cmd: ..., depends-on: ..., ...} (full dict definition)

conda_tasks.parsers.normalize.normalize_tasks(raw_tasks: dict[str, Any]) dict[str, Task][source]#

Convert a dict of {name: raw_definition} into {name: Task}.