Skip to content

Debug Session#

Interactive debugging for conda recipe builds. Set up the full build environment without running the build, then iteratively run, inspect, and modify the build script.

from rattler_build import DebugSession, DebugPaths, ScriptResult

DebugSession#

Interactive debugging session for a conda recipe.

Use :meth:create to set up the environment. Then call :meth:run_script to execute the build, inspect results, modify files, and re-run.

Example::

session = DebugSession.create(variant, channels=["conda-forge"])
result = session.run_script(trace=True)
print(result.stdout)

paths property #

paths

All paths associated with this debug session.

work_dir property #

work_dir

Work directory where the build script and sources live.

host_prefix property #

host_prefix

Host prefix (where host dependencies are installed).

build_prefix property #

build_prefix

Build prefix (where build dependencies are installed).

build_script property #

build_script

Path to the build script.

output_dir property #

output_dir

Output directory where packages are written.

setup_log property #

setup_log

Log messages captured during environment setup.

run class-attribute instance-attribute #

run = run_script

create classmethod #

create(
    variant,
    *,
    tool_config=None,
    output_dir=None,
    channels=None,
    no_build_id=True,
    progress_callback=None,
)

Create a debug session from a rendered variant.

This resolves dependencies, fetches sources, installs environments, and creates the build script — all without running the actual build.

Parameters#

variant: A rendered variant from recipe.render(). tool_config: Optional tool configuration. Uses defaults if not provided. output_dir: Where to write build artifacts. A temporary directory is used if not specified. channels: Conda channels to use. Defaults to ["conda-forge"]. no_build_id: If True (default), omit the build ID from directory paths, giving stable paths across iterations. progress_callback: Optional callback for progress events during setup.

Returns#

DebugSession A session with the environment fully set up and ready to run.

run_script #

run_script(*, trace=False)

Run the build script and capture output.

Parameters#

trace: If True, run bash with -x flag to trace each command.

Returns#

ScriptResult The exit code, stdout, and stderr from the build script.

add_packages #

add_packages(specs, *, environment='host', channels=None)

Add packages to the host or build environment.

Parameters#

specs: Conda match specs (e.g. ["numpy", "pandas>=2"]). environment: "host" or "build". channels: Override channels for this operation.

Returns#

list[str] The specs that were requested (confirmation).

create_patch #

create_patch(
    name="changes",
    *,
    output_dir=None,
    overwrite=False,
    exclude=None,
    add=None,
    include=None,
    dry_run=False,
)

Create a patch from changes in the work directory.

Parameters#

name: Patch file name (without extension). output_dir: Where to write the patch file. Defaults to the recipe directory. overwrite: Overwrite existing patch file. exclude: Glob patterns to exclude from the patch. add: Glob patterns for untracked files to include. include: Glob patterns to restrict the patch to. dry_run: If True, print the patch without writing it.

Returns#

str Empty string on success.

read_build_script #

read_build_script()

Read and return the build script contents.

DebugPaths#

All paths associated with a debug session.

work_dir instance-attribute #

work_dir

Work directory where the build script and sources live.

host_prefix instance-attribute #

host_prefix

Host prefix (where host dependencies are installed).

build_prefix instance-attribute #

build_prefix

Build prefix (where build dependencies are installed).

build_script instance-attribute #

build_script

Path to the build script (conda_build.sh / conda_build.bat).

build_env_script instance-attribute #

build_env_script

Path to the environment script (build_env.sh / build_env.bat).

build_dir instance-attribute #

build_dir

Build directory (parent of work, host_env, build_env).

output_dir instance-attribute #

output_dir

Output directory where packages are written.

recipe_dir instance-attribute #

recipe_dir

Recipe directory.

ScriptResult#

Result of running a build script.

Non-zero exit_code is not an exception — it is expected during debugging. Inspect stdout and stderr to diagnose the failure.

exit_code instance-attribute #

exit_code

Process exit code (0 = success).

stdout instance-attribute #

stdout

Captured standard output.

stderr instance-attribute #

stderr

Captured standard error.

success property #

success

Whether the script exited successfully.