
    5i                        d Z ddlmZmZmZm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ZddlZddl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  ej8                         Zd	Zd
Z G d de       Z!d Z"d Z#d Z$d Z%d Z&d!dZ'd"dZ(d Z)d Z*d Z+d#dZ,	 	 	 d$dZ-d!dZ.d!dZ/ddddddi dfdZ0	 	 d%dZ1ddddddi dfdZ2d  Z3y)&aI  
App Builder Library
+++++++++++++++++++

Contains utility methods useful for compiling and deploying applets and apps
onto the platform.

You can specify the destination project in the following ways (with the earlier
ones taking precedence):

* Supply the *project* argument to :func:`upload_resources()` or
  :func:`upload_applet()`.
* Supply the 'project' attribute in your ``dxapp.json``.
* Set the ``DX_WORKSPACE_ID`` environment variable (when running in a job context).

You can use the function :func:`get_destination_project` to determine
the effective destination project.

    )print_functionunicode_literalsdivisionabsolute_importN   )logger)merge)fill)INTERACTIVE_CLI)z
dx-toolkit)z&git@github.com:dnanexus/dx-toolkit.gitc                       e Zd ZdZy)AppBuilderExceptionzg
    This exception is raised by the methods in this module when app or applet
    building fails.
    N)__name__
__module____qualname____doc__     r/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/app_builder.pyr   r   <   s     	r   r   c                 
   t        | t              sy| j                         D ]_  \  }}t        |t              sd|v }d|v }d|v }|r|rt        dj	                  |            |sD|sGt        dj	                  |             y)a  
    Validates systemRequirements section of dxapp.json for instanceTypeSelector constraints.

    :param system_requirements: The systemRequirements section from runSpec
    :type system_requirements: dict
    :raises AppBuilderException: If validation fails
    NinstanceTypeinstanceTypeSelectorclusterSpeczpinstanceType and instanceTypeSelector keywords are mutually exclusive in systemRequirements for entry point '{}'zoinstanceTypeSelector and clusterSpec keywords are mutually exclusive in systemRequirements for entry point '{}')
isinstancedictitemsr   format)system_requirementsentry_pointrequirementshas_instance_typehas_instance_type_selectorhas_cluster_specs         r   _validate_system_requirementsr#   C   s     )40%8%>%>%@ !\,-*l:%;|%K"(L8 !;%==CVK=P  &*:%==CVK=P #r   c                 *   d| vrt        d      d| j                  di       v rt        | d   d          | j                  di       }t        |t              r=|j                         D ])  \  }}t        |t              sd|v st        |d          + y y )NrunSpecz0Required field 'runSpec' not found in dxapp.jsonsystemRequirementsregionalOptions)r   getr#   r   r   r   )applet_specregional_optionsregionoptionss       r   _validate_applet_specr-   d   s    #!"TUU {y"==%k)&<=Q&RS #'8"="D)/557 	MOFG'4(-AW-L-g6J.KL	M *r   c                     d| v rd| d   v rt        | d   d          | j                  di       }t        |t              r=|j	                         D ])  \  }}t        |t              sd|v st        |d          + y y )Nr%   r&   r'   )r#   r(   r   r   r   )app_specr*   r+   r,   s       r   _validate_app_specr0   s   s    H!5)9L!L%hy&9:N&OP  ||$5r:"D)/557 	MOFG'4(-AW-L-g6J.KL	M *r   c                     t         j                  j                  | d      }t        |      5 }t	        j
                  |      }d d d        t               d|vrt        j                  |d<   |S # 1 sw Y   -xY w)N
