
                         l   S r SSKJr  SSKJr  SSKJr  SSKrSSK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  \R,                  " \R.                  R0                  \R.                  R2                  \R.                  R4                  5       " S S\R6                  5      5       rg)z.Command to run a training application locally.    )absolute_import)division)unicode_literalsN)base)flags)
local_util)
validation)build)run)log)filesc                   X    \ rS rSrSr\R                  " S5      SS.r\S 5       r	S r
Srg	)
Create"   ziRun a custom training locally.

Packages your training code into a Docker image and executes it locally.
aI            {description}

          You should execute this command in the top folder which includes all
          the code and resources you want to pack and run, or specify the
          'work-dir' flag to point to it. Any other path you specified via flags
          should be a relative path to the work-dir and under it; otherwise it
          will be unaccessible.

          Supposing your directories are like the following structures:

            /root
              - my_project
                  - my_training
                      - task.py
                      - util.py
                      - setup.py
                  - other_modules
                      - some_module.py
                  - dataset
                      - small.dat
                      - large.dat
                  - config
                  - dep
                      - foo.tar.gz
                  - bar.whl
                  - requirements.txt
              - another_project
                  - something

          If you set 'my_project' as the package, then you should
          execute the task.py by specifying "--script=my_training/task.py" or
          "--python-module=my_training.task", the 'requirements.txt' will be
          processed. And you will also be able to install extra packages by,
          e.g. specifying "--extra-packages=dep/foo.tar.gz,bar.whl" or include
          extra directories, e.g. specifying "--extra-dirs=dataset,config".

          If you set 'my_training' as the package, then you should
          execute the task.py by specifying "--script=task.py" or
          "--python-module=task", the 'setup.py' will be processed. However, you
          won't be able to access any other files or directories that are not in
          'my_training' folder.

          See more details in the HELP info of the corresponding flags.
          a            To execute an python module with required dependencies, run:

            $ {command} --python-module=my_training.task --executor-image-uri=gcr.io/my/image --requirements=pandas,scipy>=1.3.0

          To execute a python script using local GPU, run:

            $ {command} --script=my_training/task.py --executor-image-uri=gcr.io/my/image --gpu

          To execute an arbitrary script with custom arguments, run:

            $ {command} --script=my_run.sh --executor-image-uri=gcr.io/my/image -- --my-arg bar --enable_foo

          To run an existing container training without building new image, run:

            $ {command} --executor-image-uri=gcr.io/my/custom-training-image
          )DESCRIPTIONEXAMPLESc                 0    [         R                  " U 5        g )N)r   AddLocalRunCustomJobFlags)parsers    'lib/surface/ai/custom_jobs/local_run.pyArgsCreate.Argsl   s    	##F+    c                    [         R                  " U5      n[        R                  " UR                  5         [
        R                  R                  SR                  UR                  5      5        UR                  =(       d    UR                  nUR                  (       a  [        R                  " UUR                  UR                  UR                  UR                  UR                   UR"                  UR$                  S9nUR&                  n[
        R                  R                  S5        [
        R                  R                  S5        [(        R*                  " UUR,                  UR.                  UR0                  S9  [
        R2                  R                  SR                  U5      5        [4        R6                  R9                  [4        R6                  R;                  UR                  UR                  =(       d    S5      5      u  pE[<        R>                  " U5      (       a.  [
        R                  R                  SR                  U5      5        S S S 5        g ! , (       d  f       g = f)	NzPackage is set to {}.)
base_imagehost_workdirmain_scriptpython_modulerequirementsextra_packages
extra_dirsoutput_image_namezA training image is built.zStarting to run ...)
image_name
enable_gpuservice_account_key	user_argsz<A local run is finished successfully using custom image: {}. z'Cleaned Python cache from directory: {}) r	   ValidateLocalRunArgsr   ChDirlocal_package_pathr   statusPrintformatexecutor_image_urir   scriptdocker_builder
BuildImager   r   r    r!   output_image_urinamedocker_runnerRunContainergpuservice_account_key_fileargsoutospathsplitjoinr   ClearPyCache)selfr8   executable_imagebuilt_image	cache_dir_s         r   Run
Create.Runp   s   **40D	T,,	-	jj.55d6M6MNO00CDOO	$//'00,,**.."335 '++

56	jj,-  %XX";;II	 
ggmm
H
O
O !
 WW]]
'',,t..0Ar
BDli		 	 	+	+

5<<YG	IC 
.	-	-s   HI
I* N)__name__
__module____qualname____firstlineno____doc__textwrapdedentdetailed_helpstaticmethodr   rD   __static_attributes__rF   r   r   r   r   "   sD     // , ,\aA-F , ,%Ir   r   )rK   
__future__r   r   r   r:   rL   googlecloudsdk.callioper   )googlecloudsdk.command_lib.ai.custom_jobsr   r   r	   $googlecloudsdk.command_lib.ai.dockerr
   r0   r   r4   googlecloudsdk.corer   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGABETAALPHACreateCommandr   rF   r   r   <module>r]      s    5 &  ' 	  ( ; @ @ H E # * D%%(($*;*;*@*@%%++-qIT qI-qIr   