B
    \c                 @   s  d Z ddlm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Zddl	Z	ddl
mZ ddlmZ ddlmZ y:ddlZej rdej kred	 d
Zned dZW n ek
r   dZY nX 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Z ddl m!Z!m"Z" ddlm#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1 e2ej3ddZ4ede#dfde#dfde#dfde#dfd e#d!fd"e#d#fd$e#d%fd&e#d'fd(e#d)fd*e#d+fg
Z5d,dd-dd.d/d
d
d0Z6d1Z7ej8d2krd3Z9nd4Z9d5d6 Z:G d7d8 d8e;Z<d9d: Z=d;d< Z>d=d> Z?d?d@ Z@dAdB ZAdCdD ZBdEdF ZCdGdH ZDde?fdIdJZEeFdKfdLdMZGG dNdO dOe1ZHdPdQ ZId\dRdSZJdTdU ZKdVdW ZLejMdXd fdYdZZNeOd[krePeNejMdXd  dS )]z
    sphinx.cmd.quickstart
    ~~~~~~~~~~~~~~~~~~~~~

    Quickly setup documentation source to work with Sphinx.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )absolute_import)print_functionN)OrderedDict)open)pathlibeditzbind ^I rl_completeTztab: completeF)column_width)PY2PY3	text_typebinary_type)input)quote)__display_version__package_dir)__)	texescape)colorizeboldred	turquoisenocolorcolor_terminal)	ensuredirmake_filename)SphinxRendererencodingZautodocz,automatically insert docstrings from modulesZdoctestz2automatically test code snippets in doctest blocksZintersphinxz7link between Sphinx documentation of different projectsZtodoz9write "todo" entries that can be shown or hidden on buildZcoveragez!checks for documentation coverageZimgmathz+include math, rendered as PNG or SVG imagesZmathjaxz0include math, rendered in the browser by MathJaxZifconfigz7conditional inclusion of content based on config valuesZviewcodez=include links to the source code of documented Python objectsZgithubpagesz=create .nojekyll file to publish the document on GitHub pages._z.rstindex)r   sepdotlanguagesuffixmastermakefile	batchfilez> win32r   Zpurplec             C   s*   t jdkrt| dd tdS t| S d S )Nr'    )end)sysplatformprintr   )prompt r.   4lib/python3.7/site-packages/sphinx/cmd/quickstart.py
term_input]   s    
r0   c               @   s   e Zd ZdZdS )ValidationErrorzRaised for validation errors.N)__name__
__module____qualname____doc__r.   r.   r.   r/   r1   i   s   r1   c             C   s.   t | } t | r*t | s*ttd| S )NzPlease enter a valid path name.)r   
expanduserexistsisdirr1   r   )xr.   r.   r/   is_pathm   s    
r:   c             C   s   | S )Nr.   )r9   r.   r.   r/   allow_emptyu   s    r;   c             C   s   | st td| S )NzPlease enter some text.)r1   r   )r9   r.   r.   r/   nonemptyz   s    r<   c                 s    fdd}|S )Nc                s"   |  krt tdd  | S )NzPlease enter one of %s.z, )r1   r   join)r9   )lr.   r/   val   s    zchoice.<locals>.valr.   )r>   r?   r.   )r>   r/   choice   s    r@   c             C   s$   |   dkrttd|   dkS )N)YYESNZNOzPlease enter either 'y' or 'n'.)rA   rB   )upperr1   r   )r9   r.   r.   r/   boolean   s    rE   c             C   s,   | dd dkrt | dks(ttd| S )Nr      r   z2Please enter a file suffix, e.g. '.rst' or '.txt'.)lenr1   r   )r9   r.   r.   r/   r#      s    r#   c             C   s   | S )Nr.   )r9   r.   r.   r/   ok   s    rH   c             C   sx   t | tr| S tr| tS | dddd| kr>| dS tttd y
| dS  tk
rr   | dS X d S )Nasciireplacez`* Note: non-ASCII characters entered and terminal encoding unknown -- assuming UTF-8 or Latin-1.zutf-8latin1)	
isinstancer   TERM_ENCODINGdecodeencoder,   r   r   UnicodeDecodeError)textr.   r.   r/   term_decode   s    



rR   c          
   C   s  x|d k	rt d| |f  }nt |  d }tr|dddd|krtrV|t}n>tttd y|d}W n tk
r   |d}Y nX t	rnt
t|dd	}t| }|r|s|}t|}y||}W n: tk
r } zttd
t|  wW d d }~X Y nX P qW |S )Nz	%s [%s]: z: rI   rJ   zd* Note: non-ASCII default value provided and terminal encoding unknown -- assuming UTF-8 or Latin-1.zutf-8rK   T)Z
input_modez* )PROMPT_PREFIXr	   rO   rN   rM   r,   r   r   UnicodeEncodeErrorUSE_LIBEDITr   COLOR_QUESTIONr0   striprR   r1   r   str)rQ   defaultZ	validatorr-   r9   errr.   r.   r/   	do_prompt   s8    r[   z[uU]('.*?')c             C   s   t r|d| S | S d S )Nz\1)r
   sub)sourceZrexr.   r.   r/   convert_python_source   s    r^   c                   s(   e Zd Z fddZ fddZ  ZS )QuickstartRendererc                s   |pd| _ tt|   d S )Nr(   )templatedirsuperr_   __init__)selfr`   )	__class__r.   r/   rb      s    
