
    5i                        d dl mZmZmZmZ d dlZ ej                  ej                          ej                  d      j                  ej                         d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dlZd dlZddlmZ d dlmZmZ d d	l m!Z!m"Z" dd
l#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6  ejn                  d      Z8 G d de9      Z:d Z;d Z<d Z=d,dZ>d Z?d-dZ@d ZAd.dZBd-dZCd ZDd-d ZEd! ZF	 	 	 	 d/d"ZG	 	 d0d#ZH	 	 	 	 	 	 d1d$ZId% ZJd& ZKd' ZLd( ZMd) ZNd* ZOePd+k(  r eO        yy)2    )print_functionunicode_literalsdivisionabsolute_importN)levelzurllib3.connectionpool)datetime   )logger)build_pipeline_with_npiprepare_nextflow)get_resources_subpathis_importer_job)json_load_raise_on_duplicates)resolve_pathcheck_folder_existsResolutionErroris_container_id)LocalCompleter)APP_CATEGORIES)err_exit)BOLD)USING_PYTHON2
basestring)process_extra_argszUploads a DNAnexus App.)descriptionc                       e Zd Zd Zd Zy)DXSyntaxErrorc                     || _         y Nmessage)selfr!   s     {/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/scripts/dx_build_app.py__init__zDXSyntaxError.__init__8   s	        c                     | j                   S r   r    )r"   s    r#   __str__zDXSyntaxError.__str__:   s    ||r%   N)__name__
__module____qualname__r$   r'    r%   r#   r   r   7   s    r%   r   c                     d| v r&dt        j                         j                  d      z   S dt        j                         j                  d      z   S )N+z.build.z%Y%m%d.%H%Mz+build.)r   todaystrftime)versions    r#   _get_timestamp_version_suffixr1   =   sC    
g~8>>+44]CCC8>>+44]CCCr%   c                 (   	 t         j                  j                  t         j                  j                  | d            r8t	        j
                  g d|       j                         d d }d|v rd|z   S d|z   S 	 t        |      S #  Y t        |      S xY w)Nz.git)gitz	rev-parseHEAD)cwd   r-   z.git.z+git.)ospathexistsjoin
subprocesscheck_outputstripr1   )src_dirr0   abbrev_sha1s      r#   _get_version_suffixr@   C   s    77>>"'',,w78$112NT[\bbdegfghK g~,,,, 9 )11(11s   A/B 2B Bc                 @    t         j                  j                  |       S r   )dxpyexecutable_builderget_parsed_destination)dest_strs    r#   parse_destinationrF   V   s    ""99(CCr%   c           
         | j                  dg       D ]z  }|j                  dg       D ]a  }d|v ro	 t        j                  j                  |d   ddi      }d|d   vr*|r(t	        j
                  dj                  |d   	             d|v r	 t        |d   |d   d       d|v r-|d   j                  d      r	 t        j                  |d         }d|v st%        |d   t&              sd|d   v st%        |d   d   t&              r6d|d   d   v s	 t        j                  j                  |d   d   d          t%        |d   d   t(              s-|d   d   j                  d      sF	 t        j                  |d   d         }d } y# t        j                  j                  $ rB}|j                  d
k(  r(t	        j
                  dj                  |d   	             Y d}~dd}~ww xY w# t        $ r7}t	        j
                  dj                  |d   |d                Y d}~d}~ww xY w# t        j                  j                  $ rL}|j                  d
k(  r2t        j                  j                  dj                  |d   	            Y d}~d}~wt         $ r-}t        j                  j                  t#        |            d}~ww xY w# t        j                  j                  $ rH}|j                  d
k(  r.t	        j
                  dj                  |d   d   d   	             Y d}~d}~ww xY w# t        j                  j                  $ rO}|j                  d
k(  r5t        j                  j                  dj                  |d   d   	            Y d}~}d}~wt         $ r-}t        j                  j                  t#        |            d}~ww xY w)z
    Examines the specified dxapp.json file and warns about any
    violations of suggestions guidelines.

    :raises: AppBuilderException for data objects that could not be found
    	inputSpecsuggestionsprojectpermissionsTPUBLICzProject {name} NOT PUBLIC!name)rM   i  zBSuggested project {name} does not exist, or not accessible by userNr8    z5Folder {path} could not be found in project {project})r8   rJ   z$dnanexus_link)zfile-zrecord-z*Suggested object {name} could not be foundvalue)getrB   apiproject_describer
   warnformat
exceptions
DXAPIErrorcoder   r   
startswithdescribeapp_builderAppBuilderException	Exceptionstr
isinstancedictr   )app_jsonpublishinput_field
suggestionrJ   ednanexus_links          r#   _check_suggestionsrf   Y   s     ||K4 1S%//-< 0	SJJ&B"hh77
98MP]_cOdeGw}'=='$@$G$GWU[_$G$]^
 Z'^+Jy,A:fCUWYZ  :-./::;OPK(,jAQ6R(S *$Jw4G)N#z''::!*W"56F"GN$
