3

T'ícˆPã@sdZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZddlmZmZddlmZmZddlmZdd	lmZdd
l m!Z!m"Z"ddl#m$Z$ddl%m&Z&e
rìdd
l'm(Z(ddl)m*Z*ej+e,ƒZ-dZ.e/ej0ej1fZ2ej3dƒZ4Gdd„deƒZ5ee6dœdd„Z7Gdd„dƒZ8Gdd„dƒZ9e:ee$e
e:efdœdd„Z;de9ddœdd „Z<de9ddœd!d"„Z=de9ddœd#d$„Z>de9ddœd%d&„Z?de9ddœd'd(„Z@de9ddœd)d*„ZAdd+ee:ee:ee:ee:d,œd-d.„ZBde
e:efd/œd0d1„ZCdS)2z"Build configuration file handling.éN)ÚOrderedDict)ÚgetenvÚpath)Ú
TYPE_CHECKINGÚAnyÚCallableÚDictÚ	GeneratorÚIteratorÚListÚ
NamedTupleÚOptionalÚSetÚTupleÚUnion)ÚConfigErrorÚExtensionError)Ú_Ú__)Úlogging)Úformat_date)ÚcdÚfs_encoding)ÚTags)ÚNoneType)ÚSphinx)ÚBuildEnvironmentzconf.pyz^((\d{4}-)?)(\d{4})(?=[ ,])c@s"eZdZUeeeeef	dS)ÚConfigValueN)
Ú__name__Ú
__module__Ú__qualname__ÚstrÚnamerÚvaluerÚboolÚrebuild©r&r&ú//tmp/pip-build-gk9425m9/sphinx/sphinx/config.pyrs
r)ÚobjÚreturncCsnt|tƒrdSt|tƒrHxP|jƒD] \}}t|ƒs>t|ƒr"dSq"Wn"t|tttfƒrjtdd„|DƒƒSdS)z'Check if object is serializable or not.Fcss|]}t|ƒVqdS)N)Úis_serializable)Ú.0Úir&r&r'ú	<genexpr>-sz"is_serializable.<locals>.<genexpr>T)	Ú
isinstanceÚUNSERIALIZABLE_TYPESÚdictÚitemsr*ÚlistÚtupleÚsetÚall)r(Úkeyr#r&r&r'r*$s


r*c@s:eZdZdZeddœdd„Zeeeefe	dœdd„Z
dS)	ÚENUMz±Represents the candidates which a config value should be one of.

    Example:
        app.add_config_value('latex_show_urls', 'no', None, ENUM('no', 'footnote', 'inline'))
    N)Ú
candidatesr)cGs
||_dS)N)r8)Úselfr8r&r&r'Ú__init__8sz
ENUM.__init__)r#r)cs2t|ttfƒr$t‡fdd„|DƒƒS|ˆjkSdS)Nc3s|]}|ˆjkVqdS)N)r8)r+Úitem)r9r&r'r-=szENUM.match.<locals>.<genexpr>)r.r2r3r5r8)r9r#r&)r9r'Úmatch;sz
ENUM.match)rrr Ú__doc__r!r:rrrr$r<r&r&r&r'r72sr7c6@s>eZdZUdZddgfddgfddegfdd„degfddgfddgfddgfd	degfd	degfd
gdgfddegfdd
gfddgfdd„dgfddidefddgfgdgfd	degfddgfddgfddgfddgfd	degfddgfidgfgdgfd	degfddgfgdgfgdgfd	degfd	degfddgfddegfd	d	egfid	gfd	dgfdd	gfgd	gfgd	gfddgfddgfidgfddgfd	degfddgfddgfd	dgfd	degfddgfddgfdgddgdœdgfdœ4Zeee	fiifeeefeeefd	dœdd„Z
edEeeedd œd!d"„ƒZ
eeed#œd$d%„Zd	d&œd'd(„Zd	d&œd)d*„Zd	d&œd+d,„Zeed-œd.d/„Zeed-œd0d1„Zeed	d#œd2d3„Zed	d-œd4d5„Zeed-œd6d7„Zeed	d	fd&œd8d9„Zeeeeefed	d:œd;d<„Zeeeefeed=œd>d?„Zed&œd@dA„Z ed	dBœdCdD„Z!d	S)FÚConfigaŒConfiguration file abstraction.

    The config object makes the values of all config values available as
    attributes.

    It is exposed via the :py:attr:`sphinx.application.Application.config` and
    :py:attr:`sphinx.environment.Environment.config` attributes. For example,
    to get the value of :confval:`language`, use either ``app.config.language``
    or ``env.config.language``.
    ÚPythonÚenvÚunknownÚÚhtmlcCs|jS)N)Úproject_copyright)Úcr&r&r'Ú<lambda>XszConfig.<lambda>NZlocalesz{root}.{language}{ext}FÚgettextÚindexcCs|jS)N)Ú
