Package#
Load, inspect, and test conda packages.
You can import the package classes from rattler_build:
The tests property returns a list of test objects that can be pattern matched (Python 3.10+):
for test in pkg.tests:
match test:
case PythonTest() as py_test:
print(f"Python imports: {py_test.imports}")
case CommandsTest() as cmd_test:
print(f"Commands: {cmd_test.script}")
case PackageContentsTest() as pc_test:
print(f"Package contents check, strict={pc_test.strict}")
Package#
A loaded conda package for inspection and testing.
This class provides access to package metadata, file contents, and embedded tests. The package is lazily extracted when needed (e.g., when accessing files or tests).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Package name (e.g., "numpy") |
version |
str
|
Package version (e.g., "1.26.0") |
build_string |
str
|
Build string (e.g., "py312_0") |
build_number |
int
|
Build number |
subdir |
str | None
|
Target platform subdirectory (e.g., "linux-64", "noarch") |
noarch |
str | None
|
NoArch type (None, "python", or "generic") |
depends |
list[str]
|
List of runtime dependencies |
constrains |
list[str]
|
List of dependency constraints |
license |
str | None
|
Package license |
license_family |
str | None
|
License family |
timestamp |
datetime | None
|
Build timestamp as a datetime object |
arch |
str | None
|
Architecture (e.g., "x86_64") |
platform |
str | None
|
Platform (e.g., "linux") |
path |
Path
|
Path to the package file |
archive_type |
str
|
Archive format ("conda" or "tar.bz2") |
filename |
str
|
Filename of the package |
files |
list[str]
|
List of all files in the package |
tests |
list[PackageTestType]
|
List of tests embedded in the package |
tests
property
#
List of tests embedded in the package.
Returns a list of test objects that can be pattern matched:
from_file
classmethod
#
Load a package from a .conda or .tar.bz2 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the package file |
required |
Returns:
| Type | Description |
|---|---|
Package
|
A Package object for inspection and testing |
Raises:
| Type | Description |
|---|---|
RattlerBuildError
|
If the package cannot be loaded or parsed |
run_test #
run_test(
index,
*,
channel=None,
channel_priority=None,
debug=False,
auth_file=None,
allow_insecure_host=None,
compression_threads=None,
use_bz2=True,
use_zstd=True,
use_sharded=True,
)
Run a specific test by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index of the test to run (0-based) |
required |
channel
|
Sequence[str] | None
|
List of channels to use for dependencies |
None
|
channel_priority
|
Literal['disabled', 'strict', 'flexible'] | None
|
Channel priority ("disabled", "strict", or "flexible") |
None
|
debug
|
bool
|
Enable debug mode (keeps test environment) |
False
|
auth_file
|
str | Path | None
|
Path to authentication file |
None
|
allow_insecure_host
|
Sequence[str] | None
|
List of hosts to allow insecure connections |
None
|
compression_threads
|
int | None
|
Number of compression threads |
None
|
use_bz2
|
bool
|
Enable bz2 repodata |
True
|
use_zstd
|
bool
|
Enable zstd repodata |
True
|
use_sharded
|
bool
|
Enable sharded repodata |
True
|
Returns:
| Type | Description |
|---|---|
TestResult
|
TestResult with success status and output |
Raises:
| Type | Description |
|---|---|
RattlerBuildError
|
If the test index is out of range or test execution fails |
run_tests #
run_tests(
*,
channel=None,
channel_priority=None,
debug=False,
auth_file=None,
allow_insecure_host=None,
compression_threads=None,
use_bz2=True,
use_zstd=True,
use_sharded=True,
)
Run all tests in the package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Sequence[str] | None
|
List of channels to use for dependencies |
None
|
channel_priority
|
Literal['disabled', 'strict', 'flexible'] | None
|
Channel priority ("disabled", "strict", or "flexible") |
None
|
debug
|
bool
|
Enable debug mode (keeps test environment) |
False
|
auth_file
|
str | Path | None
|
Path to authentication file |
None
|
allow_insecure_host
|
Sequence[str] | None
|
List of hosts to allow insecure connections |
None
|
compression_threads
|
int | None
|
Number of compression threads |
None
|
use_bz2
|
bool
|
Enable bz2 repodata |
True
|
use_zstd
|
bool
|
Enable zstd repodata |
True
|
use_sharded
|
bool
|
Enable sharded repodata |
True
|
Returns:
| Type | Description |
|---|---|
list[TestResult]
|
List of TestResult objects, one per test |
TestResult#
Result of running a test.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Whether the test passed |
output |
list[str]
|
Test output/logs |
test_index |
int
|
Index of the test that was run |
Test Types#
PythonTest#
Python test - imports modules and optionally runs pip check.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Index of this test in the package's test list |
imports |
list[str]
|
List of modules to import |
pip_check |
bool
|
Whether to run pip check (default: True) |
python_version |
PythonVersion | None
|
Python version specification |
PythonVersion#
Python version specification for tests.
Can be a single version, multiple versions, or unspecified (None).
CommandsTest#
Commands test - runs arbitrary shell commands.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Index of this test in the package's test list |
script |
dict[str, Any]
|
The script content (as dict) |
requirements_run |
list[str]
|
Extra runtime requirements for the test |
requirements_build |
list[str]
|
Extra build requirements for the test (e.g., emulators) |
requirements_build
property
#
Extra build requirements for the test (e.g., emulators).
PerlTest#
RTest#
RubyTest#
DownstreamTest#
Downstream test - tests a downstream package that depends on this package.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Index of this test in the package's test list |
downstream |
str
|
Name of the downstream package to test |
PackageContentsTest#
Package contents test - checks that files exist or don't exist in the package.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Index of this test in the package's test list |
files |
FileChecks
|
File checks for all files |
site_packages |
FileChecks
|
File checks for Python site-packages |
bin |
FileChecks
|
File checks for binaries in bin/ |
lib |
FileChecks
|
File checks for libraries |
include |
FileChecks
|
File checks for include headers |
strict |
bool
|
Whether to fail on non-matched glob patterns (strict mode) |
FileChecks#
File existence checks (glob patterns).
Attributes:
| Name | Type | Description |
|---|---|---|
exists |
list[str]
|
Glob patterns that must match at least one file |
not_exists |
list[str]
|
Glob patterns that must NOT match any file |
PathEntry#
Path entry from paths.json.
Attributes:
| Name | Type | Description |
|---|---|---|
relative_path |
str
|
Relative path of the file in the package |
no_link |
bool
|
Whether to skip linking this file |
path_type |
str
|
Path type ("hardlink", "softlink", or "directory") |
size_in_bytes |
int | None
|
Size of the file in bytes (if available) |
sha256 |
str | None
|
SHA256 hash of the file (if available) |