
    df                         d dl Z d dlZd dlmZ ddlmZmZmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZmZmZ d	 Zej(                  ej(                  ej(                  d
Zej,                  ej.                  ej0                  dZd Zd Zd Zd Zd Zy)    N)partial   )AbortInvalidParserNotFound)Templatebinary_suffixes   )dry_runlocal	zipsource)cookiecutter_parser
ini_parserjson_parserc                 @   | j                  dd      }|j                  dt        d       |j                  dt        dd	d
       |j                  ddd       |j                  dddd       |j                  ddt        dd       |j                  t               y )NprojectzCreate project from template)helpsourcez
source dir)typer   target?.z
target dir)r   nargsdefaultr   z	--dry-run
store_trueztest run)actionr   z-zz--zipzsource is a zip filez-pz
--sub-path za sub path within a source)r   r   r   )func)
add_parseradd_argumentstrset_defaultsmake_project)
subparsersparsers     W/home/api-vastappli/venv/lib/python3.12/site-packages/make/make_project/make_project.pysetupr'      s    ""93Q"RF
s>
s#sV
LzJ
glAWX
lb7S   \*    )r   r   r   )r   r   zipc                 6    t        |      j                  |       S )z
        Simple helperfunction to render a template.
        Plays nice with partial:

        .. code-block:: python

            render = partial(_render, variables)
            full_content = render(full_content)
    )r   render)kwargsstrings     r&   _renderr.   %   s     F""6**r(   c                    t        |       }t        |       }|j                          |j                          |j                          |j	                          t
        j                         D ]  }	  ||| j                        }| n& t        dj                  |j                              t        |||       |j                          |j                          y# t        $ r Y {w xY w)z
        * Fetches the source and target path.
        * Parses ``project.conf``
        * copy and transform files in source to target.
    )source_mediumr   Nz!cannot parse source directory: {})get_source_mediumget_target_mediumacquireensure_target_rootensure_source_rootParsersvaluesr   r   r   formatrootcreate_filesrelease)argsr0   target_mediumr%   	variabless        r&   r#   r#   2   s     &d+M%d+M$$&$$& .." T	]DLLQI$ %T 7>>}?Q?QRSSy9  		s   /C	C'&C'c                 2   | j                   xs t        j                  | j                        }|r
t        d   }n	t        d   }| j
                  r G d dt        d   |      }|}|r || j                  | j                        }|S  || j                        }|S )Nr)   r   c                       e Zd Zy)"get_source_medium.<locals>._dryrunN__name__
__module____qualname__ r(   r&   _dryrunrA   \       r(   rG   r   )r)   r   uri_is_zipfiler   Mediumr   sub_path)r<   is_zipmedium_classrG   mediums        r&   r1   r1   S   s    XX>11$++>Fe}g||	fY' 	  dkk4==9 M dkk*Mr(   c                 z    t         d   }| j                  r G d dt         d   |      }|} || j                        S )Nr   c                       e Zd Zy)"get_target_medium.<locals>._dryrunNrB   rF   r(   r&   rG   rQ   r   rH   r(   rG   r   )rJ   r   r   )r<   rM   rG   s      r&   r2   r2   n   s;    '?L||	fY' 	 $$r(   c           
         t        t        |      }| j                  }|j                  }| j                  |      D ]J  \  }}}| j	                  |      }	|dk(  rU ||      }
|	s)|
s,|j                  |
      r>|j                  ||
      }|j                  |       |j                  |       s|dk(  sy ||      }
 ||      }|	s|s|
s|j                  |
      r| j                  |||      }|j                  ||
|      }|j                  |       	 |j                  j                         t        vr,| j                  |      } ||      }|j                  ||       n#| j                  |      }|j                  ||       M y # t         $ r\}t#        dj%                  |j&                  t)        |                   | j                  |      }|j                  ||       Y d }~d }~ww xY w)Nr
   r   zCWARNING: {} can not be rendered with Jinja2. UnicodeDecodeError: {})r   r.   r9   iter_filenamesis_template_dircontains_blanksjoinpathensure_targetmkdirsuffixlowerr	   	read_text
write_text
read_byteswrite_bytesUnicodeDecodeErrorprintr8   namer!   )r0   r=   r>   r+   r   r   r   r9   fn
is_tpl_dir_roottarget_path_fnsource_pathfull_contenterrs                   r&   r:   r:   y   s   Wi(FFF)88@ )Ib"2248
Q;4LEeM,I,I%,P+44VUC++K8##K0q[4LE*C %55e<+44VT2F+44VUCH++K8I&--335H'4'>'>{'K'-l';%00lK (5'?'?'L%11+|L?)IB * I]dd',,c#h $1#;#;K#HL!--k<HHIs   A/F			G.AG))G.)ospathlib	functoolsr   errorsr   r   r   templater   r	   data_mediumr   r   r   parsersr   r   r   r'   get_varsr6   LocalDryRunLocalTargetAndZipSourcerJ   r.   r#   r1   r2   r:   rF   r(   r&   <module>ru      s    	   3 3 0 2 2 A A
+ %%''.77 [[~~,,

+B6%-Ir(   