zQuickstartRenderer.__init__c                sF   t | jt |}| jr0t |r0| ||S tt| ||S d S )N)	r   r=   r`   basenamer7   Zrender_from_filera   r_   render)rc   Ztemplate_namecontextZuser_template)rd   r.   r/   rf      s    zQuickstartRenderer.render)r2   r3   r4   rb   rf   __classcell__r.   r.   )rd   r/   r_      s   r_   c          	   C   s  t ttdt  t td d| krBt ttd| d   n t td ttddt| d< xtt| d dstt| d d	drt   t ttd
 t td t   ttddt| d< | d sdt	
d qdW d| krt td ttddt| d< d| kr8t td ttddt| d< d| kr^t td ttd| d< d| krxttd| d< d| krt td ttddt| d< d| krttd | d t| d< d!| krt td" ttd#d$| d!< | d! d$krd%| d!< d&| kr,t td' ttd(d)t| d&< d*| krTt td+ ttd,d-| d*< xtt| d | d* | d&  stt| d d	| d* | d&  rt   t ttd.| d* | d&    t td/ t   ttd0| d* | d*< qVW d1| krt td2 g | d1< x>t D ]2\}}td3||f dtr| d1 d4|  qW td5d6g| d1 rt td7 | d1 d5 d8| krt td9 ttd:d;t| d8< d<| krttd=d;t| d<< t   d%S )>a4  Ask the user for quickstart values missing from *d*.

    Values are:

    * path:      root path
    * sep:       separate source and build dirs (bool)
    * dot:       replacement for dot in _templates etc.
    * project:   project name
    * author:    author names
    * version:   version of project
    * release:   release of project
    * language:  document language
    * suffix:    source file suffix
    * master:    master document name
    * extensions:  extensions to use (list)
    * makefile:  make Makefile
    * batchfile: make command file
    z,Welcome to the Sphinx %s quickstart utility.zz
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).r   z
Selected root path: %sz'
Enter the root path for documentation.zRoot path for the documentationr   zconf.pyr]   zDError: an existing conf.py has been found in the selected root path.z>sphinx-quickstart will not overwrite existing Sphinx projects.z4Please enter a new root path (or just Enter to exit)r(   rF   r    z
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.z+Separate source and build directories (y/n)nr!   z
Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.z(Name prefix for templates and static dirr   projectzJ
The project name will occur in several places in the built documentation.zProject nameauthorzAuthor name(s)versiona/  
Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1.  If you don't need this dual structure,
just set both to the same value.zProject versionreleasezProject releaser"   a  
If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.

For a list of supported codes, see
http://sphinx-doc.org/config.html#confval-language.zProject languageZenNr#   z
The file name suffix for source files. Commonly, this is either ".txt"
or ".rst".  Only files with this suffix are considered documents.zSource file suffixz.rstr$   a  
One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.z-Name of your master document (without suffix)r   zKError: the master file %s has already been found in the selected root path.z7sphinx-quickstart will not overwrite the existing file.zIPlease enter a new file name, or rename the existing file and press Enter
extensionszDIndicate which of the following Sphinx extensions should be enabled:z%s: %s (y/n)zsphinx.ext.%szsphinx.ext.imgmathzsphinx.ext.mathjaxzZNote: imgmath and mathjax cannot be enabled at the same time. imgmath has been deselected.r%   z
A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.zCreate Makefile? (y/n)yr&   z"Create Windows command file? (y/n))r,   r   r   r   r[   r:   r   isfiler=   r*   exitrE   rH   r;   r#   
EXTENSIONSitemsappendsetissubsetremove)dnamedescriptionr.   r.   r/   ask_user   s    









&&



r{   c          	      s  t |d}t  d kr"d d< d kr2d d< t d< t d  d< t d d	 d
<  d   d< t	  d< t
 d d  d<  dg  tdd  d   d< t d tj d<  d d  d< t d d tj d< x.dD ]&} | dddd |d < q W t d sFt d   d rbt d d ph d }t|  d rt d d!}d d"< n:t| d# d! }tt d# d! d$d%g}d| d"< t| tt| d# d&  tt| d# d'  dE fd)d*	}	|r,tj|d+nd(}
|
rBt|
sTtjtd&d,d+}
t|
}t| }W d(Q R X |	t|d-||  t| d.  d/  }|	||d0   d1d2krd3}d4}nd5}d6} d7 d2kr@ d rd pd8 d9<  d rd!p d# d!  d:< |	t d d;|| d<  d= d2kr d r^d p`d8 d9<  d rvd!p d# d!  d:< |	t d d>|| d? |rd(S t   t t!t"d@ t t"dA|  d7 s d= rt"dBpt"dC||f  t"dD  d(S )Fz(Generate project based on values in *d*.)r`   Zmastertoctreer(   Zmastertocmaxdepth   r
   rj   Z