7(;<L(MMi $ 9 9*W:MN^:_`i:j k
 $Jw$78H$I:V%g./?@KKL`aS04j>QRb>c0dS0	S1S 11 Bvv}$h$o$o*4Y*? %p %A BB + ^$[$b$b*4V*<jQZF[ %c %] ^ ^^  ??55 H66S="&"2"2"F"F L S S)34D)E !T !G#H H ) % K"..BB3q6JJK $(??#=#= i#$66S=$*KK0t0{0{6@6IJZ6[\e6f 1| 1h %ii $(??#=#= Y#$66S=*.*:*:*N*N(T([([1;G1DEU1V )\ )X+Y %Y $1 $- S&*&6&6&J&J3q6&R RSs   AFG49H7(K0L?G1/7G,,G14	H4=,H//H47KAJK'(KKL<4=L77L<?OAN&&O2(OOc                    d }t        j                  t        |             }t        j                  j                  t        j                  j                  t        j                  j                  |                   }|dk(  rd|vrt        j                  d       d|v r1|d   j                  d      r2t        j                  d|d   d       nt        j                  d	        |t        j                  j                  |             }d
|v ri|r/t        j                  j                  dj                  |             |d
   j                         j                  d      s-t        j                  d       n|t        j                  d       d|v r|d   D ]  }|t         vrt        j                  d|d       |dk(  r4d|v r0|d   j                  d      st        j                  d|d   d       |dk(  scd|v sh|d   j                  d      r}t        j                  d|d   d        d|v r|d   |d   j#                         k7  rt        j                  d|d   d       ||d   k7  rtt        j                  j                  |       j%                  d      sF|j%                  d      s5t        j                  d|d   d|d       nt        j                  d        d!|v rHt        j&                  j(                  j+                  |d!         st        j                  d"|d!   d#       d$|v rNt-        |d$         D ]<  \  }}t/        j*                  d%|d         r t        j0                  d&||d   fz         > nt        j                  d'       d(|v rNt-        |d(         D ]<  \  }}	t/        j*                  d%|	d         r t        j0                  d)||	d   fz         > yt        j                  d*       y)+z
    Examines the specified dxapp.json file and warns about any
    violations of app guidelines.

    Precondition: the dxapp.json file exists and can be parsed.
    c                     dD ]a  }t         j                  j                  t         j                  j                  | |            sAt         j                  j                  | |      c S  y )N)z	README.mdz	Readme.mdz	readme.md)r7   r8   r9   r:   )dirnamebasenames     r#   _find_readmez_lint.<locals>._find_readme   sJ    ? 	7Hww~~bggll7H=>ww||GX66	7 r%   apptitlezIapp is missing a title, please add one in the "title" field of dxapp.jsonsummary.z	summary "z1" should be a short phrase not ending in a periodzMapp is missing a summary, please add one in the "summary" field of dxapp.jsonr   zDescription was provided both in Readme.md and in the "description" field of {file}. Please consolidate content in Readme.md and remove the "description" field.filezQ"description" field should be written in complete sentences and end with a periodNz<app is missing a description, please supply one in README.md
categorieszapp has unrecognized category ""ImportImporterztitle "z" should end in "Importer"ExportExporterz" should end in "Exporter"rM   zname "z" should be all lowercasez/tmpz
app name "z'" does not match containing directory "zGapp is missing a name, please add one in the "name" field of dxapp.jsonr0   z
"version" z4 should be semver compliant (e.g. of the form X.Y.Z)rH   z^[a-zA-Z_][0-9a-zA-Z_]*$zDinput %d has illegal name "%s" (must match ^[a-zA-Z_][0-9a-zA-Z_]*$)zdxapp.json contains no input specification (inputSpec). Your applet will not be usable as an app, runnable from the GUI, or composable using workflows.
outputSpeczEoutput %d has illegal name "%s" (must match ^[a-zA-Z_][0-9a-zA-Z_]*$)zdxapp.json contains no output specification (outputSpec). Your applet will not be usable as an app, runnable from the GUI, or composable using workflows.)jsonloadopenr7   r8   rj   ri   abspathr
   rS   endswithrB   rZ   r[   rT   r=   r   lowerrX   rC   GLOBAL_EXEC_VERSION_REmatch	enumeratereerror)
dxapp_json_filenamemoderk   app_specri   readme_filenamecategoryirb   output_fields
             r#   _lintr      s    yy123Hggrwwrww?R/STUGu}("KKcd 	"++C0^fgp^qstKKgh&rww7J'KLH$&&:: <@@FL_@`b b M*002;;C@op&Z[8#$\2 b>1KK RSx'(*8G3D3M3Mj3YXV]M^$`ax'(*8G3D3M3Mj3YXV]M^$`ab Fx/5577KKx?OQRhv&&rww?R/S/^/^_e/fov  pB  pB  CF  pGKKT\]cTdfmno]^H&&==CCHYDWXKK^fgp^qst h'(=> 	@NA{886F8KLcghjuv|j}f~~	@ 	 Q 	Rx(,)?@ 	BOA|886V8LMdhikwx~k  hA  A  B	B 	 Q 	Rr%   c                 <   |dk(  sd|v rd}n|dk(  rd}nt        d      t        t        j                  j	                  ||      d      5 }|j                  |        ddd       t        t        j                  j	                  ||      |||	       y# 1 sw Y   7xY w)
z
    Checks that the code whose text is in CODE parses as LANG.

    Raises DXSyntaxError if there is a problem and "enforce" is True.
    	python2.7python3zinlined_code_from_dxapp_json.pybashzinlined_code_from_dxapp_json.shz5lang must be one of "python2.7", "python3", or "bash"wNoverride_langenforce)
ValueErrorr{   r7   r8   r:   write_check_file_syntax)rW   langtemp_dirr   temp_basenameofiles         r#   _check_syntaxr      s     {i4/9	9PQQ	bggll8]3S	9 UDrww||Hm<hVZdkl s   
BBc                     t        |t              r|S t        |t              r|j                  d      S t	        dj                  t        |                   | )Nzutf-8z7The error message is neither string nor bytes, it is {})r^   r]   bytesdecodeprintrT   type)rd   r!   s     r#   _error_message_to_stringr      sJ    '3	GU	#~~g&& 	GNNtT[}]^r%   c                 d   fd}d }d}|dk(  r	t         r|}n~|dk(  r	t         s|}np|dk(  r|}nh| j                  d      rB|}d}t        | |      5 }	|	j                         }
d|
v rt         rd	|
v rt         sd}d
}ddd       n| j                  d      r|}nyt        |        	  ||        y# 1 sw Y   xY w# t        j
                  $ r}t        | dz   t        j                         t        ||j                        }|j                  d      j                  d      D ]/  }t        d|j                  d      z   t        j                         1 |rt        | dz         Y d}~yd}~wt        j                   $ r}|r!t        d| z   dz   t        j                         t        | dz   t        j                         t        ||j"                        }t        d|j                         z   t        j                         |r#t        |j"                  j                               Y d}~yd}~ww xY w)z
    Checks that the code in FILENAME parses, attempting to autodetect
    the language if necessary.

    Raises IOError if the file cannot be read.

    Raises DXSyntaxError if there is a problem and "enforce" is True.
    c                 V   t         j                  j                  t         j                  j                  |       dz         }	 t	        j
                  | |d       	 t        j                  |       y # t        $ r Y y w xY w# 	 t        j                  |       w # t        $ r Y w w xY wxY w)Nz.pycT)cfiledoraise)r7   r8   r:   rj   
