3

T'ícKKã@s®dZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZm
Z
mZmZddlZddlmZmZdd	lmZdd
lmZddlmZmZddlmZd
ejkrÜejd
jdƒZn
dddgZdEee	ƒZ e
j!eddƒZ"e#e$dœdd„Z%e#e#dœdd„Z&dFe#ee#e$dœdd„Z'e#e#eddœd d!„Z(dGe#e#ee#dd"œd#d$„Z)gdfe#e#e#ee#eee#e$ee#e#dd%œ
d&d'„Z*dHee#ee#e#dd)œd*d+„Z+gfe#eee#e$d,œd-d.„Z,e#eee#e$d/œd0d1„Z-e#ee#ee
ee#ee#ee#fddfd2œd3d4„Z.e#ee#ee$d2œd5d6„Z/dIe#ee#ee#ee#d7œd8d9„Z0e#ee#e$d:œd;d<„Z1ej2d=œd>d?„Z3ej4d@d…fee#e5dAœdBdC„Z6e7dDkrªe6ƒdS)Ju¢Creates reST files corresponding to Python modules for code documentation.

Parses a directory tree looking for Python modules and packages and creates
ReST files appropriately to create code documentation with Sphinx.  It also
creates a modules index (named modules.<suffix>).

This is derived from the "sphinx-autopackage" script, which is:
Copyright 2008 Société des arts technologiques (SAT),
https://sat.qc.ca/
éN)Úcopy)Úfnmatch)ÚEXTENSION_SUFFIXES)Úpath)ÚAnyÚ	GeneratorÚListÚTuple)Ú__display_version__Úpackage_dir)Ú
EXTENSIONS)Ú__)ÚFileAvoidWriteÚ	ensuredir)ÚReSTRendererZSPHINX_APIDOC_OPTIONSú,Úmembersz
undoc-memberszshow-inheritanceú.pyú.pyxZ	templatesZapidoc)ÚfilenameÚreturncCs:tj|ƒ}x*tttddD]}|d|krdSqWdSdS)z)Check *filename* is __init__ file or not.T)ÚkeyÚreverseÚ__init__FN)rÚbasenameÚsortedÚPY_SUFFIXESÚlen)rrÚsuffix©rú3/tmp/pip-build-gk9425m9/sphinx/sphinx/ext/apidoc.pyÚ	is_initpy.s

r!)ÚmodnamesrcGsdjtd|ƒƒS)zJoin module names with dots.Ú.N)ÚjoinÚfilter)r"rrr Úmodule_join8sr&)ÚdirnameÚfilesrcCs8|dkr|dkrdS|dkr&tj|ƒ}tdd„|DƒƒS)z+Check given *files* contains __init__ file.NFcss|]}t|ƒr|VqdS)N)r!)Ú.0Úfrrr ú	<genexpr>Dsz is_packagedir.<locals>.<genexpr>)ÚosÚlistdirÚany)r'r(rrr Ú
is_packagedir=s