project_fnZidnaZproject_urlZproject_manpageZnow=Zproject_underlinern   z%Yz, rk   	copyrightauthor_texescapedz Documentationproject_docproject_doc_texescaped)	rj   r   r   rk   r   r~   rl   rm   r$   \z\\'z\'_strr   r    r]   Zbuildexclude_patternsr!   z	Thumbs.dbz	.DS_Store	templatesstaticNc          	      sj   st | sNd kr&ttd|   t| dd|d}|| W d Q R X nd krfttd|   d S )NquietzCreating file %s.Zwtzutf-8)r   newlinez!File %s already exists, skipping.)r   rp   r,   r   r   write)ZfpathZcontentr   f)rx   	overwriter.   r/   
write_file  s    zgenerate.<locals>.write_filez	conf.py_tZ
quickstartzconf.pyr$   r#   zquickstart/master_doc.rst_t	make_modeTzquickstart/Makefile.new_tzquickstart/make.bat.new_tzquickstart/Makefile_tzquickstart/make.bat_tr%   r   ZrsrcdirZ	rbuilddirMakefile
r&   zmake.batz
z:Finished: An initial directory structure has been created.zZ
You should now populate your master file %s and create other documentation
source files. z=Use the Makefile to build the docs, like so:
   make builder
zZUse the sphinx-build command to build the docs, like so:
   sphinx-build -b builder %s %s
zQwhere "builder" is one of the supported builders, e.g. html, latex or linkcheck.
)N)#r_   r   Zinitr
   r   urlquoterO   lowertimeZasctimer   
setdefaultZstrftimer   	translateZtex_escape_maprJ   r   r8   r   r=   mapreprosrp   r   r   r^   readZrender_stringrf   getr,   r   r   )rx   r   Zsilentr`   templatekeyZsrcdirZbuilddirr   r   Z	conf_pathr   Z	conf_textZ
masterfileZmakefile_templateZbatchfile_templater.   )rx   r   r/   generate  s    

&$




  :r   c             C   s   | d }t |sdS t |s$dS tddgtt|@ rBdS | d rttj d|}t |sfdS t |stdS d| d	 d
 | d	 d | d | d  g}t|tt|@ rdS dS )Nr   TFr   zmake.batr    r]   zconf.pyr!   r   r   r$   r#   )r   r7   r8   ru   r   listdirr=   )rx   dirZreserved_namesr.   r.   r/   	valid_dir  s(    





r   c              C   s  t jdtdtdd} | jddddd td	d
 | jddddt d | jddddtdd | td}|jddd tdd |jddtdd | td}|jdd d!d"td#d$ |jd%d&d'd(td)d$ |jd*d+dd,td-d. |jd/d0d1d2td3d$ |jd4d5d6d7td8d$ |jd9d:td;d |jd<d=td>d |jd?dd@tdAd | tdB}x2tD ]*}|jdC| dDdE| dFtdG| dH qpW |jdIdJdFdKtdLdM | tdN}|jdOddPd tdQd
 |jdRdSdPtdTdU |jdVddWd tdXd
 |jdYdSdWtdZdU |jd[d\dd]d^td_d
 |jd`dadSd]tdbdU | tdc}|jdddedfdgtdhd$ |jdidjdKdktdldm | S )nNz %(prog)s [OPTIONS] <PROJECT_DIR>z5For more information, visit <http://sphinx-doc.org/>.z