dxapp.jsonproject)	ospathjoinopenjsonloadr-   dxpyWORKSPACE_ID)src_dirapplet_spec_filefhr)   s       r   _get_applet_specr?      sl    ww||G\:		 $2iim$ +&#!%!2!2I$ $s   A..A7c                     t         j                  j                  | d      }t        |      5 }t	        j
                  |      }d d d        t               |S # 1 sw Y   xY w)Nr2   )r4   r5   r6   r7   r8   r9   r0   )r<   app_spec_filer>   r/   s       r   _get_app_specrB      sQ    GGLL,7M	m	 !99R=! x O	! !s   AA Tc                    t         j                  j                  | d      }t         j                  j                  |      r}t        j                  |t         j
                        rYt        j                  dj                  t         j                  j                  |                    	 t        j                  |g       t         j                  j                  t         j                  j                  | d            szt         j                  j                  t         j                  j                  | d            s=t         j                  j                  t         j                  j                  | d            r|rd	t        fz  }nd
}t        j                  dj                  |t         j                  j                  |                    	 d
d| g}|r!|j!                  dt#        t              z          t        j                  |       yy# t        j                  $ r}t        d|j                  fz        d}~ww xY w# t        j                  $ r}t        d||j                  fz        d}~ww xY w)z
    Runs any build scripts that are found in the specified directory.

    In particular, runs ``./configure`` if it exists, followed by ``make -jN``
    if it exists (building with as many parallel tasks as there are CPUs on the
    system).
    	configurezRunning ./configure in {cwd})cwdz8./configure in target directory failed with exit code %dNMakefilemakefileGNUmakefilez	make -j%dmakezBuilding with {make} in {cwd})rI   rE   z-Cz-jz/%s in target directory failed with exit code %d)r4   r5   r6   isfileaccessX_OKr   debugr   abspath
