2019-01-27 00:13:42 +00:00
|
|
|
from __future__ import print_function
|
2020-04-26 20:50:55 +00:00
|
|
|
from io import open as io_open
|
2019-11-08 23:41:19 +00:00
|
|
|
from os import path
|
|
|
|
import sys
|
2020-04-26 20:50:55 +00:00
|
|
|
from textwrap import dedent
|
|
|
|
|
2020-04-24 21:26:31 +00:00
|
|
|
sys.path.insert(0, path.dirname(path.dirname(__file__))) # NOQA
|
2019-01-27 00:13:42 +00:00
|
|
|
import tqdm
|
2019-08-26 15:40:03 +00:00
|
|
|
import tqdm.cli
|
2020-04-26 20:50:55 +00:00
|
|
|
|
2019-01-27 00:13:42 +00:00
|
|
|
|
|
|
|
HEAD_ARGS = """
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
"""
|
|
|
|
HEAD_RETS = """
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
"""
|
|
|
|
HEAD_CLI = """
|
|
|
|
Extra CLI Options
|
|
|
|
-----------------
|
|
|
|
name : type, optional
|
|
|
|
TODO: find out why this is needed.
|
|
|
|
"""
|
|
|
|
|
2019-01-27 00:29:13 +00:00
|
|
|
|
2019-05-13 16:33:42 +00:00
|
|
|
def doc2rst(doc, arglist=True, raw=False):
|
2019-01-27 00:13:42 +00:00
|
|
|
"""
|
|
|
|
arglist : bool, whether to create argument lists
|
2019-05-13 16:33:42 +00:00
|
|
|
raw : bool, ignores arglist and indents by 2 spaces
|
2019-01-27 00:13:42 +00:00
|
|
|
"""
|
2019-05-13 16:33:42 +00:00
|
|
|
doc = doc.replace('`', '``')
|
|
|
|
if raw:
|
|
|
|
doc = doc.replace('\n ', '\n ')
|
|
|
|
else:
|
|
|
|
doc = dedent(doc)
|
|
|
|
if arglist:
|
|
|
|
doc = '\n'.join([i if not i or i[0] == ' ' else '* ' + i + ' '
|
|
|
|
for i in doc.split('\n')])
|
2019-01-27 00:13:42 +00:00
|
|
|
return doc
|
|
|
|
|
|
|
|
|
|
|
|
src_dir = path.abspath(path.dirname(__file__))
|
|
|
|
README_rst = path.join(src_dir, '.readme.rst')
|
|
|
|
with io_open(README_rst, mode='r', encoding='utf-8') as fd:
|
|
|
|
README_rst = fd.read()
|
|
|
|
DOC_tqdm = doc2rst(tqdm.tqdm.__doc__, False).replace('\n', '\n ')
|
|
|
|
DOC_tqdm_init = doc2rst(tqdm.tqdm.__init__.__doc__)
|
|
|
|
DOC_tqdm_init_args = DOC_tqdm_init.partition(doc2rst(HEAD_ARGS))[-1]\
|
|
|
|
.replace('\n ', '\n ')
|
|
|
|
DOC_tqdm_init_args, _, DOC_tqdm_init_rets = DOC_tqdm_init_args\
|
|
|
|
.partition(doc2rst(HEAD_RETS))
|
2019-08-26 15:40:03 +00:00
|
|
|
DOC_cli = doc2rst(tqdm.cli.CLI_EXTRA_DOC).partition(doc2rst(HEAD_CLI))[-1]
|
2019-05-13 16:33:42 +00:00
|
|
|
DOC_tqdm_tqdm = {}
|
|
|
|
for i in dir(tqdm.tqdm):
|
|
|
|
doc = getattr(tqdm.tqdm, i).__doc__
|
|
|
|
if doc:
|
|
|
|
DOC_tqdm_tqdm[i] = doc2rst(doc, raw=True)
|
2019-01-27 00:13:42 +00:00
|
|
|
|
|
|
|
# special cases
|
|
|
|
DOC_tqdm_init_args = DOC_tqdm_init_args.replace(' *,', ' ``*``,')
|
|
|
|
DOC_tqdm_init_args = DOC_tqdm_init_args.partition('* gui : bool, optional')[0]
|
|
|
|
|
|
|
|
README_rst = README_rst.replace('{DOC_tqdm}', DOC_tqdm)\
|
|
|
|
.replace('{DOC_tqdm.tqdm.__init__.Parameters}', DOC_tqdm_init_args)\
|
2019-08-26 15:40:03 +00:00
|
|
|
.replace('{DOC_tqdm.cli.CLI_EXTRA_DOC}', DOC_cli)\
|
2019-01-27 00:13:42 +00:00
|
|
|
.replace('{DOC_tqdm.tqdm.__init__.Returns}', DOC_tqdm_init_rets)
|
2019-05-13 16:33:42 +00:00
|
|
|
for k, v in DOC_tqdm_tqdm.items():
|
|
|
|
README_rst = README_rst.replace('{DOC_tqdm.tqdm.%s}' % k, v)
|
2019-01-27 00:13:42 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-05-14 13:44:38 +00:00
|
|
|
fndoc = path.join(path.dirname(src_dir), 'README.rst')
|
2019-01-27 00:13:42 +00:00
|
|
|
with io_open(fndoc, mode='w', encoding='utf-8') as fd:
|
|
|
|
fd.write(README_rst)
|