master_doc)Úconfigr&r&r'rFesz.rstZrestructuredtextz	utf-8-sigTÚdefaultÚpyéZqDeÚjaZmanÚtext)Ú	languagesZbuilders)4ÚprojectÚauthorrDÚ	copyrightÚversionÚreleaseÚtodayZ	today_fmtÚlanguageÚlocale_dirsZfigure_language_filenameZ gettext_allow_fuzzy_translationsrIÚroot_docÚ
source_suffixZsource_encodingZexclude_patternsZdefault_roleZadd_function_parenthesesZadd_module_namesZtrim_footnote_reference_spaceZshow_authorsZpygments_styleÚhighlight_languageÚhighlight_optionsZtemplates_pathZtemplate_bridgeZ
keep_warningsÚsuppress_warningsZmodindex_common_prefixZ
rst_epilogZ
rst_prologZtrim_doctest_flagsÚprimary_domainÚneeds_sphinxZneeds_extensionsZmanpages_urlZnitpickyZnitpick_ignoreZnitpick_ignore_regexZnumfigZnumfig_secnum_depthÚ
numfig_formatZmath_number_allZmath_eqref_formatZmath_numfigZ
tls_verifyZtls_cacertsÚ
user_agentZsmartquotesZsmartquotes_actionZsmartquotes_excludes)rJÚ	overridesr)cCs~t|ƒ|_tjjƒ|_||_|jddƒ|_d|jkrlt	|jdt
ƒr\|jjdƒjdƒ|d<n|jjdƒ|d<|jdgƒ|_
dS)NÚsetupÚ
extensionsú,)r0rbr>Ú
config_valuesÚcopyÚvaluesÚ_raw_configÚgetrcr.r!ÚpopÚsplitrd)r9rJrbr&r&r'r:‘s

zConfig.__init__)ÚconfdirrbÚtagsr)cCs>tj|tƒ}tj|ƒs&ttdƒ|ƒ‚t||ƒ}|||p:iƒS)z/Create a Config object from configuration file.z4config directory doesn't contain a conf.py file (%s))rÚjoinÚCONFIG_FILENAMEÚisfilerrÚeval_config_file)ÚclsrmrbrnÚfilenameÚ	namespacer&r&r'Úreadžs

zConfig.read)r"r#r)cCsht|tƒs|S|j|d}|j|dtkr2|S|j|dtthkrh|dkrTdS|dkr`dS|Snüt|ƒtksˆ|j|dtgkrž|dkr”dSt|ƒSnÆt|tƒrÂttdƒ||dfƒ‚n¢t|t	ƒrÖ|j
d	ƒSt|tƒr(yt|ƒStk
r$}zttd
ƒ||fƒ|‚WYdd}~XnXn<t|ƒr6|S|dk	r`t|tƒr`ttdƒ|ƒ‚n|SdS)NréÚ0FÚ1TzZcannot override dictionary config setting %r, ignoring (use %r to set individual elements)z
.key=valuerez/invalid number %r for config value %r, ignoringzAcannot override config setting %r with unsupported type, ignoring)
r.r!rhrr$Útyper0Ú
ValueErrorrr2rlÚintÚcallable)r9r"r#ZdefvalueÚexcr&r&r'Úconvert_overrides¨s@
 



"

zConfig.convert_overrides)r)cCsddddg}x~|D]v}yB||jkr<|j||j|ƒ|j|<n||jkrV|j||j|<Wqtk
r†}ztjd|ƒWYdd}~XqXqWdS)zs
        Initialize some limited config variables before initializing i18n and loading
        extensions.
        r_r]rWrXz%sN)rbrÚ__dict__rir{ÚloggerÚwarning)r9Ú	variablesr"r~r&r&r'Úpre_init_valuesÑs


zConfig.pre_init_valuescCsè|j}x¶|jjƒD]¨\}}ypd|krH|jddƒ\}}||j|iƒ|<wn||jkrdtjtdƒ|ƒwt	|t
ƒr€|j||ƒ||<n|||<Wqtk
r¸}ztjd|ƒWYdd}~XqXqWx$|D]}||jkrÄ|||j
|<qÄWdS)NÚ.rMz-unknown config value %r in override, ignoringz%s)rirbr1rlÚ
setdefaultrhrr‚rr.r!rr{r€)r9rJZvalnamer#Zrealvalnamer6r~r"r&r&r'Úinit_valuesàs&