r/)ÚnameÚtextÚoptsrc	Cs t|ddƒ}tj|jd||jfƒ}|jrB|s>ttdƒ|ƒdS|jrjtj	|ƒrj|sœttdƒ|ƒn2|s~ttdƒ|ƒt
|ƒ}|j|ƒWdQRXdS)z0Write the output file for module/package <name>.ÚquietNz%s.%szWould create file %s.z!File %s already exists, skipping.zCreating file %s.)Úgetattrrr$ÚdestdirrÚdryrunÚprintr
ÚforceÚisfilerÚwrite)r0r1r2r3Úfnamer*rrr Ú
write_fileGs
r<)Úpackagerr2Úuser_template_dirrcCs`ttƒ}|jr d|kr |jdƒt||ƒ}|j|||dœ}t|tgƒjd|ƒ}t	|||ƒdS)z.Build the text of the file and write the file.zprivate-members)Ú
show_headingsrÚqualnameÚautomodule_optionszmodule.rst_tN)
rÚOPTIONSÚincludeprivateÚappendr&Ú
noheadingsrÚtemplate_dirÚrenderr<)r=rr2r>Úoptionsr@Úcontextr1rrr Úcreate_module_fileZs

rJ)
ÚrootÚmaster_packageÚsubrootÚpy_filesr2ÚsubsÚis_namespaceÚexcludesr>rc	
sڇ‡‡‡‡fdd„|Dƒ}	‡‡‡fdd„|Dƒ}
‡‡fdd„|
Dƒ}
ttƒ}ˆjrdd|krd|jdƒtˆˆƒ}||	|
|ˆjˆj|ˆjˆjdœ	}
t	|t
gƒjd|
ƒ}t||ˆƒ|
rֈjrÖx|
D]}t
d|ˆ|ƒqÀWdS)	z.Build the text of the file and write the file.cs,g|]$}ttjˆ|ƒˆˆƒstˆˆ|ƒ‘qSr)Úis_skipped_packagerr$r&)r)Úpkgname)rQrLr2rKrMrr ú
<listcomp>qsz'create_package_file.<locals>.<listcomp>cs:g|]2}ttjˆ|ƒˆˆƒrt|ƒr|jdƒd‘qS)r#r)Úis_skipped_modulerr$r!Úsplit)r)Úsub)rQr2rKrr rTuscsg|]}tˆˆ|ƒ‘qSr)r&)r)Úmodname)rLrMrr rTxszprivate-members)	rSÚsubpackagesÚ
submodulesrPÚmodulefirstÚseparatemodulesrAr?Úmaxdepthz
package.rst_tN)rrBrCrDr&r[r\rEr]rrFrGr<rJ)rKrLrMrNr2rOrPrQr>rYrZrHrSrIr1Ú	submoduler)rQrLr2rKrMr Úcreate_package_filels.




r_Úmodules)r`r2r0r>rcCst|jƒd}x2|dd…D]"}|j|dƒr8|j|ƒq|}qW|j|j|dœ}t|tgƒjd|ƒ}t|||ƒdS)zCreate the module's index.ÚNr#)Úheaderr]Zdocnamesz	toc.rst_t)	ÚsortÚ
startswithÚremoverbr]rrFrGr<)r`r2r0r>Úprev_moduleÚmodulerIr1rrr Úcreate_modules_toc_file’srh)r'r2rQrcshtjˆƒsdStjtjˆdƒƒ}tdd„|Dƒƒ}|rD|jrDdSt‡‡fdd„|Dƒƒr`dSdSdS)z%Check if we want to skip this module.Fz*.pycss|]}t|ƒr|VqdS)N)r!)r)r*rrr r+­sz%is_skipped_package.<locals>.<genexpr>Tc3s |]}ttjˆ|ƒˆƒVqdS)N)Úis_excludedrr$)r)r*)r'rQrr r+³sN)rÚisdirÚglobr$r.Úimplicit_namespacesÚall)r'r2rQr(Zregular_packager)r'rQr rR§s
rR)rr2rQrcCs2tj|ƒsdStj|ƒjdƒr*|jr*dSdSdS)z%Check if we want to skip this module.TÚ_FN)rÚexistsrrdrC)rr2rQrrr rUºs

