Package Assembler#
Create conda packages programmatically without a recipe file.
You can import the package assembler classes and functions from rattler_build:
assemble_package#
Create a conda package from files and metadata.
This is a low-level function for creating conda packages without a recipe. Use this when you have files staged and want to package them directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Package name. |
required |
version
|
str
|
Package version. |
required |
target_platform
|
str
|
Target platform (e.g., "linux-64", "osx-arm64", "noarch"). |
required |
build_string
|
str
|
Build string (e.g., "py312_0", "h1234567_0"). |
required |
output_dir
|
str | Path
|
Directory where the package will be created. |
required |
files_dir
|
str | Path | None
|
Directory containing files to include. All files in this directory will be added to the package. |
None
|
files
|
Sequence[FileEntry] | None
|
List of FileEntry objects for explicit file mappings. Use this for fine-grained control over which files to include. |
None
|
homepage
|
str | None
|
Homepage URL for the package. |
None
|
license
|
str | None
|
License identifier (e.g., "MIT", "Apache-2.0"). |
None
|
license_family
|
str | None
|
License family (e.g., "MIT", "GPL"). |
None
|
summary
|
str | None
|
Short one-line summary of the package. |
None
|
description
|
str | None
|
Full description of the package. |
None
|
depends
|
Sequence[str] | None
|
List of runtime dependencies (e.g., ["python >=3.8", "numpy"]). |
None
|
constrains
|
Sequence[str] | None
|
List of version constraints (e.g., ["cudatoolkit >=11.0"]). |
None
|
build_number
|
int
|
Build number (default: 0). |
0
|
noarch
|
Literal['python', 'generic'] | None
|
Noarch type ("python" or "generic") or None for arch-specific. |
None
|
license_files
|
Sequence[str | Path] | None
|
List of paths to license files to include. |
None
|
test_files
|
Sequence[str | Path] | None
|
List of paths to test files to include. |
None
|
recipe_dir
|
str | Path | None
|
Path to recipe directory to include in info/recipe/. |
None
|
compression_level
|
int
|
Compression level 0-9 (default: 9, higher = smaller but slower). |
9
|
archive_type
|
ArchiveType
|
Archive format (default: ArchiveType.Conda). |
Conda
|
timestamp
|
datetime | None
|
Build timestamp as a datetime object for reproducible builds. |
None
|
compression_threads
|
int | None
|
Number of threads for compression (default: auto-detect). |
None
|
detect_prefix
|
bool
|
Whether to detect and record prefix placeholders (default: True). |
True
|
Returns:
| Type | Description |
|---|---|
PackageOutput
|
PackageOutput with path to the created package and identifier. |
Raises:
| Type | Description |
|---|---|
RattlerBuildError
|
If package name, version, or platform is invalid, or if the build fails. |
Example
from rattler_build import assemble_package, ArchiveType
# Simple package
output = assemble_package(
name="mypackage",
version="1.0.0",
target_platform="linux-64",
build_string="py312_0",
output_dir="/output",
files_dir="/staged/files",
)
# Package with metadata
output = assemble_package(
name="mypackage",
version="1.0.0",
target_platform="linux-64",
build_string="py312_0",
output_dir="/output",
files_dir="/staged/files",
homepage="https://github.com/org/mypackage",
license="MIT",
summary="My awesome package",
depends=["python >=3.12", "numpy"],
)
collect_files#
Collect files from a directory using glob patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_dir
|
str | Path
|
Directory to scan for files. |
required |
include_globs
|
Sequence[str] | None
|
Glob patterns to include (e.g., ["/.py", "bin/"]). If not specified, all files are included by default. |
None
|
exclude_globs
|
Sequence[str] | None
|
Glob patterns to exclude. Exclusions take precedence over inclusions. |
None
|
follow_symlinks
|
bool
|
Whether to follow symlinks when traversing (default: False). |
False
|
include_hidden
|
bool
|
Whether to include hidden files starting with . (default: False). |
False
|
Returns:
| Type | Description |
|---|---|
list[FileEntry]
|
List of FileEntry objects for all matched files. |
Example
from rattler_build import collect_files
# Collect all Python files except tests
files = collect_files(
"/path/to/project",
include_globs=["**/*.py"],
exclude_globs=["**/test_*.py", "**/__pycache__/**"],
)
# Collect everything including hidden files
files = collect_files("/path/to/project", include_hidden=True)
ArchiveType#
FileEntry#
Represents a file to be included in the package.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Path
|
Source path on disk. |
destination |
Path
|
Destination path within the package (relative). |
is_symlink |
bool
|
Whether this is a symlink. |
symlink_target |
Path | None
|
Symlink target (if this is a symlink). |
from_paths
classmethod
#
Create a FileEntry from source and destination paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Source path on disk. |
required |
destination
|
str | Path
|
Destination path within the package (relative). |
required |
Returns:
| Type | Description |
|---|---|
FileEntry
|
A new FileEntry instance. |
PackageOutput#
Result of successful package creation.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
Path to the created package file. |
identifier |
str
|
Package identifier (name-version-build). |