subprocess
check_callCalledProcessErrorr   
returncode	NUM_CORESappendstr)r<   parallel_buildconfig_scriptemake_shortcmdmake_cmds         r   buildr[      s    GGLL+6M	ww~~m$="'')J3::rwww?W:XY	t!!=/2 
ww~~bggll7J7877>>"'',,w
;<77>>"'',,w>?'9,6M"M4;;TVT[T[TcTcdkTl;mn	yg.Hs9~ 56!!(+ @	 ,, 	t%&`dedpdpcr&rss	t ,, 	y%&W[hjkjvjvZw&wxx	ys0   'H =H: H7H22H7:I,I''I,c                 &    ||S t        |       d   S )a  
    :returns: Project ID where applet specified by src_dir would be written
    :rtype: str

    Returns the project ID where the applet specified in *src_dir* (or
    its associated resource bundles) would be written. This returns the
    same project that would be used by :func:`upload_resources()` and
    :func:`upload_applet()`, given the same *src_dir* and *project*
    parameters.
    r3   )r?   )r<   r3   s     r   get_destination_projectr]      s     G$Y//r   c                    t         j                  j                  |        }|rt         j                  j                  |       \  }}g }|r6|j	                  |       t         j                  j                  |      \  }}|r6t         j
                  }t        |      D ]l  }|xr) |t         j
                  k(  xr |t         j                  k(   }t         j                  j                  t         j                  j                  ||            }n |S )a  
    :param link_target: The target of a symbolic link, as given by os.readlink()
    :type link_target: string
    :returns: A boolean indicating the link is local to the current directory.
              This is defined to mean that os.path.isabs(link_target) == False
              and the link NEVER references the parent directory, so
              "./foo/../../curdir/foo" would return False.
    :rtype: boolean
    )
r4   r5   isabssplitrT   sepreversedpardirrN   r6   )link_targetis_localdl
link_parts	curr_pathps          r   is_link_localrk      s     ''--,,HggmmK(!
a ''--"CAa  FF	*% 	DA Q)rvv*=*P!ryy.%QHY(BCI	D Or   c                     | t         j                  z  t         j                  z  t         j                  z  }|t         j                  z  r$|t         j
                  z  t         j                  z  }|S )a  
    :param perm_obj: A permissions object, as given by os.stat()
    :type perm_obj: integer
    :returns: A permissions object that is the result of "chmod a+rX" on the
              given permission object.  This is defined to be the permission object
              bitwise or-ed with all stat.S_IR*, and if the stat.S_IXUSR bit is
              set, then the permission object should also be returned bitwise or-ed
              with stat.S_IX* (stat.S_IXUSR not included because it would be redundant).
    :rtype: integer
    )statS_IROTHS_IRGRPS_IRUSRS_IXUSRS_IXGRPS_IXOTH)perm_objret_perms     r   
_fix_permsrv      sL     $,,&5DH$,,dll*T\\9Or   c                 :    t        | j                        | _        | S )z
    :param tar_obj: A TarInfo object to be added to a tar file
    :tpye tar_obj: tarfile.TarInfo
    :returns: A TarInfo object with permissions changed (a+rX)
    :rtype: tarfile.TarInfo
    )rv   mode)tar_objs    r   _fix_perm_filterrz      s     gll+GLNr   Fc                    |s t         j                  j                  | d      }t        |       }||d   }	n|}	||d<   t         j                  j	                  |      rt        t        j                  |            dkD  rd|v r|d   n|}
t        j                  d      5 }t        j                         }t        j                  |d	      }t        j                  |      D ]!  \  }}}|j                  |      st        d
|d|      |t        |      d }t        j                   |      }|j                  d      sd|z   }|t#        t%        |j&                              t#        t)        |j*                  dz              g}|j-                  dj                  d |D                     |j/                  |||z   dt0               |j3                          |D ]  }t         j                  j                  ||      }t         j                  j5                  |      sCt        j6                  |      }|st9        |      r|j;                  |       wt=        d|dt         j                  j?                  |      d       tA        |      D ]t  }d}t         j                  j                  ||      }t         j                  j                  ||      }t        j                   |      }t         j                  j5                  |      rXt        j6                  |      }|sAt9        |      s6	 t        jB                  t         j                  j                  ||            }d}|t#        t%        |j&                              t#        t)        |j*                  dz              g}|j-                  dj                  d |D                     |rt         j                  j?                  |      }|j/                  |||z   t0               w $ |jG                          |ri }d}nB|jI                         }tK        |      }tM        jN                  |	|
tK        |      dddd      }|r,|s&tQ        jR                  d|jU                         z          |}nMtQ        jV                  d | z          t        j                  d!d"      } tY        jZ                  | d#	      }!|j]                  d       |j_                  t`        jb                        }"|"r3|!je                  |"       |j_                  t`        jb                        }"|"r3|!jg                          |!jG                          | jG                          d|v r*	 tM        jh                  |	      jk                  |d   d$       tM        jp                  | jr                  d|	|
d|%      }t        jt                  | jr                         tM        jv                  |jU                               }#ddd       d&#d'gS g S # tD        $ r0 t=        d|dt         j                  j?                  |      d      w xY w# tL        jl                  jn                  $ r Y w xY w# 1 sw Y   pxY w)(a  
    :param ensure_upload: If True, will bypass checksum of resources directory
                          and upload resources bundle unconditionally;
                          will NOT be able to reuse this bundle in future builds.
                          Else if False, will compute checksum and upload bundle
                          if checksum is different from a previously uploaded
                          bundle's checksum.
    :type ensure_upload: boolean
    :param force_symlinks: If true, will bypass the attempt to dereference any
                           non-local symlinks and will unconditionally include
                           the link as-is.  Note that this will almost certainly
                           result in a broken link within the resource directory
                           unless you really know what you're doing.
    :type force_symlinks: boolean
    :param resources_dir: Directory with resources to be archived and uploaded. If not given, uses `resources/`.
    :type resources_dir: str
    :param worker_resources_subpath: Path that will be prepended to the default directory where files are extracted on the worker.
                                     Default is empty string, therefore files would be extracted directly to the root folder.
                                     Example: If "home/dnanexus" is given, files will be extracted into /home/dnanexus.
    :type worker_resources_subpath: str
    :returns: A list (possibly empty) of references to the generated archive(s)
    :rtype: list

    If resources_dir exists, archives and uploads the contents of the resources_dir
    (usually ``resources/``) subdirectory of *src_dir* to a new remote file
    object, and returns a list describing a single bundled dependency in
    the form expected by the ``bundledDepends`` field of a run
    specification. Returns an empty list, if no archive was created.
    	resourcesNr3   r   folderz.tar)suffixw)fileobjrx   z	Expected z to start with root directory /  r   c              3   D   K   | ]  }|j                  d       dz     ywzutf-8    Nencode.0ss     r   	<genexpr>z#upload_resources.<locals>.<genexpr>L  s     +V!AHHW,=,E+V    F)arcname	recursivefilterzLCannot include symlinks to directories outside of the resource directory.  'z' points to directory ''TzBroken symlink: Link 'z' points to 'z', which does not existc              3   D   K   | ]  }|j                  d       dz     ywr   r   r   s     r   r   z#upload_resources.<locals>.<genexpr>  s     /Za0AE0I/Zr   )r   r   )resource_bundle_checksumeitherclosed)r3   r}   