"

zConfig.init_valuescCsD|j}x.|D]&}||jkr||jkr|||j|<qWtd|ƒdS)zc
        Initialize additional config variables that are added after init_values() called.
        N)rir€rhÚcheck_confval_types)r9rJr"r&r&r'Úpost_init_valuesös

zConfig.post_init_values)r"r)cCsN|jdƒrt|ƒ‚||jkr,ttdƒ|ƒ‚|j|d}t|ƒrJ||ƒS|S)NrzNo such config value: %sr)Ú
startswithÚAttributeErrorrhrr})r9r"rKr&r&r'Ú__getattr__s

zConfig.__getattr__cCs
t||ƒS)N)Úgetattr)r9r"r&r&r'Ú__getitem__szConfig.__getitem__cCst|||ƒdS)N)Úsetattr)r9r"r#r&r&r'Ú__setitem__szConfig.__setitem__cCst||ƒdS)N)Údelattr)r9r"r&r&r'Ú__delitem__szConfig.__delitem__cCs
||jkS)N)rh)r9r"r&r&r'Ú__contains__szConfig.__contains__ccs4x.|jjƒD] \}}t|t||ƒ|dƒVqWdS)NrM)rhr1rr)r9r"r#r&r&r'Ú__iter__szConfig.__iter__)r"rKr%Útypesr)cCs0||jkrttdƒ|ƒ‚n|||f|j|<dS)NzConfig value %r already present)rhrr)r9r"rKr%r•r&r&r'Úadds
z
Config.add)r%r)cs"tˆtƒrˆg‰‡fdd„|DƒS)Nc3s|]}|jˆkr|VqdS)N)r%)r+r#)r%r&r'r-$sz Config.filter.<locals>.<genexpr>)r.r!)r9r%r&)r%r'Úfilter!s
z
Config.filtercCsŠi}x4|jjƒD]&\}}|jdƒs6t|ƒr.q|||<qWi|d<xB|jjƒD]4\}}t||ƒ}t|ƒsld}||ddf|d|<qNW|S)z'Obtains serializable data for pickling.rrhNrM)r€r1rŠr*rhr)r9r€r6r#Ú
real_valuer&r&r'Ú__getstate__&s
zConfig.__getstate__)Ústater)cCs|jj|ƒdS)N)r€Úupdate)r9ršr&r&r'Ú__setstate__=szConfig.__setstate__)NN)"rrr r=r!rrrfrrr:Úclassmethodrrvrr„r‡r‰rŒrŽrr’r$r“r	rr”rr–rr
r—r™rœr&r&r&r'r>Bs

	














(
	)
 r>)rtrnr)cCs(i}||d<||d<ttj|ƒƒüy:t|dƒ&}t|jƒ|jtƒdƒ}t||ƒWdQRXWnºt	k
r–}zt
dƒ}t||ƒ|‚WYdd}~Xn„tk
rÈ}zt
dƒ}t|ƒ|‚WYdd}~XnRtk
r܂Yn>t
k
r}z t
dƒ}t|tjƒƒ|‚WYdd}~XnXWdQRX|S)	zEvaluate a config file.Ú__file__rnÚrbÚexecNz7There is a syntax error in your configuration file: %s
zKThe configuration file (or one of the modules it imports) called sys.exit()z=There is a programmable error in your configuration file:

%s)rrÚdirnameÚopenÚcompilervÚencoderr ÚSyntaxErrorrrÚ
SystemExitÚ	ExceptionÚ	tracebackÚ
format_exc)rtrnruÚfÚcodeÚerrÚmsgr~r&r&r'rrAs(.rrr)ÚapprJr)cCsr|j}t|tƒr t|diƒ|_nNt|ttfƒrDtdd„|Dƒƒ|_n*t|tƒr\t|jƒ|_ntjt	d|ƒƒdS)z’Convert old styled source_suffix to new styled one.

    * old style: str or list
    * new style: a dict which maps from fileext to filetype
    NcSsg|]}|df‘qS)Nr&)r+Úsr&r&r'ú
<listcomp>msz)convert_source_suffix.<locals>.<listcomp>zeThe config value `source_suffix' expects a string, list of strings, or dictionary. But `%r' is given.)
rZr.r!rr2r3r0rr‚r)r®rJrZr&r&r'Úconvert_source_suffix^s

