3

T'íc”!ã@s(dZddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
ddlmZyddl
mZWn ek
r„ddlmZYnXddlmZddlmZdd	lmZdd
lmZddlmZerÒddlmZejeƒZe ƒZ!d
Z"e#e#ddœdd„Z$Gdd„dƒZ%e#e&dœdd„Z'Gdd„dƒZ(dS)z"Theming support for HTML builders.éN)Úpath)Ú
TYPE_CHECKINGÚAnyÚDictÚList)ÚZipFile)Úentry_points)Úpackage_dir)Ú
ThemeError)Ú__)Úlogging)Ú	ensuredir)ÚSphinxz
theme.conf)ÚfilenameÚ	targetdirÚreturncCs„t|ƒt|ƒj}xb|jƒD]V}|jdƒr,qtj||ƒ}ttj|ƒƒttj|ƒdƒ}|j|j	|ƒƒWdQRXqWWdQRXdS)z%Extract zip file to target directory.ú/ÚwbN)
r
rÚnamelistÚendswithrÚjoinÚdirnameÚopenÚwriteÚread)rrÚarchiveÚnameÚentryÚfp©rú0/tmp/pip-build-gk9425m9/sphinx/sphinx/theming.pyÚextract_zip s

r!c@s€eZdZdZeedddœdd„Zeedœdd	„Zefeee	e	d
œdd„Z
ifeee	feee	fd
œdd„Zddœdd„Z
dS)ÚThemez†A Theme is a set of HTML templates and configurations.

    This class supports both theme directory and theme archive (zipped theme).ÚHTMLThemeFactoryN)rÚ
theme_pathÚfactoryrcCsJ||_d|_d|_tj|ƒr*d|_||_n(tjdƒ|_tj|j|ƒ|_t	||jƒt
jƒ|_|jj
tj|jtƒƒy|jjddƒ}Wnjt
jk
rº}zttdƒ|ƒ|‚WYdd}~Xn6t
jk
rî}zttdƒ|ƒ|‚WYdd}~XnX|dkrFy|j|ƒ|_Wn:tk
rD}zttdƒ||fƒ|‚WYdd}~XnXdS)NZsxtÚthemeÚinheritz%theme %r doesn't have "theme" settingz'theme %r doesn't have "inherit" settingÚnonez(no theme named %r found, inherited by %r)rÚbaseÚrootdirrÚisdirÚthemedirÚtempfileÚmkdtemprr!ÚconfigparserÚRawConfigParserÚconfigrÚ	THEMECONFÚgetÚNoSectionErrorr
rÚ
NoOptionErrorÚcreate)Úselfrr$r%r'Úexcrrr Ú__init__3s.

"$
zTheme.__init__)rcCs(|jdkr|jgS|jg|jjƒSdS)z‹Return a list of theme directories, beginning with this theme's,
        then the base theme's, then that one's base theme's, etc.
        N)r)r,Úget_theme_dirs)r7rrr r:Ss
zTheme.get_theme_dirs)ÚsectionrÚdefaultrcCsxy|jj||ƒStjtjfk
rr}z@|jr>|jj|||ƒS|tkr^tt	dƒ||fƒ|‚n|SWYdd}~XnXdS)zdReturn the value for a theme configuration setting, searching the
        base theme chain.
        z:setting %s.%s occurs in none of the searched theme configsN)
r1r3r/r5r4r)Ú
get_configÚ	NODEFAULTr
r)r7r;rr<r8rrr r=\szTheme.get_config)Ú	overridesrcCs‚|jr|jjƒ}ni}y|j|jjdƒƒWntjk
rBYnXx8|jƒD],\}}||krrtjt	dƒ|ƒqN|||<qNW|S)z6Return a dictionary of theme options and their values.Úoptionsz!unsupported theme option %r given)
r)Úget_optionsÚupdater1Úitemsr/r4ÚloggerÚwarningr)r7r?r@ÚoptionÚvaluerrr rAlszTheme.get_optionscCs@|jr,ytj|jƒWntk
r*YnX|jr<|jjƒdS)zRemove temporary directories.N)r*ÚshutilÚrmtreeÚ	Exceptionr)Úcleanup)r7rrr rK€sz
Theme.cleanup)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr9rr:r>rr=rrArKrrrr r".s 	$r")rrcCs:y t|ƒ}t|jƒkSQRXWntk
r4dSXdS)zBCheck whether the specified file is an archived theme file or not.NF)rr2rrJ)rÚfrrr Úis_archived_theme‹s

