
    U&                     T   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SS	K	Jr  SS
K	Jr  SSKJr   " S S\
R                   5      rS rS rS rSS jr                              SS jrSS jrSS jrSS jr\" / SQ5      rS rSS jrS rg)z#Utilities for ml versions commands.    )versions_api)models_util)uploads)labels_util)repeated)
exceptions)log)
properties)	resources)
console_ioc                       \ rS rSrSrSrg)InvalidArgumentCombinationError   z<Indicates that a given combination of arguments was invalid. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       9lib/googlecloudsdk/command_lib/ml_engine/versions_util.pyr   r      s    Dr   r   c                 V    [         R                  " XR                  R                  5      $ N)r   ParseCreateArgsversion_classLabelsValue)clientargss     r   ParseCreateLabelsr    #   s    		$	$T+?+?+K+K	LLr   c                 v    [         R                  " X R                  R                  UR	                  S5      5      $ )Nlabels)r   ProcessUpdateArgsLazyr   r   GetAttrThunk)r   
get_resultr   s      r   ParseUpdateLabelsr&   '   s3    		*	*
  ,,j.E.Eh.O
Q Qr   c                     [         R                  R                  U[        R                  R
                  R                  R                  U S.SS9$ )z9Parses a model/version ID into a version resource object.)
projectsIdmodelsIdzml.projects.models.versions)params
collection)r   REGISTRYParser
   VALUEScoreproject	GetOrFail)modelversions     r   ParseVersionr4   ,   sK    				!	!"))..66@@ / 
" 
0 0r   Nc                 F    U(       a  U$ U R                  XS9R                  $ )a  Waits for an operation if asyncronous flag is on.

Args:
  operations_client: api_lib.ml_engine.operations.OperationsClient, the client
    via which to poll
  op: Cloud ML Engine operation, the operation to poll
  asyncronous: bool, whether to wait for the operation or return immediately
  message: str, the message to display while waiting for the operation

Returns:
  The result of the operation if asyncronous is true, or the Operation message
      otherwise
