o
    xi"                     @  s   d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ ddlmZ ddlmZ h dZd%ddZd&ddZd'ddZd(d#d$ZdS ))zUtilities for the agent.    )annotations)AnyN)Api)is_docker_installed)LaunchError   )AbstractBuilder)AbstractEnvironment)AbstractRegistry)AbstractRunner>   vertex	sagemaker
kuberneteslocal-processlocal-containerconfigdict[str, Any] | Nonereturnr	   c                 C  s   | sddl m} | S | d}|std|dkr%ddl m} || S |dkr4ddlm} || S |dkrCdd	lm} || S |d
krRddl	m
} || S td| )a  Create an environment from a config.

    This helper function is used to create an environment from a config. The
    config should have a "type" key that specifies the type of environment to
    create. The remaining keys are passed to the environment's from_config
    method. If the config is None or empty, a LocalEnvironment is returned.

    Arguments:
        config (Dict[str, Any]): The config.

    Returns:
        Environment: The environment constructed.
    r   )LocalEnvironmenttypezICould not create environment from config. Environment type not specified!localawsAwsEnvironmentgcpGcpEnvironmentazure)AzureEnvironmentz8Could not create environment from config. Invalid type: )environment.local_environmentr   getr   from_configenvironment.aws_environmentr   environment.gcp_environmentr   environment.azure_environmentr   )r   r   env_typer   r   r    r&   K/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/launch/loader.pyenvironment_from_config   s.   




r(   environmentr
   c                 C  s   | sddl m} | S td | d}|du s|dkr&ddl m} | S |dkr5ddlm} || S |d	krDdd
lm	} || S |dkrSddl
m} || S td| )an  Create a registry from a config.

    This helper function is used to create a registry from a config. The
    config should have a "type" key that specifies the type of registry to
    create. The remaining keys are passed to the registry's from_config
    method. If the config is None or empty, a LocalRegistry is returned.

    Arguments:
        config (Dict[str, Any]): The registry config.
        environment (Environment): The environment of the registry.

    Returns:
        The registry if config is not None, otherwise None.

    Raises:
        LaunchError: If the registry is not configured correctly.
    r   )LocalRegistrya  The `registry` block of the launch agent config is being deprecated. Please specify an image repository URI under the `builder.destination` key of your launch agent config. See https://docs.wandb.ai/guides/launch/setup-agent-advanced#agent-configuration for more information.r   Nr   ecr)ElasticContainerRegistrygcr)GoogleArtifactRegistryacr)AzureContainerRegistryz>Could not create registry from config. Invalid registry type: )registry.local_registryr*   wandbtermwarnr    #registry.elastic_container_registryr,   r!   !registry.google_artifact_registryr.   !registry.azure_container_registryr0   r   )r   r)   r*   registry_typer,   r.   r0   r&   r&   r'   registry_from_configF   s,   



r8   registryr   c                 C  s   | st  rddlm} |i ||S ddlm} |i ||S | d}|du r,td|dkr=ddlm} || ||S |dkrNdd	lm	} || ||S |d
kr_ddlm} || ||S td| )a  Create a builder from a config.

    This helper function is used to create a builder from a config. The
    config should have a "type" key that specifies the type of builder to import
    and create. The remaining keys are passed to the builder's from_config
    method. If the config is None or empty, a default builder is returned.

    The default builder will be a DockerBuilder if we find a working docker cli
    on the system, otherwise it will be a NoOpBuilder.

    Arguments:
        config (Dict[str, Any]): The builder config.
        registry (Registry): The registry of the builder.

    Returns:
        The builder.

    Raises:
        LaunchError: If the builder is not configured correctly.
    r   )DockerBuilder)NoOpBuilderr   Nz@Could not create builder from config. Builder type not specifieddockerkaniko)KanikoBuildernoopz<Could not create builder from config. Invalid builder type: )
r   builder.docker_builderr:   r!   builder.noopr;   r    r   builder.kaniko_builderr>   )r   r)   r9   r:   r;   builder_typer>   r&   r&   r'   builder_from_config}   s2   
rD   runner_namestrapir   runner_configdict[str, Any]r   c              
   C  sD  | r| dv rddl m} |||||S | dkr"ddlm} |||S | dkrVddlm} t||sIz| }W n tyH } ztd|d	}~ww dd
l	m
}	 |	||||S | dv rddlm}
 t||
s}z|
 }W n ty| } ztd|d	}~ww ddlm} |||||S | dkrddlm} |||||S td|  )a`  Create a runner from a config.

    This helper function is used to create a runner from a config. The
    config should have a "type" key that specifies the type of runner to import
    and create. The remaining keys are passed to the runner's from_config
    method. If the config is None or empty, a LocalContainerRunner is returned.

    Arguments:
        runner_name (str): The name of the backend.
        api (Api): The API.
        runner_config (Dict[str, Any]): The backend config.

    Returns:
        The runner.

    Raises:
        LaunchError: If the runner is not configured correctly.
    )r   r   r   )LocalContainerRunnerr   )LocalProcessRunnerr   r   zUCould not create Sagemaker runner. Environment must be an instance of AwsEnvironment.N)SageMakerRunner)r   z
gcp-vertexr   zRCould not create Vertex runner. Environment must be an instance of GcpEnvironment.)VertexRunnerr   )KubernetesRunnerz:Could not create runner from config. Invalid runner name: )runner.local_containerrJ   runner.local_processrK   r"   r   
isinstancefrom_defaultr   runner.sagemaker_runnerrL   r#   r   runner.vertex_runnerrM   runner.kubernetes_runnerrN   )rE   rG   rH   r)   r9   rJ   rK   r   erL   r   rM   rN   r&   r&   r'   runner_from_config   sT   


rW   )r   r   r   r	   )r   r   r)   r	   r   r
   )r   r   r)   r	   r9   r
   r   r   )rE   rF   rG   r   rH   rI   r)   r	   r9   r
   r   r   )__doc__
__future__r   typingr   r2   wandb.apis.internalr   wandb.dockerr   wandb.sdk.launch.errorsr   builder.abstractr   environment.abstractr	   registry.abstractr
   runner.abstractr   WANDB_RUNNERSr(   r8   rD   rW   r&   r&   r&   r'   <module>   s     
	
,
7;