py_compilecompileunlinkOSError)filenamepyc_pathr   s     r#   check_pythonz(_check_file_syntax.<locals>.check_python  s     77<<"''*:*:8*Dv*MN	xxF		(# 		(# sB   B A2 2	A>=A>B(BB(	B%"B($B%%B(c                     t        j                         dk(  rt        j                  d       y t	        j
                  dd| gt        j                         y )NWindowszDSkipping bash syntax check due to unavailability of bash on Windows.z	/bin/bashz-n)stderr)platformsystemloggingrS   r;   r<   STDOUT)r   s    r#   
check_bashz&_check_file_syntax.<locals>.check_bash  s@    ??	)LLZ\ ##[$$A*J[J[\r%   Fr   r   r   z.pyrpython2TNz.shz( has a syntax error! Interpreter output:rp   
z  z has a syntax errorz
Unsure if zI is using Python 2 or Python 3, the following error might not be relevant)r   r}   r{   readliner;   CalledProcessErrorr   sysr   r   outputr=   splitrstripr   r   PyCompileErrormsg)r   r   r   r   r   r   python_unsure
checker_fn	read_modef
first_linerd   errmsglines    `            r#   r   r     s   ] M#!
	)	#M!
	&	 
			5	!!
 	(I& 	%!J*,]*, $	% 	% 
		5	!
 	 	N/8#	% 	%$ (( BhCC#**U)!QXX6LL&,,T2 	=D$T**<	=+@ @AA $$ /,),ww  B  I  I  JhCC#**U)!QUU3dV\\^##**5.. /s2   )B-$B9 -B69H/BE''H/=B(H**H/c           
         t        t        j                  j                  | d      |       t	        j
                  t        t        j                  j                  | d                  }d|v rHd|d   vrt        j                  j                  d      d|d   vrt        j                  j                  d      d|d   vrt        j                  j                  d      |d   d   d	v rd
|d   v rZt        j                  j                  t        j                  j                  | |d   d
               }	 t        |||d   d   |       n#d|d   v r	 t        |d   d   |d   d   ||       t        |      }|D ]U  }t        j                  j                  t        j                  j                  | |            }		 t        |	||d   d   |       W d|d   v rt!        |d   d   t"              st        j                  j                  d      t%        d |d   d   D              st        j                  j                  d      t'        d |d   d   D              rXt!        |j)                  d      t*              rd|d   vr2dj                  g d      }
t        j                  j                  |
      d|v rt!        |d   t"              rt!        |d   t,              rt        j                  j                  d       |d   D ]M  }|d!k7  s	t!        |t,              rt/        j0                  d"|      r0t        j                  j                  d#       d$|v r&d%}|d&z  }t        j                  j                  |      g }t        j2                  t        j                  j                  t        j                  j                  | d'                  D ]L  \  }}}|D ]A  }|j5                  d(      r	 t        t        j                  j                  ||      |d)       C N |rbt9        |      d+k(  r|d,   n5|d,   d-z   t;        t9        |      d+z
        z   d.z   t9        |      d/kD  rd0nd1z   }t=        j>                  |d2       yy# t        $ r*}t        j                  j                  d|d|      d}~wt        $ r$ t        j                  j                  d|d      w xY w# t        $ r  t        j                  j                  d      w xY w# t        $ r*}t        j                  j                  d|	d|      d}~wt        $ r# t        j                  j                  d|z        w xY w# t        $ rH}t        j                  j                  d*t        j                  j                  ||      d|      d}~wt        $ r3 |j7                  t        j                  j                  ||             Y "w xY w)3xPerforms syntax and lint checks on the app source.

    Precondition: the dxapp.json file exists and can be parsed.
    
dxapp.jsonrunSpecinterpreterz)runSpec.interpreter field was not presentdistributionz2Required field runSpec.distribution is not presentreleasez-Required field runSpec.release is not present)r   r   r   rq   r   zCould not open runSpec.file=z. The problem was: NzEntry point file zZ has syntax errors, see above for details. Rerun with --no-check-syntax to proceed anyway.rW   r   znCode in runSpec.code has syntax errors, see above for details. Rerun with --no-check-syntax to proceed anyway.z(Could not open cluster bootstrap script z|Code in cluster bootstrapScript %r has syntax errors, see above for details. Rerun with --no-check-syntax to proceed anyway.execDependsz\Expected runSpec.execDepends to be an array. Rerun with --no-check-syntax to proceed anyway.c              3   <   K   | ]  }t        |t                y wr   )r^   r_   .0deps     r#   	<genexpr>z._verify_app_source_dir_impl.<locals>.<genexpr>  s     [z#t,[s   zfExpected runSpec.execDepends to be an array of hashes. Rerun with --no-check-syntax to proceed anyway.c              3   F   K   | ]  }|j                  d d      dk7    yw)package_manageraptN)rP   r   s     r#   r   z._verify_app_source_dir_impl.<locals>.<genexpr>  s!     l#377,e4=ls   !accessnetworkr   )zXrunSpec.execDepends specifies non-APT dependencies, but no network access spec is given.zDAdd {"access": {"network": ["*"]}} to allow dependencies to install.z[See https://documentation.dnanexus.com/developer/apps/execution-environment#network-access.z/Rerun with --no-check-syntax to proceed anyway.authorizedUsersz0Expected authorizedUsers to be a list of stringsrL   z^(org-|user-)zcauthorizedUsers field contains an entry which is not either the string "PUBLIC" or a user or org IDpricingPolicyzG"pricingPolicy" at the top level is not accepted. It must be specified zCunder the "regionalOptions" field in all enabled regions of the app	resourcesz._Tz+Could not open file in resources directory    r   z and z other filer	   srN   z/ contained syntax errors, see above for details) r   r7   r8   r:   ry   rz   r{   rB   rZ   r[   r|   r   IOErrorr   r   '_get_all_cluster_bootstrap_script_namesr^   listallanyrP   r_   r   r   r   walkrX   appendlenr]   r   rS   )r>   r   r   r   manifestentry_point_filerd   cluster_bootstrap_scriptsr   abs_filenamer   thingerror_messagefiles_with_problemsdirpathdirnames	filenames	files_strs                     r#   _verify_app_source_dir_implr   O  s<   
 
"'',,w
-t4 yybggll7LABCHH 33""667bcc)!44""667kllHY//""667fggI}-1QQ),,#%77??277<<R[I\]cId3e#f F&'7QYZcQderQs  ~E  F 8I..q!(9"5f"=x	?RS`?acku|} )PPX(Y%5 J!wwrww||GX/NO	J&|'/5=i5H5W/68J HY//hy1-@$G&&::  <Z  [  [[8KM8Z[[&&::  <d  e  elR[I\]jIkll!(,,x"8$?9T\]eTfCf)) %G HC **>>sCCH$(#45t<
8TeKfhr@s""667ijj/0 	bE *UJ*GrxxXginOo&&::  <a  b  b	b ("c``22=AA (*WVa@b0c(d P$9! 	PH &&t,
P&rww||GX'FZ^_	PP(  /22E.F!.K'*RefgRhkrRruxy|  ~Q  zR  UV  zV  vW  SW  Zg  Sg  ru  vI  rJ  MN  rN  kn  TV  SW	IWX [  g**>>Qacdeg g$ F**>>  sC  @E  F  FF
 % q**>>  @p  q  qq  o**>>]iklmo o$ J**>>  @~  AI  @I  J  JJZ  **>>gx8!=  % P (..rww||GX/NOPs[   3R S# :T-,U/	S %R000S #)T	U,%T==/U,/	W:8AV;;;W:9W:c                 >   d| d   v r<| d   d   }|D ]/  }d||   v sd}|dz  }t         j                  j                  |       g }d| v rD| d   D ]<  }d| d   |   v s| d   |   d   }|D ]  }	 ||   d   d   }|j                  |       ! > |S # t        $ r Y 1w xY w)NsystemRequirementsr   clusterSpecz>"clusterSpec" in "runSpec.systemRequirements" is not accepted.zr It must be specified in "systemRequirements" under the "regionalOptions" field in all enabled regions of the app.regionalOptionsbootstrapScript)rB   rZ   r[   r   KeyError)r   sys_reqsentry_pointerr_msgscript_namesregionr   s          r#   r   r     s
   x	22I&';<# 	DK 55^  T  T&&::7CC		D LH$01 		!F#x0A'B6'JJ#$56v>?ST#+ !K!#+K#8#GHY#Z$++H5!		! 	 $ ! !s   .B	BBc                     t        j                  d      }	 t        | |||       t        j                  |       y# t        j                  |       w xY w)r   zdx-build_tmp)prefixr   N)tempfilemkdtempr   shutilrmtree)r>   r   r   r   s       r#   _verify_app_source_dirr    s@    
 ~6H #GXtWMhhs	   = Ac                 P   t         j                  j                  |       st        j	                  d| z         t         j                  j                  t         j                  j                  | d            s"t        j                  j                  d| z        t        t         j                  j                  | d            5 }	 t        |      cddd       S # t        $ r:}t        j                  j                  dt        |j                        z         d}~ww xY w# 1 sw Y   yxY w)zReturns the parsed contents of dxapp.json.

    Raises either AppBuilderException or a parser error (exit codes 3 or
    2 respectively) if this cannot be done.
    z%s is not a directoryr   zSDirectory %s does not contain dxapp.json: not a valid DNAnexus app source directoryNz)Could not parse dxapp.json file as JSON: )r7   r8   isdirparserr   r9   r:   rB   rZ   r[   r{   r   r\   r]   args)r>   app_descrd   s      r#   _parse_app_specr
    s     77==!,w6777>>"'',,w=>22  4I  LS  4S  T  	T	bggll7L1	2 rh	r0:r r  	r""667behijioioep7pqq	rr rs*    D
C	D5DDDD%c                    | dk(  rd}nd}t        |      }dddddd	}|d
   j                  d      }|dk(  r|d
   j                  dd      dk(  r|dz  }n||j                  |d      z  }t        j                         }i }|r||d<   nN|rL|rJ|d   }d }	 t        j
                  j                  d|d   z   |d      }|d|v s|s|t        ||      z   |d<   |r||d<   |sd|d<   |sd|d<   |sd|d<   |	sd|d<   d}d }d }| dk(  rCt        j                  }|rt        |      \  }}}|t        j                  d       |rHd |z   |d!<   n?| dk(  r:d"}	 i }d#|d<   |r||d$<   |
r|
|d%<   t        j
                  j                  |      d&   }	 t"        j$                  j'                  |      }t"        j$                  j)                  |d'      }t+        j,                  g d(|t*        j.                  )      }t1        |d*      5 }d+}d+}t3        j2                         }d} 	 |j5                         }!|j6                  j9                  d,      }"|!t;        |"      d+k(  rn|j=                  |"       |t;        |"      z  }t3        j2                         }#|#|z
  d-kD  r|#|z
  d.kD  rt>        j@                  jC                         rx|d+kD  rt>        j@                  j=                  d/       t>        j@                  j=                  d0jE                  ||d1z  2             t>        j@                  jG                          |#}n'| s%t>        j@                  j=                  d3|d4       d"} ?	 d d d        d+kD  rt>        j@                  j=                  d5       !d+k7  rtI        d6tK        |!      z         t	        jL                         t	        jN                  |d7d"d"8      }$	 t	        jP                  |$      |d9}%| dk(  r||%d:<   d;t"        j$                  jS                  |      |%|d<}&|r||&d=<   t        j
                  jU                  ||&>      }'|'d&   }(tW        d?|(       |r	 t+        jX                  d@dA|(g       t	        j`                  |(      jc                  dCD       | dk(  rt	        jd                  t        j
                  jg                  |(      dE   dF         \  })}*|)|s3t	        jh                  |      jk                  |$jm                         g       |r"t        j
                  jo                  |dGd"i       tq        jr                  |       S 	 |s3t	        jh                  |      jk                  |$jm                         g       |r"t        j
                  jo                  |dGd"i       tq        jr                  |       y # t        j                  j                  $ r1}|j                  dk(  s| dk(  r|j                  dk(  rn|Y d }~=d }~ww xY w#  t!                Y xY w# 1 sw Y   xY w# t*        jZ                  $ r2}|j\                  dBk(  rt?        j^                  dB       n|Y d }~d }~ww xY w# |s4t	        jh                  |      jk                  |$jm                         g       w w xY w# |r"t        j
                  jo                  dGd"i       tq        jr                  |       w xY w)HNrl   zapp-tarball_app_builderzapp-tarball_applet_builderrN   _trusty_xenial_focal_noble)z12.04z14.0416.04z20.04z24.04r   r   r  r0   01
_xenial_v1version_overrideapp-rM   F)aliasalways_retryResourceNotFoundappletPermissionDenied	publishedbill_to_overridedo_version_autonumberingdo_try_updatedo_parallel_builddo_check_syntaxCan't create an applet without specifying a destination project; please use the -d/--destination flag to explicitly specify a project/destination_overrideTz'dx-build-app --remote temporary projectbillTor   idzapp_tarball.tar.gz)tarz-czf-z	--excludez./.gitro   )r5   stdoutwbr   i  @ g      ?g      ?z8Compressing target directory {dir}... ({kb_so_far:,} kb)i   )dir	kb_so_farzCompressing target directory z...r   z#tar exited with non-zero exit code zapplication/gzip)
media_typewait_on_closeshow_progress)
input_filebuild_optionsra   zRemote build of )rM   inputrJ   folderinput_paramszStarted builder job dxwatch   r   )intervalr   output_appletterminateJobs):r
  rP   r   r  rB   rQ   app_describerU   rV   rM   r@   WORKSPACE_IDrF   r  r   project_newr   r7   r8   realpathr:   r;   PopenPIPEr{   timepollr(  readr   r   r   r   isattyrT   flushr\   r]   set_workspace_idupload_local_filedxlinkrj   app_runr   
check_callr   
returncodeexitDXJobwait_on_doneget_dxlink_idsjob_describe	DXProjectremove_objectsget_idproject_destroyr  r  )+r   r>   ra   r#  r  r  r  r  r  r   r   r7  builder_appr   builder_versionsr   r   r1  original_versionr<  rd   #using_temp_project_for_remote_builddest_folderdest_applet_namebuild_project_idproject_inputapp_tarball_filetar_subprocesstar_output_filetotal_num_byteslast_console_update
start_timeprinted_static_messagetar_exitcodedatacurrent_timeremote_file
input_hashapi_optionsapp_run_resultjob_id	applet_id_s+                                              r#   _build_app_remotero    s    u}/2w'H!#i)!)H>y!%%i0G'hy155iEL|#'++GR88 !HM,<()	! $'	2L#xx44Vhv>N5NVfuz4{ ',.m 9IK^_fhxKy8yM"45 ,<()#4901).o&-2)*+0'(*/'
 Kx  ,,>OPd>e;k+;#LL  a  b47:J4JM01	.2+		M$MM&!*:h'*0h'#xx33MB4H`  ''""7+ 77<<2FG#))*Z`gpzpp  A"D) 	6_O"#J%*"-224%,,11/B+D	Q%%d+3t9,#yy{  "55<PZAZ]`A`zz((*.2JJ,,T2

(()c)j)jov  CR  VZ  CZ)j  *[  \

((*.:+3 

((QX)Z[15.+  	6: "JJT"1ACDUUVV./,,-=J\;?tU*	X"kk+6!.J u}(/
9%020@0@0IK#+K
 (3H%!XX--k-TN#D)Ff67 ))4&*AB JJv++Q+7x#224883H3H3PQY3Z[j3kl	1  7/0??ASASAU@VW.HH$$%57NOh 6/0??ASASAU@VW.HH$$%57NOhu ??-- 66//DH4DSeIeG n	J	6 	6v "44 	 ||q(  $	 * 7/0??ASASAU@VW 7 /HH$$%57NOhs   (V0 7X A3Z# :EXA6Z# BY( X  +A&Y( 5Z# 5Z# 0W>&W99W>XXZ#  Y%3'Y Y(  Y%%Y( (8Z  Z# #;[c                    | d   }	| d   }
t         j                  j                  d|
z          |s"t        j                  d| d   d| d   d       t         j
                  j                  | d   dd	d
ii      d	   }|d|	ii}d}i }|D ]  }|| v s| |   ||<    d}|D ]  }||vs||   r| d   ||<    t         j                  j                  ||
d ||||||||      }t         j
                  j                  |      }|sy|r&t        j                  d|d   d|d   d|d       nQt        j                  d|d   d|d   d|d       t        j                  dj                  |d   |d                |r|S d|iS )Nr%  rM   r  z!Will create app from the applet:  ()rJ   fieldsr   Tr4  r  )rn   rm   r   developerNotesdetailsr   ignoreReuse)rn   rm   r   rt  )ra   set_defaultr$  try_versions