Generate required files for a Sphinx project.

sphinx-quickstart is an interactive tool that asks some questions about your
project and then generates a complete documentation directory and sample
Makefile to be used with sphinx-build.
)ZusageZepilogrz   z-qz--quiet
store_truer   z
quiet mode)actiondestrY   helpz	--versionrl   Zshow_versionz%%(prog)s %s)r   r   rl   r   ZPROJECT_DIRr   ?zoutput path)metavarrY   nargsr   zStructure optionsz--sepz,if specified, separate source and build dirs)r   rY   r   z--dotDOTz&replacement for dot in _templates etc.)r   r   zProject basic optionsz-pz	--projectZPROJECTrj   zproject name)r   r   r   z-az--authorZAUTHORrk   zauthor namesz-vZVERSIONr(   zversion of project)r   r   rY   r   z-rz	--releaseZRELEASErm   zrelease of projectz-lz
--languageZLANGUAGEr"   zdocument languagez--suffixZSUFFIXzsource file suffixz--masterZMASTERzmaster document namez--epubFzuse epubzExtension optionsz--ext-%sZappend_constzsphinx.ext.%srn   zenable %s extension)r   Zconstr   r   z--extensionsrr   rt   zenable arbitrary extensions)r   r   r   r   zMakefile and Batchfile creationz
--makefiler%   zcreate makefilez--no-makefileZstore_falsezdo not create makefile)r   r   r   z--batchfiler&   zcreate batchfilez--no-batchfilezdo not create batchfilez-mz--use-make-moder   Tz#use make-mode for Makefile/make.batz-Mz--no-use-make-modez*do not use make-mode for Makefile/make.batzProject templatingz-tz--templatedirZTEMPLATEDIRr`   z%template directory for template filesz-dz
NAME=VALUE	variableszdefine a template variable)r   r   r   r   )argparseArgumentParserr   add_argumentr   Zadd_argument_grouprr   )parsergroupextr.   r.   r/   
get_parser  s    










r   rF   c          
   C   sX  t jtjd t jtjtdd t	 s4t
  t }y|| }W n$ tk
rl } z|jS d }~X Y nX t|}tdd | D }yd|krtddg|sttd	 d
S tdddg|r2|dd |d|d  t }|| |}t|s:t  tttd ttd d
S nt| W n( ttfk
rd   t  td dS X x.| D ]"\}}t|t rpt!|||< qpW |dg  xF|d d d  D ]2}d|kr|d "| |d #|$d qW xX|%dg D ]H}	y|	$d\}
}|||
< W n& t&k
r<   ttd|	  Y nX qW t'|d|j(d dS )Nr(   localesphinxc             s   s"   | ]\}}|d k	r||fV  qd S )Nr.   ).0kvr.   r.   r/   	<genexpr>w  s    zmain.<locals>.<genexpr>r   rj   rk   zH"quiet" is specified, but any of "project" or "author" is not specified.rF   rl   rm   zHError: specified path is not a directory, or sphinx files already exist.zWsphinx-quickstart only generate into a empty directory. Please specify a new root path.z[Interrupted.]   rn   ,r   r}   zInvalid template variable: %sF)r   r`   r   ))r   r   	setlocaleLC_ALLZinit_consoler   r   r=   r   r   r   r   
parse_args
SystemExitcodevarsdictrs   ru   rv   r,   r   r   DEFAULTScopyupdater   r   r{   KeyboardInterruptEOFErrorrL   r   rR   rw   extendsplitr   
ValueErrorr   r`   )argvr   argsrZ   rx   Zd2r   valuer   Zvariablery   r.   r.   r/   mainf  sb    


r   __main__)TFN)Qr5   Z
__future__r   r   r   r   r   rer*   r   collectionsr   ior   r   readlineparse_and_bindrU   ImportErrorZdocutils.utilsr   Zsixr	   r
   r   r   Z	six.movesr   Zsix.moves.urllib.parser   r   Zsphinx.localer   r   r   r   Zsphinx.utilr   Zsphinx.util.consoler   r   r   r   r   r   Zsphinx.util.osutilr   r   Zsphinx.util.templater   getattrstdinrM   rr   r   rS   r+   rV   r0   	Exceptionr1   r:   r;   r<   r@   rE   r#   rH   rR   r[   compiler^   r_   r{   r   r   r   r   r   r2   rq   r.   r.   r.   r/   <module>
   s   


 








)	 
pRG
