o
    ¨ÊhD  ã                   @   sÚ   d dl 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mZmZmZ d dlmZmZ d dlZzeZeZW n	 eyK   Y nw dZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Ze dkrkeƒ  dS dS )é    )Úwith_statement)Úprint_function)Údatetime)ÚabspathÚdirnameÚexistsÚjoinÚisdirÚsplitext)ÚchdirÚgetcwdÚlistdirÚmkdirÚsep)ÚPopenÚPIPENz0.3c                  C   sP  t tƒ ƒD ]} t| ƒd  ¡ dkr| } n
qtƒ  tdƒ dS ttƒ dƒ}t|ƒs-t|ƒ tt|dƒdƒ�}| 	d| ¡ W d  ƒ n1 sGw   Y  tt|d	ƒdƒ�}| 	d
¡ | 	d¡ W d  ƒ n1 siw   Y  tƒ  td| ƒ zddl
}W n tyŽ   tƒ  tdƒ Y dS w t|dƒ}td||gƒ ¡  tƒ  td| ƒ dS )aE  
    Main entry point for running sphinx_me as a script.
    Creates a docs directory in the current directory and adds the
    required files for generating Sphinx docs from the project's
    README file - a conf module that calls setup_conf() from this
    module, and an index file that includes the project's README.
    r   ÚREADMEz/ABORT: No README file in the current directory.NÚdocsz	index.rstÚwz.. include:: ../%szconf.pyz5# This file is automatically generated via sphinx-me
z8from sphinx_me import setup_conf; setup_conf(globals())
z)SUCCESS: Sphinx docs layout created in %sz(Sphinx not installed. Not building docs.Úbuildzsphinx-buildzDocs built in %s)r   r   r
   ÚupperÚprintr   r	   r   ÚopenÚwriteÚsphinxÚImportErrorr   Úwait)ÚnameÚreadmeÚ	docs_pathÚfr   Ú
build_path© r"   ú;/var/www/html/env/lib/python3.10/site-packages/sphinx_me.pyÚinstall   s<   þÿ
þþ
r$   c                 C   s   t | tƒst| dd�S | S )Núutf-8)Úencoding)Ú
isinstanceÚstr)Úsr"   r"   r#   Údecode_utf8<   s   
r*   c              	   C   s”   g d¢}|  dd„ |D ƒ¡ |D ]7}zt| |ƒ}W n	 ty"   Y qw t|ƒr*|ƒ }zd dd„ | ¡ D ƒ¡}W |  S  tyG   Y |  S w dS )z‰
    Attempts to read a version attribute from the given module that
    could be specified via several different names and formats.
    )Ú__version__Úget_versionÚversionc                 S   s   g | ]}|  ¡ ‘qS r"   )r   )Ú.0r   r"   r"   r#   Ú
<listcomp>H   ó    zget_version.<locals>.<listcomp>Ú.c                 S   ó   g | ]}t |ƒ‘qS r"   )r(   )r.   Úir"   r"   r#   r/   Q   r0   N)ÚextendÚgetattrÚAttributeErrorÚcallabler   Ú__iter__)ÚmoduleÚversion_namesr   r-   r"   r"   r#   r,   B   s$   ÿþþ÷r,   c                 C   s,   d|d|  g}t |td� ¡ d  d¡ ¡ S )z¸
    Runs the project's setup.py script in a process with an arg that
    will print out the value for a particular attribute such as author
    or version, and returns the value.
    Úpythonz--%s)Ústdoutr   r%   )r   r   ÚcommunicateÚdecodeÚstrip)Ú	attributeÚ
setup_pathÚargsr"   r"   r#   Úget_setup_attributeW   s   rC   c              
      s†  t tt| d ƒdƒƒ}t|ƒ tj d|¡ d}d}d}d}t||ƒ}|f}t|ƒrPzddl}W n	 t	y9   Y nw t
d|ƒ}|dkrEd}t
d	|ƒ}|d
krPd}t|ƒD ]v}	t||	ƒ}
|	 ¡ |kr‹t|
dƒ�}| ¡ D ]}| d¡}|rzt|ƒ} nqkW d  ƒ n1 s…w   Y  qT|	|vrÊt|
ƒs›t|	ƒd dkrÊzt|	ƒ}W n t	tfy¬   Y qTw |s³t|ƒ}|rÊ|sÊz	tt|dƒƒ}W qT tyÉ   Y qTw qT|sÑtdƒ}|sûtdƒ}t|ƒ}tt||ƒdƒ�}| | d¡¡ W d  ƒ n1 söw   Y  ||| t¡ t¡d ddt ¡ j |f dœ}t!dd„ | "¡ D ƒƒd ‰ t#ƒ  t#dƒ t#ƒ  t#d ‡ fdd„| $¡ D ƒ¡ƒ t#ƒ  |  %|¡ dS )a  
    Setup function that is called from within the project's
    docs/conf.py module that takes the conf module's globals() and
    assigns the values that can be automatically determined from the
    current project, such as project name, package name, version and
    author.
    Ú__file__z..r   ÚAUTHORSNzsetup.pyr-   z0.0.0ÚauthorÚUNKNOWNÚrz*- 
	é   z.pyÚ
__author__z+No version number found, please enter one: z#No author found, please enter one: Úwbr%   éÿÿÿÿÚindexz%s, %s)r-   ÚreleaseÚprojectÚ
master_docÚ	copyrightc                 S   r2   r"   )Úlen)r.   Úkr"   r"   r#   r/   «   r0   zsetup_conf.<locals>.<listcomp>é   z%sphinx-me using the following values:Ú
c                    s"   g | ]\}}|d    ˆ ¡| ‘qS )ú:)Úljust)r.   rS   Úv©Úpadr"   r#   r/   ¯   s   " )&r   r   r   r   ÚsysÚpathÚinsertr   Ú
setuptoolsr   rC   r   r   r   Ú	readlinesr?   r*   r	   r
   Ú
__import__Ú
ValueErrorr,   r5   r6   Úinputr   ÚencodeÚrstripr   Úsplitr   ÚnowÚyearÚmaxÚkeysr   ÚitemsÚupdate)Úconf_globalsÚproject_pathÚauthors_filer-   rF   ÚsetuprA   Úignorer^   r   r\   r    Úliner9   Úsettingsr"   rY   r#   Ú
setup_confa   sŒ   
ÿ



þ€ý€ ÿÿ€ÿû rs   Ú__main__)!Ú
__future__r   r   r   Úos.pathr   r   r   r   r	   r
   Úosr   r   r   r   r   Ú
subprocessr   r   r[   Ú	raw_inputrb   Úunicoder(   Ú	NameErrorr+   r$   r*   r,   rC   rs   Ú__name__r"   r"   r"   r#   Ú<module>   s,    ÿ'
S
ÿ