rU)ÚrootpathrQr2rc#sŽt|ddƒ}t|ddƒ}xptj||dD]^\‰}}t‡‡fdd„|Dƒƒ}|rTd‰nd‰t‡‡‡fd	d„|Dƒƒ|d
d
…<ˆ||fVq(Wd
S)
z@Walk through the directory and list files and subdirectories up.ÚfollowlinksFrC)rqc3s0|](}|jtƒrttjˆ|ƒˆƒr|VqdS)N)Úendswithrrirr$)r)r*)rQrKrr r+Îs
zwalk.<locals>.<genexpr>r#rnc3s2|]*}|jˆƒrttjˆ|ƒˆƒr|VqdS)N)rdrirr$)r)rW)Úexclude_prefixesrQrKrr r+ÙsN)r#)r#rn)r4r,Úwalkr)rprQr2rqrCrOr(r)rsrQrKr rtÆs"rtcCs(x"t|||ƒD]\}}}|rdSqWdS)zACheck the given directory contains child module/s (at least one).TF)rt)rprQr2Ú_rootZ_subsr(rrr Úhas_child_moduleßsrv)rprQr2r>rcCsªt|ddƒ}t|ƒs|r*|jtjƒd}nd}g}xpt|||ƒD]^\}}}	td|	ƒ}
|
o`|}|
rœxL|	dd…D]"}t|ƒrt|	j|ƒ|	jd|ƒqtWn||kr´|s´|dd…=qB|
s¾|r>|sÜt	|	ƒdksÜt
||ƒr¢|t	|ƒd…jtjƒjtjdƒ}
|st
|||ƒr¢t|||
|	|||||ƒ	|jt||
ƒƒqB||krR|dksVt‚xJ|	D]B}ttj||ƒ||ƒs\|jdƒd}t||||ƒ|j|ƒq\WqBW|S)z`
    Look for every file in the directory tree and create the corresponding
    ReST files.
    rlFéNrr#éÿÿÿÿ)r4r/rVrÚseprtr!reÚinsertrrRÚlstripÚreplacervr_rDr&ÚAssertionErrorrUr$rJ)rprQr2r>rlZroot_packageZ	toplevelsrKrOr(Zis_pkgrPr*Z
subpackageZpy_filergrrr Úrecurse_treeèsB







r~)rKrQrcCs x|D]}t||ƒrdSqWdS)zÄCheck if the directory is in the exclude list.

    Note: by having trailing slashes, we avoid common prefix issues, like
          e.g. an exclude "foo" also accidentally excluding "foobar".
    TF)r)rKrQÚexcluderrr ris

ri)rc	Cs¾tjdtdƒtdƒd}|jddddtd	|jd
tdƒd|jd
dtdƒd|jdddddtdƒd|jdddtdƒd|jddddtd td!ƒd"|jd#d$dd%td&ƒd|jd'd(dd)d*td+ƒd,|jd-d.dd/td0ƒd|jd1d2dd3td4ƒd|jd5d6dd7td8ƒd|jd9dd:d;td<ƒd,|jd=d>d?d:td@ƒd|jdAdBddCtdDƒd|jdEdFddGtdHƒd|jdIddJtdKƒd|jdLdMddNdOtdPƒd,|jdQdRddStdTƒd|jdUdVddWtdXƒd|jdYdZdd[td\ƒd|jd]d^dd_td`ƒd|jdadbddtdcƒd|jdddeddftdgƒd|jtdhƒƒ}|jdidjdkdltdmƒdnx2tD]*}|jdo|dpdq|dktdrƒ|dsqfW|jtdtƒƒ}|jdudvdwdxtdyƒdz|S){NzH%(prog)s [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...]z:For more information, visit <https://www.sphinx-doc.org/>.aE
Look recursively in <MODULE_PATH> for Python modules and packages and create
one reST file with automodule directives per package in the <OUTPUT_PATH>.

The <EXCLUDE_PATTERN>s can be file and/or directory patterns that will be
excluded from generation.

