Registry Explorer¶
hatch.registry_explorer
¶
Utilities for exploring a Hatch package registry.
This module provides functions to search and extract information from a Hatch registry data structure (see hatch_all_pkg_metadata_schema.json).
Functions¶
find_package(registry, package_name, repo_name=None)
¶
Find a package by name, optionally within a specific repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Dict[str, Any]
|
The registry data. |
required |
package_name
|
str
|
Name of the package to find. |
required |
repo_name
|
str
|
Name of the repository to search in. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: Package data if found, None otherwise. |
Source code in hatch/registry_explorer.py
find_package_version(pkg, version_constraint=None)
¶
Find a version dict for a package, optionally matching a version constraint.
This function uses a multi-step approach to find the appropriate version: 1. If no constraint is given, it returns the latest version 2. If that's not found, it falls back to the highest version number 3. For specific constraints, it sorts versions and checks compatibility
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
Dict[str, Any]
|
The package dictionary. |
required |
version_constraint
|
str
|
A version constraint string (e.g., '>=1.2.0'). Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: The version dict matching the constraint or latest version. |
Source code in hatch/registry_explorer.py
find_repository(registry, repo_name)
¶
Find a repository by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Dict[str, Any]
|
The registry data. |
required |
repo_name
|
str
|
Name of the repository to find. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: Repository data if found, None otherwise. |
Source code in hatch/registry_explorer.py
get_latest_version(pkg)
¶
Get the latest version string for a package dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
Dict[str, Any]
|
The package dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: Latest version string if available, None otherwise. |
Source code in hatch/registry_explorer.py
get_package_release_url(pkg, version_constraint=None)
¶
Get the release URI for a package version matching the constraint (or latest).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
Dict[str, Any]
|
The package dictionary. |
required |
version_constraint
|
str
|
A version constraint string (e.g., '>=1.2.0'). Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[str], Optional[str]]
|
Tuple[Optional[str], Optional[str]]: A tuple containing: - str: The release URI satisfying the constraint (or None) - str: The matching version string (or None) |
Source code in hatch/registry_explorer.py
list_packages(registry, repo_name=None)
¶
List all package names, optionally within a specific repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Dict[str, Any]
|
The registry data. |
required |
repo_name
|
str
|
Name of the repository to list packages from. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of package names. |
Source code in hatch/registry_explorer.py
list_repositories(registry)
¶
List all repository names in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
Dict[str, Any]
|
The registry data. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of repository names. |