properties
visibilityzero_okstatereturn_handlerzGFound existing resource bundle that matches local resources directory: zUploading in z.tar.gz)r~   deletewb)parents)wait_on_closer3   r}   hiddenr   zresources.tar.gznameid)<r4   r5   r6   r?   existslenlistdirtempfileNamedTemporaryFilehashlibsha1tarfiler7   walk
startswithAssertionErrorlstatrU   rv   st_modeintst_mtimeupdateaddrz   sortislinkreadlinkrk   rT   r   realpathsortedrm   OSErrorclose	hexdigestr   r:   find_one_data_objectr   infoget_idrM   gzipGzipFileseekreadioDEFAULT_BUFFER_SIZEwriteflushget_handler
new_folder
exceptions
DXAPIErrorupload_local_filer   unlinkdxlink)$r<   r3   r}   ensure_uploadforce_symlinksbriefresources_dirworker_resources_subpathr)   dest_projecttarget_folder
tar_tmp_fhoutput_sha1tar_fhdirnamesubdirsfilesrelative_dirnamedir_statfieldssubdir_namedir_pathrd   filename
deref_linkrelative_filenametrue_filename	file_statproperties_dictexisting_resourcesdirectory_checksumdx_resource_archivetargz_fh	targz_gzfdatarchive_links$                                       r   upload_resourcesr      s   < Wk:"7+K"9-!(I	ww~~m$RZZ-F)G!)K19[1HH-f6 ((7 `	E:!,,.K\\*3?F+-77=+A N}'%))-8(Zacp)qrr $+3}+=+>#? 88G,'2237'*-='=$*C
8;K;K0L,MsSVW_WhWhkoWoSpOqr""388+Vv+V#VW 

7,DGW,Wch  rB
  C  $+ KK!ww||G[AH ww~~h/ ')kk(&; *];-G!LL5"5  em  oq  ov  ov  o  o  @H  oI  7J  #K  KK& !'u "}H!&J(*5Ex(P%$&GGLL($CM " 7Iww~~m4 ')kk-&@ .-2Lp,.GGBGGLL+4V,W	-1
 0Z	@Q@Q5R1SUXY\]f]o]orv]vYwUxyF&&sxx/ZSY/Z'Z[ "(*(8(8(GJJ}6NQb6bk{J|E"}YN}h LLN "$%*"%0%:%:%<""&@R"S%)%>%>((#=OP' "#'&" "KK i 2 9 9 ;!< = '9# _w67 $66iPUV
 !MM(F	" oob&<&<=OOC($//"*@*@AC  !! {*((6AA+hBWaeAf '+&<&<MM"&((.'# 		(--(  ;;':'A'A'CDLA`	EH ,<@AA	C $+ p
 ':  L  NP  NU  NU  N^  N^  _l  Nm  ;n  'p  !ppV  ??55 a`	E `	EsX    E;Y,DY,(5XGY,84Y,-)Y	A'Y,9Y	Y,	Y)&Y,(Y))Y,,Y5c
                     t        |       }||d   }n|}||d<   d|vr@	 t        j                  j                  t        j                  j	                  |             |d<   |r||d<   d|vrd|d<   |r||d<   d|vrt        j                  |d<   g }d}|r|s|d   |d   j                  d      sdnd	z   |d   z   }t        j                  d