try_updateconfirminherited_metadatabriefUploaded and published app r"  r0   ) successfullyUploaded app 1You can publish this app with: dx publish {n}/{v}nv)rB   rC   verify_developer_rightsr
   inforQ   rR   rZ   create_app_multi_regionr<  rT   )applet_descr0   ra   r  r  return_object_dumprz  r|  kwargsrm  app_nameapplet_regionregional_optionsfields_to_inheritr{  fieldrequired_non_emptyapp_idr<  s                      r#   build_app_fromr    s    D!I6"H33FX4EF+fBUWbcgWhjkHH--k).D<DxQUFV;W . YYacM 	), " ;K(3E(:u%; O# <**2DU2K(3F(;u%< 556F6>6:>EBI=MCJAN>EI[<A 6 
CF 88((0LKKP\]cPdfrs|f}  @F  G  HKK,vBVXdenXoqwxyKKKRRUabhUimy  {D  nER  F  G-<AD&>Ar%   c                 J   t         j                  j                  | |	       t        |       }t	        ||       t        | ||       |dk(  r'|s%t         j                  j                  d|d   z          d }d}d }d }t         j                  j                  ||      }|/t        |      dkD  r!|st         j                  j                  d	      d }|d
k(  r|rt        |      \  }}}|j                  d      rF|r3t        j                  dj                  |j                  d                   |j                  d      }t         j                   j#                  |dddii      d   }||i}n=|dk(  r|r|si }|e	 |D ]^  }dj                  |      |d}|r||d<   t         j                   j%                  |      d   }|||<   t        j&                  d|d       ` nt	 ddi}|r||d<   t         j                   j%                  |      d   }t         j                   j#                  |dddii      d   }|||<   t        j&                  d|d       d}nT|dk(  rO|sM	 |j                  dt         j0                        }t         j                   j#                  |dddii      d   }|i}	 |d
k(  r'|%t         j0                  t4        j7                  d       |d
k(  r8|xs$ t         j0                  xs |j                  dd      } 	 t         j                   j#                  | dddii      d   }|| i}|s|s	 |xsO |j                  d      xs< t8        j:                  j=                  t8        j:                  j?                  |             }!|xs |j                  d      xs d}"|"jA                  d      s|"dz   }"t        jB                  d
|!|"| d      D ]?  }#|"|!z   }$dj                  |$|#d         }%|%d z  }%t         j                  j                  |%       |rd!d"i}|tE        d#      d$|v r=d%|v st        |      dkD  r+d&}&|&d'z  }&|&d(z  }&t         j                  j                  |&      i }'t+        |jG                               D ]3  \  }}|s't         j                  jI                  | |||||||)      ng |'|<   5 i }(	 t+        |jG                               D ]h  \  }}t        j                  jJ                  | |'|   f|d
k(  |xr |d
k(  |xr |d
k(  |||||d*|\  })}*|st        j&                  d+|)z   d,z          |)|(|<   j 	 |r;	 |r7t         j                  j)                  t+        |j-                                      y y *d   }-|dk(  rd0|vrt4        j7                  d1       |d0   }.|xs |.g}/|s |
r|/jS                  |.tU        | |.      z          i }0d%|v r2t+        |d%   jG                               D ]  \  }}1d$|1v s|1d$   |0|<    n&d$|v r"|d$   |0t+        |jW                               d-   <   i }2|D ]  }d
|(|   i|2|<   ||0v s|0|   |2|   d$<    d%|v r4t+        |d%   jG                               D ]  \  }}1d2|1v s|1d2   |2|   d2<    t         j                  jY                  |2|-| ||||/|||3
      }3t         j                   j[                  |3      }4|sy|r&t        j\                  d4|4d   d|4d0   d5|3d6       nQt        j\                  d7|4d   d|4d0   d5|3d6       t        j\                  d8j                  |4d   |4d0   9             |r|4nd|3i	 |r7t         j                  j)                  t+        |j-                                      S S |d
