sagemaker.core.utils.install_requirements#
CodeArtifact-aware pip requirements installer.
Reads CA_REPOSITORY_ARN from the environment and authenticates with
CodeArtifact before installing packages. Tries boto3 first (matching
sagemaker-training-toolkit), falls back to AWS CLI, and hard-fails
when the env var is set but neither mechanism is available.
- Can be used as:
An importable module:
configure_pip()— returns an authenticated pip index URL (orNone). Use when you need to build your own pip command with custom flags.install_requirements(path)— configures pip and runspip install -r. Use when you just want requirements installed.
from sagemaker.core.utils.install_requirements import configure_pip, install_requirements
A standalone script:
python install_requirements.py requirements.txt
Functions
|
Configure pip for CodeArtifact if |
|
Install pip requirements with optional CodeArtifact authentication. |
|
CLI entry point. |
Classes
|
Authentication method for CodeArtifact pip configuration. |
- class sagemaker.core.utils.install_requirements.CodeArtifactAuthMethod(value)[source]#
Bases:
EnumAuthentication method for CodeArtifact pip configuration.
- AUTO = 'auto'#
Try boto3 first, fall back to AWS CLI, hard-fail if neither is available.
- AWS_CLI = 'aws_cli'#
Use AWS CLI only. Fails if AWS CLI is not available.
- BOTO3 = 'boto3'#
Use boto3 only. Fails if boto3 is not available.
- sagemaker.core.utils.install_requirements.configure_pip(auth_method=CodeArtifactAuthMethod.AUTO)[source]#
Configure pip for CodeArtifact if
CA_REPOSITORY_ARNis set.- Parameters:
auth_method – Authentication mechanism to use. Defaults to
CodeArtifactAuthMethod.AUTO(try boto3 first, fall back to AWS CLI).- Returns:
An authenticated pip index URL (str) when boto3 succeeds,
Nonewhen AWS CLI was used (pip config modified globally), orNonewhenCA_REPOSITORY_ARNis not set.- Raises:
SystemExit – When
CA_REPOSITORY_ARNis set but the requested auth method is not available.ValueError – When the ARN format is invalid.
- sagemaker.core.utils.install_requirements.install_requirements(requirements_file='requirements.txt', python_executable=None, auth_method=CodeArtifactAuthMethod.AUTO)[source]#
Install pip requirements with optional CodeArtifact authentication.
- Parameters:
requirements_file – Path to the requirements file.
python_executable – Python executable to use for pip. Defaults to
sys.executable.auth_method – Authentication mechanism for CodeArtifact. Defaults to
CodeArtifactAuthMethod.AUTO.