|z          t        j                  d|d   |d   |d      D ]:  }|r|j                  |d          |r
t        j                  d|d   z         t        j                  |      }d}	 |j                  |       |j#                  |d   g|       t        j$                  |d   |      }t&        j&                  j)                  |j*                  dz        j-                         }|j.                  dj1                  |      z   }|j3                  |       |	rt        j4                  d|d   d|d|d|d	       (t        d|d|d   d       |d   j7                  dg        |d   j7                  dg        |st        j8                  j;                  |d d!d"ii#      d!   }t=        |j?                  d$i             d%k7  r5||j?                  d$i       vr!d&j1                  |      }|d'z  }t        |      |j?                  d$i       j?                  |i       }d(|v r|d(   |d   d(<   d|v r|d   d   jA                  |d          d|v r|d   d   jA                  |d          t        jB                  jE                  ||        d)|d   v rTtG        t        j                  jI                  | |d   d)               5 }|jK                         |d   d*<   |d   d)= ddd       d(|d   v rf|d   d(   }|D ]Y  }	 t        j                  jI                  | ||   d+   d,         }tG        |      5 }|jK                         ||   d+   d,<   ddd       [ ||d   d   jA                  |       |d   d   }tQ        |      tR        ustU        d. |D              rt        d/      |D ]  }|j?                  dd      }|j?                  dd      }|j?                  d0d      } d|v r+t        jV                  |d         jY                  d1hd"2      }!nLd|v r=|;d3|v r7	 t        jZ                  d"d4d5|d   t]        |d3   6      ||dd"d1d"id7d8d9      }!nt        d;      |!rd|v r|!d1   }#n|!d<   d1   }#d=|#v r|#d=   }$nt        d>|!d   z        t        jb                  |$      jY                         d   }%|%|$d?}&| r| |&d0<   |d   d   j                  |&       |r1t        jV                  |!d   |@      jY                         d   |k7  sat        jV                  |!d   |!d         je                  |       t        dAtg        jh                  |      z         tk        ||
       |r7tm        dB       tm        tg        jh                  |dCD             tm        dE       yF|j?                  dGg       r2dH|vrg |dH<   tS        to        |dH         to        |dG         z        |dH<   t        j8                  jq                  |      d   }'|r|js                  dI|'i       |rM|	s't        j4                  dJdKjI                  |      z         t        j                  |      ju                  |       |'|fS #  t        d| d      xY w# t        j                  $ r |j!                  |       Y (w xY w# 1 sw Y   xY w# 1 sw Y   mxY w# tL        $ r Y tN        $ r t        d-      w xY w# t        j^                  j`                  $ r" d:}"t        |"j1                  |d   ||            w xY w)La  
    Creates a new applet object.

    :param project: ID of container in which to create the applet.
    :type project: str, or None to use whatever is specified in dxapp.json
    :param override_folder: folder name for the resulting applet which, if specified, overrides that given in dxapp.json
    :type override_folder: str
    :param override_name: name for the resulting applet which, if specified, overrides that given in dxapp.json
    :type override_name: str

    Nr3   r   zoCould not determine applet name from the specification (dxapp.json) or from the name of the working directory ()r}   r   dxapi z Checking for existing applet at appletF)	classnamer   r}   r3   recurser   zArchiving applet %sz/.Applet_archive)objectsdestination)r3   r   z ({d}))rf   zArchived applet z to z:""zAn applet already exists at z (id zC) and the --overwrite (-f) or --archive (-a) options were not givenr%   bundledDependsassetDependsr   r+   Tinput_paramsr'   r   zVdestination project is in region {} but "regionalOptions" do not contain this region. z3Please, update your "regionalOptions" specificationr&   filecoder   bootstrapScriptz4The clusterSpec "bootstrapScript" could not be read.c              3   >   K   | ]  }t        |      t        u  y wN)typer   )r   deps     r   r   z upload_applet.<locals>.<genexpr>m  s     -]d3it.C-]s   z7Expected runSpec.assetDepends to be an array of objectsstagesdetails)r   default_fieldsversionrecordAssetBundle)r  )defaultFieldsr   r   )r   r   typenamer   r   r3   r}   r   describer   more_okzSFound more than one asset record that matches: name={0}, folder={1} in project={2}.zhEach runSpec.assetDepends element must have either {'id'} or {'name', 'project' and 'version'} field(s).r
  archiveFileIdzWThe required field 'archiveFileId' was not found in the details of the asset bundle %s r   )dxidr3   z;No asset bundle was found that matched the specification %sz"Would create the following applet:   )indentz'*** DRY-RUN-- no applet was created ***)NN
