uv_manager
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
flavor.packaging.python.uv_manager
¶
UV tool manager for FlavorPack packaging.
This module provides UV (uv) command management with Foundation integration for Python package management operations that benefit from uv's performance.
IMPORTANT: UV commands are used for specific operations where performance is critical. For complex dependency resolution, use PyPaPipManager instead.
Classes¶
UVManager
¶
Bases: BaseToolManager
UV tool manager extending Foundation's BaseToolManager.
Handles UV-specific operations with proper platform support for fast Python package management operations.
CRITICAL: This class is for UV-specific operations where speed matters. For complex dependency resolution, use PyPaPipManager instead.
DO NOT REPLACE PyPA pip commands with uv pip - they have different capabilities!
Initialize the UV manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig | None
|
Foundation configuration (can be None for default) |
None
|
Source code in flavor/packaging/python/uv_manager.py
Functions¶
compile_requirements
¶
compile_requirements(
input_file: Path,
output_file: Path,
python_version: str | None = None,
) -> None
Compile requirements file using UV pip-compile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Path
|
Input requirements.in file |
required |
output_file
|
Path
|
Output requirements.txt file |
required |
python_version
|
str | None
|
Target Python version |
None
|
Source code in flavor/packaging/python/uv_manager.py
create_venv
¶
Create virtual environment using UV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
venv_path
|
Path
|
Path where venv should be created |
required |
python_version
|
str | None
|
Specific Python version constraint |
None
|
Source code in flavor/packaging/python/uv_manager.py
download_uv_binary
¶
Download UV binary for packaging (manylinux2014 on Linux).
CRITICAL: This downloads the UV binary itself, not packages using UV. UV cannot download itself - this uses PyPA pip or direct download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dest_dir
|
Path
|
Directory to save UV binary to |
required |
python_exe
|
Path | None
|
Python executable to use for pip (optional) |
None
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to UV binary if successful, None otherwise |
Retries
Up to 3 attempts with exponential backoff for network errors
Source code in flavor/packaging/python/uv_manager.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | |
download_wheels_network
¶
Download wheels via UV's HTTP client using install+cache collection.
Note: uv pip download does not exist as a UV subcommand.
Strategy: install into an isolated --target dir with a private
--cache-dir, then collect the .whl files that UV wrote into its
wheel cache during the install.
This works where pip fails because UV uses its own Rust HTTP client (reqwest) which succeeds on Windows GHA where Python urllib3 gets [Errno 11001] getaddrinfo failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requirements_file
|
Path
|
Path to requirements.txt file (no hashes) |
required |
dest_dir
|
Path
|
Directory to collect wheel files into |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if wheels were collected, False otherwise |
Source code in flavor/packaging/python/uv_manager.py
download_wheels_offline
¶
Attempt to download wheels from a pre-warmed local wheel cache (no network).
Checks the FLAVOR_WHEEL_CACHE environment variable for a directory containing
pre-downloaded .whl files (populated by the CI pre-warm step or equivalent).
Uses pip download --no-index --find-links to copy matching wheels from that
local directory into dest_dir without any network access.
Note: uv pip download does not exist as a UV subcommand. This function
uses standard pip with --no-index to ensure zero network activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requirements_file
|
Path
|
Path to requirements.txt file |
required |
dest_dir
|
Path
|
Directory to download wheels to |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all wheels were found in local cache, False otherwise |
Source code in flavor/packaging/python/uv_manager.py
export_requirements
¶
Export pinned requirements from an existing uv.lock file (no network needed).
Uses uv export --frozen which reads the committed lock file without
making any PyPI/DNS calls. Preferred over compile_requirements when a
lock file is already present.
uv export excludes the root project itself from output by default, so only transitive runtime dependencies are listed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_dir
|
Path
|
Project directory containing uv.lock |
required |
output_file
|
Path
|
Output requirements.txt file |
required |
no_dev
|
bool
|
Whether to exclude dev dependencies (default True) |
True
|
Source code in flavor/packaging/python/uv_manager.py
find_system_uv
¶
Find system-installed UV executable.
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to UV executable if found, None otherwise |
Source code in flavor/packaging/python/uv_manager.py
get_available_versions
¶
Get list of available UV versions from GitHub releases.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of version strings available for download |
Source code in flavor/packaging/python/uv_manager.py
get_metadata
¶
Get metadata for a specific UV version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
UV version string |
required |
Returns:
| Type | Description |
|---|---|
ToolMetadata
|
ToolMetadata with UV download information |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If version metadata cannot be retrieved |
Source code in flavor/packaging/python/uv_manager.py
get_uv_executable
¶
Get path to UV executable, installing if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str | None
|
Specific version to use (None for system UV) |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to UV executable |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If UV cannot be found or installed |
Source code in flavor/packaging/python/uv_manager.py
install_packages_fast
¶
install_packages_fast(
venv_python: Path,
packages: list[str],
requirements_file: Path | None = None,
) -> None
Install packages using UV pip for speed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
venv_python
|
Path
|
Python executable in target venv |
required |
packages
|
list[str]
|
List of package names to install |
required |
requirements_file
|
Path | None
|
Optional requirements file |
None
|