Note: By default this script will not overwrite already created files.)ÚusageÚepilogÚdescriptionz	--versionÚversionZshow_versionz%%(prog)s %s)ÚactionÚdestrƒÚmodule_pathzpath to module to document)ÚhelpÚexclude_patternÚ*zGfnmatch-style file and/or directory patterns to exclude from generation)Únargsr‡z-oz--output-dirÚstorer5Tzdirectory to place all output)r„r…Úrequiredr‡z-qÚ
store_truer3z,no output on stdout, just warnings on stderr)r„r…r‡z-dz
--maxdepthr]éz;maximum depth of submodules to show in the TOC (default: 4))r„r…ÚtypeÚdefaultr‡z-fz--forcer8zoverwrite existing filesz-lz--follow-linksrqFzNfollow symbolic links. Powerful when combined with collective.recipe.omelette.)r„r…rr‡z-nz	--dry-runr6z%run the script without creating filesz-ez
--separater\z1put documentation for each module on its own pagez-Pz	--privaterCzinclude "_private" modulesz	--tocfileÚtocfiler`z0filename of table of contents (default: modules)z-Tz--no-tocÚstore_falsez%don't create a table of contents filez-Ez
--no-headingsrEzedon't create headings for the module/package packages (e.g. when the docstrings already contain them)z-Mz--module-firstr[z7put module documentation before submodule documentationz--implicit-namespacesrlzNinterpret module paths according to PEP-0420 implicit namespaces specificationz-sz--suffixrZrstzfile suffix (default: rst)z-Fz--fullÚfullz.generate a full project with sphinx-quickstartz-az--append-syspathÚappend_syspathz9append module_path to sys.path, used when --full is givenz-Hz
--doc-projectrbz(project name (default: root module name)z-Az--doc-authorÚauthorz,project author(s), used when --full is givenz-Vz
--doc-versionz*project version, used when --full is givenz-Rz
--doc-releaseÚreleasezEproject release, used when --full is given, defaults to --doc-versionzextension optionsz--extensionsrÚ
extensionsrDzenable arbitrary extensions)Úmetavarr…r„r‡z--ext-%sÚappend_constz
sphinx.ext.%szenable %s extension)r„Úconstr…r‡zProject templatingz-tz
--templatedirZTEMPLATEDIRÚtemplatedirz%template directory for template files)r˜r…r‡)ÚargparseÚArgumentParserr
Úadd_argumentr
ÚintÚadd_argument_groupr)ÚparserÚgroupÚextrrr Ú
get_parser*s’











r¤rw)ÚargvrcCs<tjjtjdƒtjjtjjtdƒdƒt	ƒ}|j
|ƒ}tj|jƒ}|j
dkr`|jtjƒd|_
|jjdƒr||jdd…|_tj|ƒs¦ttdƒ|tjdtjdƒ|js¶t|jƒd	d
„|jDƒ}t||||jƒ}|jrddlm }|j!ƒd}d}x2|D]*}	|	j|dƒrq|	}|d
|	7}qW|jdd|j
|j"pDd|j#pNd|j$p`|j#p`dd|jdddddgddd|j%|d||j&dœ}
|j'r¦|
dj(|j'ƒ|j)r¶d|
d<xF|
ddd…D]2}d|krÈ|
dj*|ƒ|
dj(|jdƒƒqÈW|js8|j+|
d|j,|jdn|j-r8t.|||j-|jƒdS)z+Parse and check the command line arguments.raÚlocaleÚsphinxNrwr#z%s is not a directory.)ÚfilecSsg|]}tj|ƒ‘qSr)rÚabspath)r)rrrr rT szmain.<locals>.<listcomp>r)Ú
quickstartz   %s
FrnZAuthorÚindexTzsphinx.ext.autodoczsphinx.ext.viewcodezsphinx.ext.todoÚen)rryÚdotÚprojectr•rƒr–rZmasterZepubr—ÚmakefileZ	batchfileZ	make_modeZmastertocmaxdepthZ
mastertoctreeÚlanguager†r”r—r3r)ZsilentÚ	overwriter›rx)/r§r¦Ú	setlocaleÚLC_ALLZinit_consoler,rr$rr¤Ú
parse_argsr©r†rbrVryrrdrjr7r
ÚsysÚstderrÚexitr6rr5rˆr~r›r“Z
sphinx.cmdrªrcr•rƒr–r]r”r—Úextendr3reÚgenerater8r‘rh)r¥r¡ÚargsrprQr`Úqsrfr1rgÚdr£rrr Úmain‹sx









r½Ú__main__)rr)NN)N)r`N)N)8Ú__doc__rœrkr¦r,rµrrÚimportlib.machineryrrÚtypingrrrr	Z
sphinx.localer§r
rZsphinx.cmd.quickstartrr
Zsphinx.util.osutilrrZsphinx.util.templaterÚenvironrVrBÚtuplerr$rFÚstrÚboolr!r&r/r<rJr_rhrRrUrtrvr~rirr¤r¥rŸr½Ú__name__rrrr Ú<module>
sT


2$
*
 5a"L