categoriestagsreplacedWithzDeleting applet(s) %s,);r?   r4   r5   basenamerN   r   r:   API_VERSIONendswithr   rM   find_data_objectsrT   	DXProjectlist_folderr   r   moveDXAppletdatetimefromtimestampcreatedctimer   r   renamer   
setdefaultapiproject_describer   r(   extendexecutable_builderinline_documentation_filesr7   r6   r   KeyErrorIOErrorr   listanyDXRecordr
  r   r   r   DXSearchErrorDXFilecloner8   dumpsr	   printset
applet_newset_propertiesremove_objects)(r<   uploaded_resourcescheck_name_collisions	overwritearchiver3   override_folderoverride_namedry_runr   kwargsr)   r   applets_to_overwritearchived_appletdestination_pathresultprojarchive_foldernownew_namer+   err_mesgr*   code_fhsys_reqsr   bootstrap_scriptasset_dependsassetasset_projectasset_folderasset_stagesasset_recordmsgasset_detailsarchive_file_idarchive_file_namebundle_depends	applet_ids(                                           r   upload_appletrU    s    #7+K"9-!(I[ 	i"$''"2"2277??73K"LK  /H{" #H+Fk!#//GOW&x0{8?T?]?]^a?bChjkny  {A  oB  B7:JJK,,xkRXFYbmnvbw  BN  X]  ^ 	yF %++F4L92fTlCD~~l3!34$$^4 		6$<.n	M"&--tl"S''55o6M6Md6RSYY[*//(//C/2HH&&x0KKtVbdrt| }~)  Yi  kq  rv  kw  +x  y  y3	yB 	%%&6;	%%nb9**<xRZ\`QaFb*cdlm {0"56!;koo^oqsNt@tqxxy  AHOOH%h//&??+<bAEEfbQ  #33;KL`;aK	"#78//	"#34;;<LM]<^_--	">299:J>:Z[ 	66{GL Y''"'',,wI(>v(FGH 	/G-4\\^K	"6*I&v.	/ {955y)*>?# 		dKd#%77<<+9N}9]^o9p#q *+ ]wNUllnH[)-89JK]		d %I/0778JK  	*>:MM$&#-]}-]*]!"[\\ ,=		)T2yy3/yy405===t5>>ykbf>gLu_!:yE?Qb#88QYdq>CFmX\ejkteuXvANWcmrTXenptduBv?GQV	 X & 'T U U u} ,Y 7 ,Z 8 C-/"/"@) +PR^_cRd+e f f $O < E E G O)%N +7x(	"#34;;NKMM|D'9<PYY[\efjvvl40,y:QRXXYef%&c)-E):'< = =W,=\ 
+v
 23djjQ/078|R($"$K"3{6':#;c+lB[>\#\]F##K06I&&	'BC KK/388<P3QRS|$334HIk!!u	i%  _f  'h  i  i@  4OON34h	/ 	/] ]  d)*bccd0 ??00 bk)#**U6]LR_*`aabs_   ?] ]^4^	^#^25^>]$]>=]>^^	^	^;'^;>?_=c                    	 t         j                  j                  |      d   }|S # t         j                  j                  $ r}|j
                  dk(  r|j                  dk(  rwt        d|d   d|dt        j                         t         j                  j                  d	| z   |
      }|j                  dd      dkD  rY d}~yt        | |||      cY d}~S |d}~ww xY w)z}
    Creates a new version of the app. Returns an app_id, or None if the app has
    already been created and published.
    r   InvalidInputz:Specified name and version conflict with an existing aliasApp r   r   z already existsr   app-)alias	publishedr   N
try_update)r:   r"  app_newr   r   r   rO  r0  sysstderrapp_describer(   _update_version)app_namer  r/   r^  app_idrX   rb  s          r   _create_or_update_versionrf    s    !!(+D1??%% 66^#1m(m0@'JQTQ[Q[\  8800(1B'0RLQ/!3"8Wh:VVs(   #& CA<CCCCCc                    |sy	 t         j                  j                  d| z   ||      d   }|S # t         j                  j                  $ r@}|j
                  dk(  r*t        d|d   d|dt        j                  	       Y d}~y|d}~ww xY w)
zv
    Updates a version of the app in place. Returns an app_id, or None if the
    app has already been published.
    NrZ  r   InvalidStaterX  r   r   z has already been publishedrY  )	r:   r"  