k(  r_|rt         j                   j_                  )      nd)i	 |r7t         j                  j)                  t+        |j-                                      S S t         j                  j                  d:|      #  t         j                  j)                  t+        |j-                                      t/                Y xY w#  t/                Y _xY w# t2        $ r t/                Y w xY w# t2        $ r t/                Y qw xY w#  t         j                  j                  d| d      xY w#  |st+        |jG                               D ]{  \  }}|'|   D +cg c]  }+t        jL                  |+d         d-    nc c}+w },}+|,s:t         j                   jO                  t         j                  jQ                  | |.      d/|,i       }  xY w# |r7t         j                  j)                  t+        |j-                                      w w xY w);N)parallel_buildra   r   rl   r  rM   Fr   zFCannot specify --no-temp-build-project when building multi-region appsr  zPName of the applet is set in both destination and extra args! "{}" will be used!rs  r   Tr4  z/Temporary build project for dx-build-app in {r})r   )rM   r   r$  r%  zCreated temporary project z to build inz(Temporary build project for dx-build-apprJ   r!  z]Could not determine applet name from specification + (dxapp.json) or from working directory (rr  r3  r"  )	classnamerM   r3  rJ   recursez2An applet already exists at {} (id {}) and neitherz, -f/--overwrite nor -a/--archive were given.zdummy-cloud:dummy-regionzproject-dummyz5'projects_by_region' should not be None at this pointr   r   z8dxapp.json cannot contain a top-level "resources" field z1when the "regionalOptions" field is used or when z&the app is enabled in multiple regions)rJ   r3  ensure_uploadforce_symlinksr|  resources_dirworker_resources_subpath)check_name_collisions	overwritearchiverJ   override_folderoverride_namedry_runr|  zCreated applet z successfullyr   )rJ   objectsr0   zJdxapp.json contains no "version" field, but it is required to build an appr   )ra   rw  r$  rx  ry  rz  r|  r}  rq  r~  r  r  r  zUnrecognized mode )0rB   rZ   buildr
  rf   r  rC   r  get_enabled_regionsr   r[   rF   rP   r
   warningrT   rQ   rR   r>  debugdelete_temporary_projectsr   valuesr   r=  r\   r  r   r7   r8   rj   r|   r}   find_data_objectsAssertionErroritemsupload_resourcesupload_appletrP  project_remove_objectsget_destination_projectr   r@   keysr  r<  r  applet_describe)5r>   r   r  r  ra   r#  r  r  use_temp_build_projectr  r  r  r   r  r  rz  r  r  r   r|  r  r  r  r`   working_projectusing_temp_projectr  override_applet_nameenabled_regionsprojects_by_regionr]  rJ   dest_project	dest_namerZ  result	dest_pathr   r   resources_bundles_by_regionapplet_ids_by_regionrm  applet_specbundled_resource_objobjects_to_deleteapplet_namer0   rx  additional_resources_by_regionregion_configr  r  r<  s5                                                        r#   build_and_upload_locallyr    s
    	73DEw'Hx17D/Bu}W77&AQ8QROO&&::8VLO "s?';a'?H^223{|| x0ARSgAh>*>::f#  66<fVZZ=O6PR#)::f#5 **?9AHdCS8T + VV^`$o6	1'&- 	bF Q X X[a X b"(%M (2Bh/&*hh&:&:=&I$&OO1@&v.LL!`a	b"!')S T#.>M(+"&(("6"6}"Ed"K XX..=ERVGW<X / ZZbdF)8v&LLXY!	w	ll9d.?.?@GXX..w=ERVGW<X / ZZbdF %g.\a8 7D<M<M<ULL  a  b8*ad.?.?a8<<PY[`CaL22<AIHVZK[@\ 3 ^^fh #),!7W{ 4 zV8L zPRPWPWP`P`acahahapapqxayPzI .Nh1GN3"++C0"-"3K"44xi`k=ISXZ DF +i 7INUUV_aghlamnCIIC**>>sCCD  #=o!N% !XYY ("(9X(EM_I`cdIdXMRRMEEM""66}EE&(##$6$<$<$>? 		ZOFG KR 372B2B2S2S&+-+)A 3T 3C XZ (/		Z  "	#'(:(@(@(B#C 9)-)9)9)G)G/7* ,08+;'<DH,<#8(8#$3"6#* *&	; LL!2Y!>!PQ/8$V,9< z ##==dCUC\C\C^>_` w "&)5=(kly)G,78L#(@##G.A'7.S$ST-/* H,-1(;L2M2S2S2U-V \)FM"m3AN{A[6v>\ (U]^iUj.t4F4K4K4M/Nq/QR!, c,46J66R+S (;;<Z[a<b$V,[9c !H,-1(;L2M2S2S2U-V c)FM&-7DQRaDb(0Ac %%==>N>I>EFMJQEUKWIVFMDI > 	KF  88008LKKXdekXlnz  |E  oF  HN  !O  PKK,W]J^`lmv`wy  !A  BKK S Z Z]ijp]q  vB  CL  vM Z  !N  O#5<D&>I ##==dCUC\C\C^>_`  X:L488++I6SWYbRcc ##==dCUC\C\C^>_` 	 ""66QU7WXXm ''AA$GYG`G`GbBcd

  	J	  
{**>>pw@z { {v	
 &'+,>,D,D,F'G IOFG yT  U[  y\  )]`t)<)<=QRV=W)XYZ)[  )]  )]%  )](77 ,,DDWV]D^*35F)G 8 II @ ##==dCUC\C\C^>_` s   8A#` -a Aa, (Ae' (b +e' 4Ab  D2e' :Bc >e' <A>e' ;Ae' 7e' :Ce' )e' 0"e' Aaa),bbbe' be'  %ce' *e$2"d
e$Ae$$e' ';f"c                     | rt        |       \  }}}nt        j                  }t        j                  j	                  |dddii      d   S )a  
    :param destination: The destination path for building the applet, as given by the --destination option to "dx build". Will be in the form [PROJECT_NAME_OR_ID:][/[FOLDER/][NAME]].
    :type destination: str

    :returns: The name of the region in which the applet will be built, e.g. 'aws:us-east-1'. It doesn't take into account the destination project specified in dxapp.json.
    :rtype: str
    rs  r   Tr4  )rF   rB   r=  rQ   rR   )destinationdest_project_idrn  s      r#   get_destination_regionr    sN      1+ >A++88$$_HxY]N^C_$`aijjr%   c                     d|v r|d   S | r2t        |       \  }}}|j                  d      rt        j                  }|S t        j                  S )NrJ   z
container-)rF   rX   rB   PROJECT_CONTEXT_ID)r  
extra_argsr  rn  s       r#   get_project_to_checkr    sV     J)$$ 1+ >A%%l3"55O&&&r%   c                     t        | |      }t        j                  d|z   dz   ddgid      j                  di       }|j                  dd      }|st        j                  j                  d      y )	Nr"  z/checkFeatureAccessfeatures
dxNextflowT)r  FzPermissionDenied: billTo of the applet's destination project must have the dxNextflow feature enabled. For inquiries, please contact support@dnanexus.com)r  rB   DXHTTPRequestrP   rZ   r[   )r  r  dest_project_to_checkr  dx_nextflow_lics        r#   verify_nf_licenser    s    0jI!!#(="=@U"UXbeqdrWs  CG  H  L  L  MW  Y[  \Hll<7O22  4O  P  	P r%   c                 8   d}| j                   }d}| j                  rt        | j                  |       t	        | j
                  | j                  fD cg c]  }| c}      }t               rdn|}| j                  rd|sbt        | j                   | j                  t        | j                        | j                  | j                        }| j                   }t        |      }| j                  rt        | j                  | j                  gf| j                   | j"                  | j$                  | j&                  | j(                  | j*                  d|}|*| j,                  t/        t)        j0                  |             |d   S | j2                  sH|sEt5        || j6                  fi d| j8                  d| j:                  d	| j                   d
