nat.registry_handlers.package_utils#
Attributes#
Functions#
|
Return the first top-level module name for a given distribution name. |
|
Extract the base package name from a requirement string. |
|
Resolve package extras to their actual package dependencies. |
|
Extract dependency names from pyproject.toml with extras properly resolved. |
|
Get all installed distributions. This is an expensive operation and should be cached. |
|
Try to find the correct distribution name for a given package name. |
|
Get transitive dependencies from a list of Python distribution names. |
|
Get all unique transitive dependencies from a list of Python distribution names. |
|
Builds a Python .whl for the specified package and saves to disk, sets self._whl_path, and returned as bytes. |
Loads discovery metadata for all registered NAT components included in this Python package. |
|
|
Builds a complete NeMo Agent toolkit Artifact that can be published for discovery and reuse. |
Module Contents#
- logger#
- get_module_name_from_distribution(distro_name: str) str | None #
Return the first top-level module name for a given distribution name.
- parse_requirement(requirement: str) str #
Extract the base package name from a requirement string.
This function extracts only the package name, ignoring extras, version specifiers, and environment markers.
- Args:
requirement (str): A requirement string like ‘numpy>=1.20.0’ or ‘requests[security]~=2.28.0’
- Returns:
str: The base package name (e.g., ‘numpy’ from ‘numpy>=1.20.0’, ‘requests’ from ‘requests[security]~=2.28.0’)
- resolve_extras_to_packages( ) set[str] #
Resolve package extras to their actual package dependencies.
- Args:
package_name (str): The base package name (e.g., ‘nvidia-nat’) extras (list[str]): List of extra names (e.g., [‘langchain’, ‘telemetry’])
- Returns:
set[str]: Set of additional package names that the extras resolve to (e.g., {‘nvidia-nat-langchain’, ‘nvidia-nat-opentelemetry’, ‘nvidia-nat-phoenix’, ‘nvidia-nat-weave’, ‘nvidia-nat-ragaai’})
- extract_dependencies_with_extras_resolved(
- pyproject_path: str,
Extract dependency names from pyproject.toml with extras properly resolved.
This function not only extracts the base package names but also resolves any extras (e.g., package[extra1,extra2]) to their actual package dependencies.
- Args:
pyproject_path (str): Path to the pyproject.toml file
- Returns:
set[str]: Set of all dependency names including those resolved from extras
- Example:
For a dependency like “nat[langchain,telemetry]~=1.2”, this will return: {‘nvidia-nat’, ‘nvidia-nat-langchain’, ‘nvidia-nat-opentelemetry’, ‘nvidia-nat-phoenix’, …}
- Raises:
FileNotFoundError: If the pyproject.toml file doesn’t exist ValueError: If the file cannot be parsed
- get_distributions() list[importlib.metadata.Distribution] #
Get all installed distributions. This is an expensive operation and should be cached.
- find_distribution_name(name: str) str | None #
Try to find the correct distribution name for a given package name.
Uses dynamic discovery through importlib.metadata to find distributions that provide the requested module/package name.
- Args:
name (str): Package name to search for.
- Returns:
str | None: The correct distribution name if found, None otherwise.
- get_transitive_dependencies( ) dict[str, set[str]] #
Get transitive dependencies from a list of Python distribution names.
This function recursively resolves all dependencies for the given distribution names, returning a mapping of each package to its complete set of transitive dependencies. This is useful when publishing plugins to remote registries that contain with nested dependencies, ensuring that all dependencies are included in the Artifact’s metadata.
- Args:
distribution_names (list[str]): List of Python distribution names (package names) to analyze.
- Returns:
dict[str, set[str]]: Dictionary mapping each distribution name to its set of transitive dependencies. The dependencies include both direct and indirect dependencies.
- get_all_transitive_dependencies( ) set[str] #
Get all unique transitive dependencies from a list of Python distribution names.
Returns a flattened set of all unique dependencies across all the provided distribution names. This is useful when publishing plugins to remote registries that contain with nested dependencies, ensuring that all dependencies are included in the Artifact’s metadata.
- Args:
distribution_names: List of Python distribution names (package names) to analyze
- Returns:
set[str]: Set of all unique transitive dependency names
- build_wheel(
- package_root: str,
Builds a Python .whl for the specified package and saves to disk, sets self._whl_path, and returned as bytes.
- Args:
package_root (str): Path to the local package repository.
- Returns:
WheelData: Data model containing a built python wheel and its corresponding metadata.
- build_package_metadata(
- wheel_data: nat.registry_handlers.schemas.package.WheelData | None,
Loads discovery metadata for all registered NAT components included in this Python package.
- Args:
wheel_data (WheelData): Data model containing a built python wheel and its corresponding metadata.
- Returns:
dict[ComponentEnum, list[typing.Union[dict, DiscoveryMetadata]]]: List containing each components discovery metadata.
- build_artifact(
- package_root: str,
Builds a complete NeMo Agent toolkit Artifact that can be published for discovery and reuse.
- Args:
package_root (str): Path to root of python package
- Returns:
Artifact: A publishable Artifact containing package wheel and discovery metadata.
- build_aiq_artifact#