app_updater   r   r   r0  r`  ra  )rd  r  r/   r^  re  rX   s         r   rc  rc    s    
 $$Vh%6J4P??%% 66^#HV<LgV]`]g]gh	s   (. B4BBBc                 B    t        t        |       |||||||||	|
      S )a  
    Creates a new app object from the specified applet(s).

    :param regional_options: Region-specific options for the app. See
        https://documentation.dnanexus.com/developer/api/running-analyses/apps#api-method-app-new
        for details; this should contain keys for each region the app is
        to be enabled in, and for the values, a dict containing (at
        minimum) a key "applet" whose value is an applet ID for that
        region.
    :type regional_options: dict
    )r'   )publishset_defaultbillTotry_versionsr^  confirminherited_metadatar   _create_appr   )r*   rd  r<   rk  rl  rm  rn  r^  ro  rp  r   s              r   create_app_multi_regionrs    s5     t,<=xZa#.vLeo&;MUZ\ \r   c
                 >    t        t        |       ||||||||	      S )z
    Creates a new app object from the specified applet.

    .. deprecated:: 0.204.0
       Use :func:`create_app_multi_region()` instead.

    )r   )rk  rl  rm  rn  r^  ro  rq  )
rT  applet_namer<   rk  rl  rm  rn  r^  ro  r*   s
             r   
