Skip to main content

puccinialin

Install rust into a temporary directory to support rust-based builds.

Cargo and rustc are installed into a cache directory, to avoid modifying the host's environment, and activated using a set of environment variables.

The difficulty is mapping one of the various sources python platform information (sys, platform, sysconfig, etc.) to a rustc target triple (https://doc.rust-lang.org/nightly/rustc/platform-support.html). This project mainly uses SOABI for detection, but can be extended to use other APIs for other platforms. By using rustup, it is currently limited to the platforms listed under https://rust-lang.github.io/rustup/installation/other.html#manual-installation. SOABI, which contains the file extensions of native modules.

Contributing

The platform specific logic is in src/puccinialin/_target.py, specifically get_triple.

Usage: Python

There is a single setup_rust function that takes the installation directory, or uses the user cache directory by default. It returns a dict of environment variables to be used when calling rust.

import os
from subprocess import check_call

from puccinialin import setup_rust

extra_env = setup_rust("path/to/installation/dir")
check_call(["cargo", "build"], env={**os.environ, **extra_env})

With setuptools-rust:

import os
import shutil

from setuptools import setup
from setuptools_rust import RustBin

if not shutil.which("cargo"):
    from puccinialin import setup_rust

    print("Rust not found, installing into a temporary directory")
    extra_env = setup_rust()
    env = {**os.environ, **extra_env}
else:
    env = None

setup(
    ...,
    rust_extensions=[RustBin(..., env=env)],
)

You can use it as custom build backend to avoid the dependency when not needed, as e.g. in maturin:

"""Support installing rust before compiling maturin.

Installing a package that uses maturin as build backend on a platform without maturin
binaries, we install rust in a cache directory if the user doesn't have a rust
installation already. Since this bootstrapping requires more dependencies but is only
required if rust is missing, we check if cargo is present before requesting those
dependencies.

https://setuptools.pypa.io/en/stable/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks
"""

from __future__ import annotations

import os
import shutil
from typing import Any

# noinspection PyUnresolvedReferences
from setuptools.build_meta import *


def get_requires_for_build_wheel(_config_settings: dict[str, Any] = None) -> list[str]:
    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
        return ["puccinialin"]
    return []


def get_requires_for_build_sdist(_config_settings: dict[str, Any] = None) -> list[str]:
    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
        return ["puccinialin"]
    return []

Usage: CLI

$ python -m puccinialin --help
usage: __main__.py [-h] [--location LOCATION] [--program PROGRAM] [--info-json INFO_JSON]

options:
  -h, --help            show this help message and exit
  --location LOCATION   The directory for installing rust to
  --program PROGRAM     The name of the installation directory in the cache, if `--location` was not used. Defaults to 'puccinialin'.
  --info-json INFO_JSON
                        Write the new environment variables as JSON to this file

Implementation

Setting up rust consists of 4 steps:

  • Determine the platform in terms of a rust target triple
  • Download rustup-init for this target triple
  • Use rustup to install rust and cargo for this target
  • Report the environment variables to use this rust installation

Metadata

Release files for puccinialin 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for puccinialin 0.1.14
File Size Uploaded
puccinialin-0.1.14.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for puccinialin 0.1.14
File Interpreter ABI Platform
puccinialin-0.1.14-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / puccinialin-0.1.14.tar.gz

Download URL puccinialin-0.1.14.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c186d3ab26ceceae709f7edb7a620ea51e46fbeeb4f58d2de717c485e507914b
BLAKE2b-256 checksum
How to use checksums
272d6a096277eca8815d2192bcedef1b6605ac9fdd8b7c84115ee876be634bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / puccinialin-0.1.14-py3-none-any.whl

Download URL puccinialin-0.1.14-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1773f8a5190477fa002beb2021ac2b11f4288463be1ddfe01c552630c6afec3e
BLAKE2b-256 checksum
How to use checksums
7ca89333b5bf6ece3124b94560be93b56addecaade70bb81c31c3fbf49a39dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.14 This release

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page