| j                  d| j                  d| j$                  d| j<                  d| j>                  d| j@                  d| j"                  d| jB                  d| jD                  d| jF                  d| jH                  d| j&                  d| j(                  d| jJ                  d| j*                  d|d||}|*| j,                  t/        t)        j0                  |             | jH                  ry|d   S | j                  rdnd}| jH                  r$tL        jO                  djQ                  |             | j8                  r$tL        jO                  djQ                  |             | j:                  r$tL        jO                  djQ                  |             | j(                  r$tL        jO                  d jQ                  |             | j<                  s$tL        jO                  d!jQ                  |             tS        | jJ                  tT              r-tW        | jJ                        d"kD  rtL        jO                  d#       | jJ                  | jJ                  d$   nd}	i }
| j                  r| j                  |
d<   | j$                  r| j$                  |
d<   | j@                  sd|
d<   | j"                  sd|
d<   | j>                  sd|
d<   | jB                  sd|
d<   | j                  rm|rj| j
                  }| j
                  s| j                   rtY        jZ                  d%       t]        | j                  |      }t_        | j                        \  }}}|xs d}t`        jb                  je                  |d&      jg                  d'      }d(je                  |d'|z   d'z   g      }d}	 ti        |d't`        jb                  je                  |d&      jg                  d'      z   t`        jb                  jk                  | j                         )      }|rttn        jp                  js                  d+jQ                  t`        jb                  je                  |t`        jb                  jk                  | j                               |            d,d-| j                   d.d/|d0g}tu        jv                  |      }t`        jb                  je                  |t`        jb                  jk                  | j                               }ty        || jz                  | j                  | j|                  | j                  | j                  | j~                  | j*                  | j                  |1
      S t        |      }t        || j                   2       t        || j6                         | j6                  d3k(  r1| jH                  s%tn        j                  j                  d4|d5   z          t        | j6                  |f| j                  | j                   |	| j                  d6|
S c c}w # tl        $ r( tY        jZ                  d*jQ                  |             Y 1w xY w)7zBuilds an app or applet and returns the resulting executable ID
    (unless it was a dry-run, in which case None is returned).

    TODO: remote app builds still return None, but we should fix this.

    NrN   F)r  profiler   cache_dockernextflow_pipeline_params)ra   r  r  rz  r  r|  r%  r  r  ra   r#  r  r  r  r  r  r  r   r  r  r  rz  r  r   r|  r  r  z--cache-dockerz--remote and --repositoryz${} cannot be combined with --dry-runz){} cannot be combined with --overwrite/-fz'{} cannot be combined with --archive/-az!{} cannot be combined with --jsonz2{} cannot be combined with --no-temp-build-projectr   z5--region can only be specified once for remote buildsr   zwBuilding nextflow pipeline with the Nextflow Pipeline Importer app. Uploading the local nextflow source to the platformz