message)WaitForOperationresponse)operations_clientopasyncronousr7   s       r   WaitForOpMayber=   7   s&     I		+	+B	+	@	I	IIr   c!                    U(       a   [         R                  " XE5      nUb  [        R
                  R                  S5        [        R                  " U5      n!U R                  UUUUU	UU
UUUUUUUUUUUUUUUUUUUUU S9n"U"R                  (       d  U(       a  [        S5      e[        U"S5      =(       a3    [        U"R                  S5      =(       a    U"R                  R                  n#U"R                  (       d  U#(       d  U(       d  [        S5      eU R                  U!U"5      n$[        UU$USS	9$ ! [         R                   a    [        S5      ef = f)
z<Create a version, optionally waiting for creation to finish.zPIf --origin is provided as a local path, --staging-bucket must be given as well.zExplanations reflect patterns in your model, but don't necessarily reveal fundamental relationships about your data population. See https://cloud.google.com/vertex-ai/docs/explainable-ai/limitations for more information.)pathdeployment_uriruntime_versionr"   descriptionmachine_type	frameworkpython_versionpackage_urisprediction_classaccelerator_configservice_accountexplanation_methodnum_integral_steps	num_pathsimagecommandcontainer_argsenv_varsportspredict_routehealth_route	min_nodes	max_nodesmetricscontainers_hiddenautoscaling_hiddenzgEither `--origin` must be provided or `deploymentUri` must be provided in the file given by `--config`.	containerrM   zlEither `--origin`, `--image`, or equivalent parameters in a config file (from `--config`) must be specified.z3Creating version (this might take a few minutes)...r<   r7   )r   UploadDirectoryIfNecessaryMissingStagingBucketExceptionr   r	   statusPrintr   
ParseModelBuildVersiondeploymentUrihasattrrY   rM   Creater=   )%versions_clientr:   
version_idr2   originstaging_bucketrA   config_filer<   r"   rC   rB   rD   rE   rG   rF   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   	model_refr3   	has_imager;   s%                                        r   rc   rc   J   s   D 11&If
 #JJ	 ! $$U+)((%#'+%++#!)+9 ) -': 
		#4
)	45 5 g{# 0A0A7(K   
		y9J
)	45 5 i1"	C
E Ek 00 + s   D2 2 Ec                     [        X25      n[        R                  " SR                  UR                  5      SS9  U R                  U5      n[        XSSR                  UR                  5      S9$ )Nz This will delete version [{}]...T)cancel_on_noFzDeleting version [{}]...rZ   )r4   r   PromptContinueformat
versionsIdDeleter=   )rd   r:   r3   r2   version_refr;   s         r   rp   rp      sk    U,+(//0F0FG k*"	(//0F0FG
I Ir   c                 :    [        X!5      nU R                  U5      $ r   )r4   Getrd   r3   r2   rq   s       r   Describeru      s    U,+			[	))r   c                 P    [         R                  " U5      nU R                  U5      $ r   )r   r_   List)rd   r2   ri   s      r   rw   rw      s#    $$U+)			i	((r   )autoScalingrB   manualScalingrequestLoggingConfigc                   ^ [         R                  R                  U R                  U5      nSn[	        TS5      (       a1  TR
                  (       a   U R                  TR
                  [        5      nTR                  =(       d    U(       a  UR                  OSn[        XT5      nSnU(       a1  [	        UR                  S5      (       a  UR                  R                  nSn	U(       a1  [	        UR                  S5      (       a  UR                  R                  n	Sn
U(       a1  [	        UR                  S5      (       a  UR                  R                  n
[        TSS5      nUc8  U(       a1  [	        UR                   S5      (       a  UR                   R"                  n[        TSS5      nUc8  U(       a1  [	        UR                   S	5      (       a  UR                   R$                  n/ S
Qn U R'                  UUUUU	U
UUS9nUR)                  USR+                  UR-                  5       5      S9R.                  $ ! [0        R2                   a=    [5        U4S jU 5       5      (       d  e [6        R8                  R;                  S5         gf = f)zUpdate the given version.NconfignodesminNodesmaxNodesbigquery_table_namebigqueryTableNamesampling_percentagesamplingPercentage)update_labelsclear_labelsremove_labelsrB   )manual_scaling_nodesauto_scaling_min_nodesauto_scaling_max_nodesr   r   zUpdating version [{}]r6   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )IsSpecified).0argr   s     r   	<genexpr>Update.<locals>.<genexpr>   s     9t$$s   !zNo update to perform.)r   CachedResultFromFuncrs   rb   r|   
ReadConfig_ALLOWED_UPDATE_YAML_FIELDSrB   r&   ry   r}   rx   r~   r   getattrrz   r   r   Patchr8   rn   Namer9   r   NoFieldsSpecifiedErroranyr	   r]   r^   )rd   r:   rq   r   r%   r3   rB   labels_updater   r   r   r   r   all_argsr;   s      `           r   Updater      sA   $$--;(* 'T8((02G   NGW%8%8+ $OF-..88"0066,,j99$0099,,j99$0099&;TB W""$729 29!66HH&;TB W""$82: 2:!66IIN(Q			155// 
 
1B --
+22;3C3C3EF . HHPQ 
	,	, 9999JJ,-	s   'H4 4AJJc                 :    [        X!5      nU R                  U5      $ r   )r4   
SetDefaultrt   s       r   r   r     s    U,+		#	#K	00r   c                     [         R                  " 5       R                  R                  nXR                  :w  a1  UR                  S5      (       d  [        SR                  U5      5      eg g )Nmlz=Machine type {0} is currently only supported with tensorflow.)r   GetMessagesModuleGoogleCloudMlV1VersionFrameworkValueValuesEnum
TENSORFLOW
startswithr   rn   )rD   rC   frameworks_enums      r   !ValidateFrameworkAndMachineTypeGar     sf    $$&==  ---

!
!$
'
'
)GNN	  ( .r   )FN)NNNNNNNNNNNNNNNNNNNNNNNNNNNNTTr   )r    googlecloudsdk.api_lib.ml_enginer   $googlecloudsdk.command_lib.ml_enginer   r   $googlecloudsdk.command_lib.util.argsr   r   googlecloudsdk.corer   r	   r
   r   googlecloudsdk.core.consoler   Errorr   r    r&   r4   r=   rc   rp   ru   rw   	frozensetr   r   r   r   r   r   r   <module>r      s    * : < 8 < 9 * # * ) 2j&6&6 
MQ
0J,  """!"A\E~I*
)
 ( )  9Qx1
r   