rRc@s¢eZdZdZdddœdd„Zddœdd	„Zedd
œdd„Zedd
œdd„Zddœdd„Z	ddœdd„Z
edd
œdd„Zeeeefdœdd„Z
eed
œdd„ZdS)r#z A factory class for HTML Themes.rN)ÚapprcCs8||_|jj|_|jƒt|jddƒr4|j|jjƒdS)NÚhtml_theme_path)	rSÚregistryZhtml_themesÚthemesÚload_builtin_themesÚgetattrr1Úload_additional_themesrT)r7rSrrr r9—s

zHTMLThemeFactory.__init__)rcCs6|jtjtdƒƒ}x|jƒD]\}}||j|<qWdS)zLoad built-in themes.rVN)Úfind_themesrrr	rCrV)r7rVrr&rrr rWžsz$HTMLThemeFactory.load_builtin_themes)Útheme_pathsrcCsRxL|D]D}tjtj|jj|ƒƒ}|j|ƒ}x|jƒD]\}}||j|<q4WqWdS)z7Load additional themes placed at specified directories.N)rÚabspathrrSZconfdirrZrCrV)r7r[r$Zabs_theme_pathrVrr&rrr rY¤s


z'HTMLThemeFactory.load_additional_themes)rrcCs |dkr|jƒn
|j|ƒdS)z,Try to load a theme with the specified name.Ú	alabasterN)Úload_alabaster_themeÚload_external_theme)r7rrrr Úload_extra_theme¬s
z!HTMLThemeFactory.load_extra_themecCs"ddl}tj|jƒdƒ|jd<dS)zLoad alabaster theme.rNr])r]rrÚget_pathrV)r7r]rrr r^³sz%HTMLThemeFactory.load_alabaster_themecCs@y&ddl}|jƒ}tj|dƒ|jd<Wntk
r:YnXdS)z+Load sphinx_rtd_theme theme (if installed).rNÚsphinx_rtd_theme)rbZget_html_theme_pathrrrVÚImportError)r7rbr$rrr Úload_sphinx_rtd_theme¸sz&HTMLThemeFactory.load_sphinx_rtd_themecCsPtdd}y,||}|jjj|j|jƒ|jjjƒdStk
rJYnXdS)zjTry to load a theme using entry_points.

        Sphinx refers to ``sphinx_themes`` entry_points.
        zsphinx.html_themes)ÚgroupN)rrSrUZload_extensionÚmoduler1Zpost_init_valuesÚKeyError)r7rZtheme_entry_pointsZentry_pointrrr r_Ás
z$HTMLThemeFactory.load_external_theme)r$rcCs˜i}tj|ƒs|Sx€tj|ƒD]r}tj||ƒ}tj|ƒrv|jƒjdƒrvt|ƒrd|dd…}|||<qt	j
tdƒ|ƒqtjtj|tƒƒr|||<qW|S)z'Search themes from specified directory.z.zipNézAfile %r on theme path is not a valid zipfile or contains no themeéüÿÿÿ)
rr+ÚosÚlistdirrÚisfileÚlowerrrRrDrErr2)r7r$rVrÚpathnamerrrr rZÐs


zHTMLThemeFactory.find_themescCsj||jkr|j|ƒ||jkr<|dkr<tjtdƒƒ|jƒ||jkrVttdƒ|ƒ‚t||j||dS)zCreate an instance of theme.rbzKsphinx_rtd_theme (< 0.3.0) found. It will not be available since Sphinx-6.0z-no theme named %r found (missing theme.conf?))r%)rVr`rDrErrdr
r")r7rrrr r6ås


zHTMLThemeFactory.create)rLrMrNrOr9rWrPrYr`r^rdr_rrZr"r6rrrr r#”s	r#))rOr/rjrHr-rÚtypingrrrrÚzipfilerZimportlib_metadatarrcZimportlib.metadataZsphinxr	Z
sphinx.errorsr
Z
sphinx.localerZsphinx.utilrZsphinx.util.osutilr
Zsphinx.applicationrÚ	getLoggerrLrDÚobjectr>r2rPr!r"ÚboolrRr#rrrr Ú<module>s2
]