.nf_sourcer"  :)rJ   r8   folder_namezQDestination folder {} does not exist. Creating and uploading the pipeline source.z\Folder {} exists in the project {}. Remove the directory to avoid file duplication and retryr6  uploadz-rz-oz-p)

repositorytagr  docker_secretsr  r  	git_credsr|  r  r  r  rl   r  rM   )r#  ra   r   r7  )Gr>   nextflowr  r  r   r  r  r   r   r  r  r  r   _fromr  r  ra   updatebill_torz  ry   r|  runr   dumpsremoter  r   r  r  r  r  version_autonumberingcheck_syntaxr  r  r  r   r  r   rT   r^   r   r   r
   r  r  rF   r7   r8   r:   r=   r   rj   r   rB   rZ   r[   r;   r<   r   r  r  git_credentialsr
  rf   r  rC   r  ro  r7  )r  r  r  
source_dirr  xbuild_nf_with_npir   incompatible_optionsr   more_kwargsnf_scrr  rn  rZ  upload_destination_dirqualified_upload_destdest_folder_exists
upload_cmdr`   s                       r#   
_build_appr    s    MJ!}}$**J7 $:K:K(LM1QMN!0!28I}}/%,,LL)$*:*:;**%)%B%B

 #8#G zzJJ""#

 LL++!\\LL#yy**

 

 $(("2$**V$%d|;;0)II nn LL	
 LL "&!1!1 "22 "\\ $(#>#> #11 &*%?%? ++ !-- ,,  ..  LL!" LL#$  $yy%& ;;'( **)* (+, &>/4 $(("2$**V$%<<d| 483D3D/Je<<LL?FFG[\]>>LLDKKL`ab<<LLBIIJ^_` 99LL<CCDXYZ**LLMTTUijkdkk4(S-=-ALLPQ#';;#:Q  .2.C.CK*+<<.2llK*+))6;K23{{+0K(""/4K+,  -2K)* ==.__FOOJ  4D4D4DjQ$5d6F6F$G!;)/R)+*%* ' ),,F\@\_b@b1c(d%%*")< , 277<<\#J#P#PQT#UU$&GG$4$4T\\$B*& &**>>v}}GGLL)?AQAQRVR^R^A_`bn  #'$,,dLacg!hJ"//