r±cCs2|j}|r.tdd„|jƒDƒƒr.|j|i|_dS)z—Convert old styled highlight_options to new styled one.

    * old style: options
    * new style: a dict which maps from language name to options
    css|]}t|tƒVqdS)N)r.r0)r+Úvr&r&r'r-~sz,convert_highlight_options.<locals>.<genexpr>N)r\r5rhr[)r®rJÚoptionsr&r&r'Úconvert_highlight_optionswsr´cCs4tdƒtdƒtdƒtdƒdœ}|j|jƒ||_dS)z$Initialize :confval:`numfig_format`.z
Section %szFig. %szTable %sz
Listing %s)ÚsectionÚfigureÚtablez
code-blockN)rr›r`)r®rJr`r&r&r'Úinit_numfig_formatƒsr¸cCsFtdƒdk	rBx4dD],}||krdtdƒ}tj|||ƒ||<qWdS)zºCorrect values of copyright year that are not coherent with
    the SOURCE_DATE_EPOCH environment variable (if set)

    See https://reproducible-builds.org/specs/source-date-epoch/
    ZSOURCE_DATE_EPOCHNrSÚepub_copyrightz\g<1>%sz%Y)rSr¹)rrÚcopyright_year_reÚsub)r®rJÚkÚreplacer&r&r'Úcorrect_copyright_years

r¾c
Cs–xŽ|D]„}|j|j\}}}t|ƒr0||ƒ}|dkr@|r@q|tkrJqt|tƒrŠ|j|jƒsˆtdƒ}t	j
|j|j|j|jdddqt
|jƒt
|ƒkržqt
|jƒ|kr®qtt
|jƒjt
|jƒfƒtt
|ƒjƒ@}|jtƒ|rèq|r`tdƒ}dd„|Dƒ}t|ƒd	kr2d
jdj|dd…ƒ|dƒ}	n
d
j|ƒ}	t	j
|j|jt
|jƒ|	dddqtdƒ}t	j
|j|jt
|jƒt
|ƒdddqWdS)zCheck all values for deviation from the default value's type, since
    that can result in TypeErrors all over the place NB.
    NzTThe config value `{name}` has to be a one of {candidates}, but `{current}` is given.)r"Úcurrentr8T)ÚoncezNThe config value `{name}' has type `{current.__name__}'; expected {permitted}.cSsg|]}dj|jƒ‘qS)z`{}')Úformatr)r+rEr&r&r'r°Ász'check_confval_types.<locals>.<listcomp>rwz	{}, or {}z, rMz or )r"r¿Ú	permittedzZThe config value `{name}' has type `{current.__name__}', defaults to `{default.__name__}'.)r"r¿rKéÿÿÿÿrÃ)rhr"r}rr.r7r<r#rrr‚rÁr8rzr4Ú	__bases__ÚdiscardÚobjectÚlenro)
r®rJZconfvalrKr%Úannotationsr­Zcommon_basesZwrapped_annotationsrÂr&r&r'rˆœsL


rˆcCs2|j}|r.|jj|ƒr.tjtdƒ|ƒd|_dS)Nz%primary_domain %r not found, ignored.)r^ÚregistryZ
has_domainrr‚r)r®rJr^r&r&r'Úcheck_primary_domainÓsrÊr)r®r@ÚaddedÚchangedÚremovedr)cCs>|jjdkr:d|jjkr:d|jjkr:tjtdƒƒd|j_|S)zjAdjust root_doc to 'contents' to support an old project which does not have
    any root_doc setting.
    rHÚcontentszkSince v2.0, Sphinx uses "index" as root_doc by default. Please add "root_doc = 'contents'" to your conf.py.)rJrYrQZdocnamesrr‚r)r®r@rËrÌrÍr&r&r'Úcheck_root_docÚsrÏ)r®r)cCsx|jdtdd|jdtdd|jdtdd|jdtdd|jdtdd|jdtdd|jdtƒddddœS)Nz
config-initedi )Úpriorityzenv-get-outdatedÚbuiltinT)rTZparallel_read_safeZparallel_write_safe)Úconnectr±r´r¸r¾rˆrÊrÏ)r®r&r&r'rcésrc)Dr=Úrer¨r•ÚcollectionsrÚosrrÚtypingrrrrr	r
rrr
rrrZ
sphinx.errorsrrZ
sphinx.localerrZsphinx.utilrZsphinx.util.i18nrZsphinx.util.osutilrrZsphinx.util.tagsrZsphinx.util.typingrZsphinx.applicationrZsphinx.environmentrÚ	getLoggerrrrprzÚ
ModuleTypeÚFunctionTyper/r£rºrr$r*r7r>r!rrr±r´r¸r¾rˆrÊrÏrcr&r&r&r'Ú<module>sH8


7