puccinialin
Puccinialin is a Python library designed to install Rust (cargo and rustc) into a temporary, cache-aware directory. This helps Python projects with Rust-based build backends bootstrap their Rust dependencies without modifying the host's environment. The current version is 0.1.9, and its release cadence appears irregular, with updates driven by need rather than a fixed schedule.
Warnings
- breaking Puccinialin requires Python version 3.9 or newer. Installation or use in environments with older Python versions (e.g., 3.8) will result in installation failures or 'No matching distribution found' errors.
- gotcha The `setup_rust` function returns a dictionary of environment variables. It's crucial to merge these with `os.environ` when executing Rust commands via `subprocess` to ensure the newly installed Rust toolchain is properly used. Failing to do so will result in Rust commands not being found or using a different, potentially incompatible, Rust installation.
Install
-
pip install puccinialin
Imports
- setup_rust
from puccinialin import setup_rust
Quickstart
import os
from subprocess import check_call
from puccinialin import setup_rust
# Install Rust into a user cache directory by default, or specify a path
extra_env = setup_rust()
# Use the returned environment variables to call Rust tools like cargo
# For example, to run 'cargo build' with the installed Rust environment:
try:
print("Attempting to run 'cargo build' with installed Rust...")
# Combine current environment with the extra_env provided by puccinialin
check_call(["cargo", "build"], env={**os.environ, **extra_env})
print("Cargo build command executed successfully.")
except Exception as e:
print(f"Error executing cargo build: {e}")
print("Note: 'cargo build' requires a Rust project in the current directory. This is an example of how to use the setup_rust output.")