;AWW\\*?AQAQRVR^R^A_`F*!HH!..#22)-)F)F..jj ,,%  #:.8T\\:z499599dll##;;FXfEU<UV J QTM]M])-(.djjQDOQ 	QG NB ' KKkrr1s   	_#A%_( (-``c                    	 t        |        t        | | j                  xs i       }| j                  6t        d      	 t        j                   dd|ddg| j                  z          y y # t        j                  j
                  $ rG}t        d|j                  t        j                         t        j                  d       Y d }~d }~wt        j                  j                  $ r=}t        d|t        j                         t        j                  d       Y d }~d }~ww xY w# t        j"                  $ r)}t        j                  |j$                         Y d }~y d }~w t'                Y y xY w)	NzError: rp   r8  z%Expected executable_id to be set herer6  r  z
--priorityhigh)r   r  r  rB   rZ   r[   r   r  r   r   rM  rU   rV   r  r  r;   rK  r   rL  r   )r  executable_idrd   s      r#   r  r    s   
4 "4)>B? xx  !HII	!!4|V"TW[W_W_"_`  //  	QVV%CJJ7??%% Q szz2 ,, 	#HHQ\\""	Js;   %A* 'D) *D&=C		 D&)3D!!D&)E1<E  E1c                  2   t        t        j                        dkD  r{t        j                  d   j                  d      rt	        j
                  d       n7t        j                  d   j                  d      rt	        j
                  d       t        d       yy)a  
    Entry point for dx-build-app(let).

    Don't call this function as a subroutine in your program! It is liable to
    sys.exit your program when it detects certain error conditions, so you
    can't recover from those as you could if it raised exceptions. Instead,
    call dx_build_app.build_and_upload_locally which provides the real
    implementation for dx-build-app(let) but is easier to use in your program.
    r   zdx-build-appzaWarning: dx-build-app has been replaced with "dx build --create-app". Please update your scripts.zdx-build-appletzWWarning: dx-build-applet has been replaced with "dx build". Please update your scripts.N)r   r   argvr}   r   rS   rM  )r  s    r#   mainr    sg     388}q88A;/LL|}XXa[!!"34LLrsQ r%   __main__)F)T)NT)
FNNNTTTTNT)FTNFTF)FFFNNNTTTTTFFTFFNFNrN   )Q
__future__r   r   r   r   r   basicConfigWARNING	getLoggersetLevelERRORr7   r   ry   r;   argparser   r   r   r  r   rB  r   rB   dxpy.app_builderdxpy.workflow_builderdxpy.executable_builderrN   r
   dxpy.nextflow.nextflow_builderr   r   dxpy.nextflow.nextflow_utilsr   r   utilsr   utils.resolverr   r   r   r   utils.completerr   app_categoriesr   rU   r   utils.printingr   compatr   r   cli.parsersr   ArgumentParserr  r\   r   r1   r@   rF   rf   r   r   r   r   r   r   r  r
  ro  r  r  r  r  r  r  r  r  r(   r+   r%   r#   <module>r     s{  ( S R    '// *   * + 4 4W]] C * * *   	          T O 1 ` ` , + ! ! . , 
!	 	 -F	GI D2&D8StORbm*I/XkY\2	 r  JN>B[_?C@ F ^bAF8Bv qubfbf;@indfpadk'PtQn0$ zF r%   