create_apprv    s-     t9-{GWbm$<J`gi ir   c           	         |rYt        |      }|
s+t        j                  dt        j                  |             t
        j                  j                  ||       n|	}|j                  | |       |r||d<   |s|d   g}|D ](  }t        j                  d|d       ||d<   d }	 t
        j                  j                  d|d   z   |d	
      }|St        j                  d|d   d|d       t        |d   |d   ||      }||
st        j                  d|z           n|j!                  dd      dk(  rSt        j                  d|d   d|d       t#        |d   |d   ||      }||
st        j                  d|z           n[t        j                  d|d   d|d       + t%        |      dk7  rddj'                  |      z   }nd|d   z   }t)        d|      |j!                  dg       }t
        j                  j+                  |      d   }t-        |      j/                  t-        |            }t-        |      j/                  t-        |            }|r,t
        j                  j1                  |dt3        |      i       |r,t
        j                  j5                  |dt3        |      i       |j!                  d      }|t
        j                  j7                  |      d   }t-        |      t-        |      z
  }t-        |      t-        |      z
  }d	}|s|rg }|r,|j9                  ddj'                  t;        |            z          |r,|j9                  ddj'                  t;        |            z          d j'                  |      }|ryt<        r[	 t?        d!       t?        tA        d"|z                t?        d!       tC        d#      }|jG                         jI                  d%      s0d&}n-t        jJ                  d'       d&}nt        jJ                  |       |s\|r,t
        j                  jM                  |dt3        |      i       |r,t
        j                  jO                  |dt3        |      i       |j!                  d(      }t
        j                  jQ                  |      d(   }|Pt-        |      t-        |      z
  }t-        |      t-        |      z
  } d	}!d)|v rd|d   d*}"|ryt<        r[	 t?        d!       t?        tA        d"|"z                t?        d!       tC        d+      }|jG                         jI                  d%      s0d&}!n-t        jJ                  d,       d&}!nt        jJ                  |"       |!r|d)hz  }|r,t
        j                  jS                  |d(t3        |      i       |!rt        jJ                  d-|d   d.       | rOt
        j                  jU                  |d(t3        |       i       n"t%        |      s|
st        jJ                  d/       |r%t
        j                  jW                  |d0|i       |S t%        t3        t        jX                  |d&d1                  dk(  }#|#r$t
        j                  j[                  |d2d3gi       |S # t
        j                  j                  $ r}|j                  dk(  rn|Y d }~d }~ww xY w# tD        $ r d$}Y w xY w# tD        $ r d$}Y w xY w)4NzWill create app with spec: )r   rm  r  zAttempting to create version z...rZ  r   F)r[  always_retryResourceNotFoundrX  r   z does not yet existr]  zCreated app r\  r   z* already exists and has not been publishedzUpdated existing app z& already exists and has been publishedr   zany of the requested versions: z, zthe requested version: zCould not create r  r   
developersz(the following developers will be added: z*the following developers will be removed: z; and z***z	WARNING: z(Confirm updating developers list [y/N]: nyTzuskipping requested change to the developer list. Rerun "dx build" interactively or pass --yes to confirm this change.authorizedUsersPUBLICz] will be made public. Anyone will be able to view and run all published versions of this app.z&Confirm making this app public [y/N]: zskipping requested change to add PUBLIC to the authorized users list. Rerun "dx build" interactively or pass --yes to confirm this change.z_the app was NOT made public as requested in the app spec. To make it so, run "dx add users app-z	 PUBLIC".zuauthorizedUsers is missing from the app spec. No one will be able to view or run the app except the app's developers.makeDefault)r   r\  limitr  default).rB   r   r   r8   r/  r:   r%  r&  r   rM   r"  rb  r   r   r   rf  r(   rc  r   r6   r   app_list_categoriesr1  
differenceapp_add_categoriesr)  app_remove_categoriesapp_list_developersrT   r   r   r0  r
   inputKeyboardInterruptlowerr   warnapp_add_developersapp_remove_developersapp_list_authorized_usersapp_add_authorized_usersapp_remove_authorized_usersapp_publish	find_appsapp_add_tags)$applet_or_regional_optionsrd  r<   rk  rl  rm  rn  r^  ro  rp  r   r/   r  rb  rX   re  tried_versionscategories_to_setexisting_categoriescategories_to_addcategories_to_removedevelopers_to_setexisting_developersdevelopers_to_adddevelopers_to_removeskip_updating_developerspartsdeveloper_change_messagevalueauthorized_users_to_setexisting_authorized_usersauthorized_users_to_addauthorized_users_to_removeskip_adding_publicacl_change_messageno_published_versionss$                                       r   rr  rr    s     )KK4::h;OQR::8WM%OO.XO># +, 6MWFG%	  8800(6:J1JRYhm0nL LL8F;KWUV.x/?)ATV^kuvF~NV34k1-2LLRZ[aRbdklm$Xf%5x	7JHaklF~3f<=LLhW]N^`ghi_6Md |!><AXXN6aHN!>"KLL !\26((66v>|L-.99#>Q:RS23>>sCT?UV##F,M^H_9`#a&&v\4PdKe<f&g !\2$"hh::6B<P 12S9L5MM"#67#>O:PP#(  4E G$))TZ[lTmJnno#IDIIV\]qVrLsst'/}}U';$"$ed;1I#IJKe %&P Q !;;=33C8370 KK  !X  Y/3,45' ++F,PTUfPgAh+i#..v\SWXlSmDn.o 'll+<= $ B B6 JK\ ]*"%&=">E^A_"_%()B%CcJaFb%b"".. KS  TZ  K[  "]"$ed;1C#CDEe %&N O !;;=33C8-1* KK  !m  n)-&./#z1#"HH--fDUW[\sWtCu-vKK  IQ  RX  IY  [  \%HH00GXZ^_yZzF{0|*+E 	  M  	NV=+2NO M	 !$DXQU]^)_$` aef f HH!!&7L!MMg )) 	vv++ 	V - $ #$F - $ #$s<   '(Z(8[%  8[7 (["[["%[43[47\\c                     t         j                  j                  d| |t              }|t	        |      dk(  rt        d      |S )ad  Returns a list of the regions in which the app should be enabled.

    Also validates that app_spec['regionalOptions'], if supplied, is
    well-formed.

    :param app_spec: app specification
    :type app_spec: dict
    :param from_command_line: The regions specified on the command-line
      via --region
    :type from_command_line: list or None

    appr   z1This app should be enabled in at least one region)r:   r%  get_enabled_regionsr   r   r   )r/   from_command_lineenabled_regionss      r   r  r    sF     --AA%SdfyzO"s?';q'@PQQr   )Tr   )Nr   FFFNr   )TFFNNNFF)FFNNTTN)4r   
__future__r   r   r   r   r4   r`  r8   rO   r   multiprocessingr  r   r   r   r   rm   r:   dxpy.executable_builderr   r   utilsr	   utils.printingr
   clir   	cpu_countrS   DX_TOOLKIT_PKGSDX_TOOLKIT_GIT_URLS	Exceptionr   r#   r-   r0   r?   rB   r[   r]   rk   rv   rz   r   rU  rf  rc  rs  rv  rr  r  r   r   r   <module>r     s  "( S R ; ; ;    	          %O%%'	!A 	) 	BM
My@06"k\ ejDH',S"l." JO\ajn)-$ackp\$ mq?Ci  HMZ_hl!dDUW_dslr   