Tools
provide.foundation.tools
¶
TODO: Add module docstring.
Classes¶
BaseToolManager
¶
Bases: ABC
Abstract base class for tool managers.
Provides common functionality for downloading, verifying, and installing development tools. Subclasses must implement platform-specific logic.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration object. |
|
tool_name |
str
|
Name of the tool being managed. |
executable_name |
str
|
Name of the executable file. |
supported_platforms |
list[str]
|
List of supported platforms. |
Initialize the tool manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig
|
Configuration object containing settings. |
required |
Source code in provide/foundation/tools/base.py
Attributes¶
Functions¶
get_available_versions
abstractmethod
¶
get_install_path
¶
get_metadata
abstractmethod
¶
Get metadata for a specific version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version string to get metadata for. |
required |
Returns:
| Type | Description |
|---|---|
ToolMetadata
|
ToolMetadata object with download URLs and checksums. |
Source code in provide/foundation/tools/base.py
get_platform_info
¶
Get current platform information.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary with platform and arch keys. |
Source code in provide/foundation/tools/base.py
install
async
¶
Install a specific version of the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version to install (default: "latest"). |
'latest'
|
force
|
bool
|
Force reinstall even if cached. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the installed tool. |
Raises:
| Type | Description |
|---|---|
ToolInstallError
|
If installation fails. |
Source code in provide/foundation/tools/base.py
is_installed
¶
resolve_version
¶
Resolve a version specification to a concrete version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
str
|
Version specification (e.g., "latest", "~1.5.0"). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Concrete version string. |
Raises:
| Type | Description |
|---|---|
ToolNotFoundError
|
If version cannot be resolved. |
Source code in provide/foundation/tools/base.py
uninstall
¶
Uninstall a specific version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version to uninstall. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if uninstalled, False if not found. |
Source code in provide/foundation/tools/base.py
ToolCache
¶
Cache for installed tools with TTL support.
Tracks installed tool locations and expiration times to avoid unnecessary re-downloads and installations.
Initialize the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path | None
|
Cache directory (defaults to ~/.provide-foundation/cache). |
None
|
Source code in provide/foundation/tools/cache.py
Functions¶
clear
¶
get
¶
Get cached tool path if valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
str
|
Tool name. |
required |
version
|
str
|
Tool version. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to cached tool if valid, None otherwise. |
Source code in provide/foundation/tools/cache.py
get_size
¶
Get total size of cached tools in bytes.
Returns:
| Type | Description |
|---|---|
int
|
Total size in bytes. |
Source code in provide/foundation/tools/cache.py
invalidate
¶
Invalidate cache entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
str
|
Tool name. |
required |
version
|
str | None
|
Specific version, or None for all versions. |
None
|
Source code in provide/foundation/tools/cache.py
list_cached
¶
List all cached tools.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of cache entries with metadata. |
Source code in provide/foundation/tools/cache.py
prune_expired
¶
Remove expired entries from cache.
Returns:
| Type | Description |
|---|---|
int
|
Number of entries removed. |
Source code in provide/foundation/tools/cache.py
store
¶
Store tool in cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
str
|
Tool name. |
required |
version
|
str
|
Tool version. |
required |
path
|
Path
|
Path to installed tool. |
required |
ttl_days
|
int
|
Time-to-live in days. |
7
|
Source code in provide/foundation/tools/cache.py
ToolDownloader
¶
ToolDownloader(
client: UniversalClient,
time_source: Callable[[], float] | None = None,
async_sleep_func: (
Callable[[float], Awaitable[None]] | None
) = None,
)
Advanced download capabilities for tools.
Features: - Progress reporting with callbacks - Parallel downloads for multiple files - Mirror fallback support - Checksum verification
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Transport client for HTTP requests. |
|
progress_callbacks |
list[Callable[[int, int], None]]
|
List of progress callback functions. |
retry_policy |
Policy for retry behavior on downloads. |
Initialize the downloader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
UniversalClient
|
Universal client for making HTTP requests. |
required |
time_source
|
Callable[[], float] | None
|
Optional time source for testing (defaults to time.time). |
None
|
async_sleep_func
|
Callable[[float], Awaitable[None]] | None
|
Optional async sleep function for testing (defaults to asyncio.sleep). |
None
|
Source code in provide/foundation/tools/downloader.py
Functions¶
add_progress_callback
¶
download_parallel
async
¶
Download multiple files in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
list[tuple[str, Path]]
|
List of (url, destination) tuples. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of downloaded file paths in the same order as input. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If any download fails. |
Source code in provide/foundation/tools/downloader.py
download_with_mirrors
async
¶
Try multiple mirrors until one succeeds using fallback pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mirrors
|
list[str]
|
List of mirror URLs to try. |
required |
dest
|
Path
|
Destination file path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to downloaded file. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If all mirrors fail. |
Source code in provide/foundation/tools/downloader.py
download_with_progress
async
¶
Download a file with progress reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to download from. |
required |
dest
|
Path
|
Destination file path. |
required |
checksum
|
str | None
|
Optional checksum for verification. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the downloaded file. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If download or verification fails. |
Source code in provide/foundation/tools/downloader.py
verify_checksum
¶
Verify file checksum.
Uses Foundation's hash_file() for consistent hashing behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to file to verify. |
required |
expected
|
str
|
Expected checksum (hex string). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if checksum matches, False otherwise. |
Source code in provide/foundation/tools/downloader.py
ToolError
¶
ToolError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: FoundationError
Base exception for tool-related errors.
Source code in provide/foundation/errors/base.py
ToolInstaller
¶
Handle tool installation from various artifact formats.
Supports: - ZIP archives - TAR archives (with compression) - Single binary files - Platform-specific installation patterns
Functions¶
create_symlinks
¶
Create symlinks for easier access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_dir
|
Path
|
Installation directory. |
required |
metadata
|
ToolMetadata
|
Tool metadata. |
required |
Source code in provide/foundation/tools/installer.py
extract_tar
¶
Extract tar archive (with optional compression).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
Path
|
Path to tar file. |
required |
dest
|
Path
|
Destination directory. |
required |
Source code in provide/foundation/tools/installer.py
extract_zip
¶
Extract ZIP archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
Path
|
Path to ZIP file. |
required |
dest
|
Path
|
Destination directory. |
required |
Source code in provide/foundation/tools/installer.py
get_install_dir
¶
Get installation directory for tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
ToolMetadata
|
Tool metadata. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Installation directory path. |
Source code in provide/foundation/tools/installer.py
install
¶
Install tool from artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifact
|
Path
|
Path to downloaded artifact. |
required |
metadata
|
ToolMetadata
|
Tool metadata with installation info. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to installed tool directory. |
Raises:
| Type | Description |
|---|---|
InstallError
|
If installation fails. |
Source code in provide/foundation/tools/installer.py
install_binary
¶
Install single binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary
|
Path
|
Path to binary file. |
required |
dest
|
Path
|
Destination directory. |
required |
metadata
|
ToolMetadata
|
Tool metadata. |
required |
Source code in provide/foundation/tools/installer.py
is_binary
¶
Check if file is a binary executable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if file appears to be binary. |
Source code in provide/foundation/tools/installer.py
set_permissions
¶
Set appropriate permissions on installed files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_dir
|
Path
|
Installation directory. |
required |
metadata
|
ToolMetadata
|
Tool metadata. |
required |
Source code in provide/foundation/tools/installer.py
ToolMetadata
¶
Metadata about a tool version.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Tool name (e.g., "terraform"). |
version |
str
|
Version string (e.g., "1.5.0"). |
platform |
str
|
Platform identifier (e.g., "linux", "darwin"). |
arch |
str
|
Architecture (e.g., "amd64", "arm64"). |
checksum |
str | None
|
Optional checksum for verification. |
signature |
str | None
|
Optional GPG/PGP signature. |
download_url |
str | None
|
URL to download the tool. |
checksum_url |
str | None
|
URL to download checksums file. |
install_path |
Path | None
|
Where the tool is/will be installed. |
env_vars |
dict[str, str]
|
Environment variables to set. |
dependencies |
list[str]
|
Other tools this depends on. |
executable_name |
str | None
|
Name of the executable file. |
VersionResolver
¶
Resolve version specifications to concrete versions.
Supports: - "latest": Most recent stable version - "latest-beta": Most recent pre-release - "~1.2.3": Patch version range - "^1.2.3": Minor version range - "1.2.*": Wildcard matching - Exact versions
Initialize version resolver with pattern cache.
Source code in provide/foundation/tools/resolver.py
Functions¶
compare_versions
¶
Compare two versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v1
|
str
|
First version. |
required |
v2
|
str
|
Second version. |
required |
Returns:
| Type | Description |
|---|---|
int
|
-1 if v1 < v2, 0 if equal, 1 if v1 > v2. |
Source code in provide/foundation/tools/resolver.py
get_latest_any
¶
get_latest_prerelease
¶
Get latest pre-release version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Latest pre-release version, or None if no pre-releases. |
Source code in provide/foundation/tools/resolver.py
get_latest_stable
¶
Get latest stable version (no pre-release).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Latest stable version, or None if no stable versions. |
Source code in provide/foundation/tools/resolver.py
is_prerelease
¶
Check if version is a pre-release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if version appears to be pre-release. |
Source code in provide/foundation/tools/resolver.py
parse_version
¶
Parse version string into numeric components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version string. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
List of numeric version components. |
Source code in provide/foundation/tools/resolver.py
resolve
¶
Resolve a version specification to a concrete version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
str
|
Version specification. |
required |
available
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Resolved version string, or None if not found. |
Source code in provide/foundation/tools/resolver.py
resolve_caret
¶
Resolve caret range (^1.2.3 means >=1.2.3 <2.0.0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str
|
Base version without caret. |
required |
available
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Best matching version, or None if no match. |
Source code in provide/foundation/tools/resolver.py
resolve_tilde
¶
Resolve tilde range (~1.2.3 means >=1.2.3 <1.3.0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str
|
Base version without tilde. |
required |
available
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Best matching version, or None if no match. |
Source code in provide/foundation/tools/resolver.py
resolve_wildcard
¶
Resolve wildcard pattern (1.2.* matches any 1.2.x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Version pattern with wildcards. |
required |
available
|
list[str]
|
List of available versions. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Best matching version, or None if no match. |
Source code in provide/foundation/tools/resolver.py
Functions¶
get_tool_manager
¶
Get a tool manager instance from the global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name or alias. |
required |
config
|
BaseConfig
|
Configuration object. |
required |
Returns:
| Type | Description |
|---|---|
BaseToolManager | None
|
Tool manager instance, or None if not found. |
Source code in provide/foundation/tools/registry.py
get_tool_registry
¶
Get the global tool registry instance.
Returns:
| Type | Description |
|---|---|
ToolRegistry
|
Tool registry instance. |
Source code in provide/foundation/tools/registry.py
register_tool_manager
¶
register_tool_manager(
name: str,
manager_class: type[BaseToolManager],
aliases: list[str] | None = None,
) -> None
Register a tool manager with the global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name. |
required |
manager_class
|
type[BaseToolManager]
|
Tool manager class. |
required |
aliases
|
list[str] | None
|
Optional aliases. |
None
|