コード例 #1
0
def test_quickstart_defaults(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['extensions'] == []
    assert ns['templates_path'] == ['_templates']
    assert ns['source_suffix'] == '.rst'
    assert ns['master_doc'] == 'index'
    assert ns['project'] == 'Sphinx Test'
    assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
    assert ns['version'] == '0.1'
    assert ns['release'] == '0.1'
    assert ns['todo_include_todos'] is False
    assert ns['html_static_path'] == ['_static']
    assert ns['latex_documents'] == [
        ('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
         'Georg Brandl', 'manual')]

    assert (tempdir / '_static').isdir()
    assert (tempdir / '_templates').isdir()
    assert (tempdir / 'index.rst').isfile()
    assert (tempdir / 'Makefile').isfile()
    assert (tempdir / 'make.bat').isfile()
コード例 #2
0
ファイル: test_quickstart.py プロジェクト: Felix-neko/sphinx
def test_quickstart_defaults(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['extensions'] == []
    assert ns['templates_path'] == ['_templates']
    assert ns['source_suffix'] == '.rst'
    assert ns['master_doc'] == 'index'
    assert ns['project'] == 'Sphinx Test'
    assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
    assert ns['version'] == '0.1'
    assert ns['release'] == '0.1'
    assert ns['todo_include_todos'] is False
    assert ns['html_static_path'] == ['_static']
    assert ns['latex_documents'] == [
        ('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
         'Georg Brandl', 'manual')]

    assert (tempdir / '_static').isdir()
    assert (tempdir / '_templates').isdir()
    assert (tempdir / 'index.rst').isfile()
    assert (tempdir / 'Makefile').isfile()
    assert (tempdir / 'make.bat').isfile()
コード例 #3
0
def monkey_patch_ask_user(d):
    global hook_d

    org_do_prompt = None

    if not qsp_ask_latest():
        org_do_prompt = quickstart.do_prompt

        # monkey patch
        def _do_prompt(_d, key, text, default=None, validator=nonempty):
            default = hook_d.get(key, default)
            if isinstance(default, bool):
                default = 'y' if hook_d[key] else 'n'
            org_do_prompt(_d, key, text, default, validator)

        quickstart.do_prompt = _do_prompt
    else:
        d.update(hook_d)
        _print_default_setting(d)
        print()

    ask_user(d)
    qsp_ask_user(d)

    if org_do_prompt:
        quickstart.do_prompt = org_do_prompt
コード例 #4
0
ファイル: test_quickstart.py プロジェクト: jklukas/sphinx
def test_quickstart_all_answers(tempdir):
    answers = {
        'Root path': tempdir,
        'Separate source and build': 'y',
        'Name prefix for templates': '.',
        'Project name': u'STASI™'.encode('utf-8'),
        'Author name': u'Wolfgang Schäuble & G\'Beckstein'.encode('utf-8'),
        'Project version': '2.0',
        'Project release': '2.0.1',
        'Source file suffix': '.txt',
        'Name of your master document': 'contents',
        'autodoc': 'y',
        'doctest': 'yes',
        'intersphinx': 'no',
        'todo': 'n',
        'coverage': 'no',
        'pngmath': 'N',
        'mathjax': 'no',
        'ifconfig': 'no',
        'viewcode': 'no',
        'Create Makefile': 'no',
        'Create Windows command file': 'no',
        'Do you want to use the epub builder': 'yes',
    }
    qs.term_input = mock_raw_input(answers, needanswer=True)
    qs.TERM_ENCODING = 'utf-8'
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'source' / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
    assert ns['templates_path'] == ['.templates']
    assert ns['source_suffix'] == '.txt'
    assert ns['master_doc'] == 'contents'
    assert ns['project'] == u'STASI™'
    assert ns['copyright'] == u'%s, Wolfgang Schäuble & G\'Beckstein' % \
           time.strftime('%Y')
    assert ns['version'] == '2.0'
    assert ns['release'] == '2.0.1'
    assert ns['html_static_path'] == ['.static']
    assert ns['latex_documents'] == [
        ('contents', 'STASI.tex', u'STASI™ Documentation',
         u'Wolfgang Schäuble \\& G\'Beckstein', 'manual')]
    assert ns['epub_author'] == u'Wolfgang Schäuble & G\'Beckstein'
    assert ns['man_pages'] == [
        ('contents', 'stasi', u'STASI™ Documentation',
         [u'Wolfgang Schäuble & G\'Beckstein'], 1)]
    assert ns['texinfo_documents'] == [
        ('contents', 'STASI', u'STASI™ Documentation',
         u'Wolfgang Schäuble & G\'Beckstein', 'STASI',
         'One line description of project.', 'Miscellaneous'),]

    assert (tempdir / 'build').isdir()
    assert (tempdir / 'source' / '.static').isdir()
    assert (tempdir / 'source' / '.templates').isdir()
    assert (tempdir / 'source' / 'contents.txt').isfile()
コード例 #5
0
ファイル: thpppt.py プロジェクト: davidmiller/thpppt
    def sphinx(self):
        """
        Initialize Sphinx documentation for this project.


        Return: None
        Exceptions: None
        """
        try:
            from sphinx import quickstart
        except ImportError:
            print "Can't import Sphinx. Skipping"
            return

        sphinxopts = dict(dotfile.items("sphinx"))
        for f in sphinxopts:
            if sphinxopts[f] in ["False"]:
                sphinxopts[f] = False
            if sphinxopts[f] in ["True"]:
                sphinxopts[f] = True

        sphinxopts["path"] = self.root + "doc"
        sphinxopts["project"] = args.name
        if variable("author", None, ask="Project Author"):
            sphinxopts["author"] = variable("author", None)
        sphinxopts["version"] = self.version
        sphinxopts["release"] = self.version

        quickstart.ask_user(sphinxopts)
        quickstart.generate(sphinxopts)
        return
コード例 #6
0
ファイル: test_quickstart.py プロジェクト: Felix-neko/sphinx
def test_generated_files_eol(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    def assert_eol(filename, eol):
        content = filename.bytes().decode('unicode-escape')
        assert all([l[-len(eol):] == eol for l in content.splitlines(True)])

    assert_eol(tempdir / 'make.bat', '\r\n')
    assert_eol(tempdir / 'Makefile', '\n')
コード例 #7
0
def test_generated_files_eol(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    def assert_eol(filename, eol):
        content = filename.bytes().decode('unicode-escape')
        assert all([l[-len(eol):] == eol for l in content.splitlines(True)])

    assert_eol(tempdir / 'make.bat', '\r\n')
    assert_eol(tempdir / 'Makefile', '\n')
コード例 #8
0
ファイル: test_quickstart.py プロジェクト: Felix-neko/sphinx
def test_default_filename(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': u'\u30c9\u30a4\u30c4',  # Fullwidth characters only
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['latex_documents'][0][1] == 'sphinx.tex'
    assert ns['man_pages'][0][1] == 'sphinx'
    assert ns['texinfo_documents'][0][1] == 'sphinx'
コード例 #9
0
def test_default_filename(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': u'\u30c9\u30a4\u30c4',  # Fullwidth characters only
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['latex_documents'][0][1] == 'sphinx.tex'
    assert ns['man_pages'][0][1] == 'sphinx'
    assert ns['texinfo_documents'][0][1] == 'sphinx'
コード例 #10
0
ファイル: test_quickstart.py プロジェクト: wuxi20/Pythonista
def test_quickstart_defaults(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_raw_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    f = open(conffile, 'rbU')
    try:
        code = compile(f.read(), conffile, 'exec')
    finally:
        f.close()
    exec code in ns
    assert ns['extensions'] == []
    assert ns['templates_path'] == ['_templates']
    assert ns['source_suffix'] == '.rst'
    assert ns['master_doc'] == 'index'
    assert ns['project'] == 'Sphinx Test'
    assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
    assert ns['version'] == '0.1'
    assert ns['release'] == '0.1'
    assert ns['html_static_path'] == ['_static']
    assert ns['latex_documents'] == [
        ('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
         'Georg Brandl', 'manual')
    ]

    assert (tempdir / '_static').isdir()
    assert (tempdir / '_templates').isdir()
    assert (tempdir / 'index.rst').isfile()
    assert (tempdir / 'Makefile').isfile()
    assert (tempdir / 'make.bat').isfile()
コード例 #11
0
ファイル: test_quickstart.py プロジェクト: APSL/django-braces
def test_quickstart_defaults(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Sphinx Test',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_raw_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    f = open(conffile, 'rbU')
    try:
        code = compile(f.read(), conffile, 'exec')
    finally:
        f.close()
    exec code in ns
    assert ns['extensions'] == []
    assert ns['templates_path'] == ['_templates']
    assert ns['source_suffix'] == '.rst'
    assert ns['master_doc'] == 'index'
    assert ns['project'] == 'Sphinx Test'
    assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
    assert ns['version'] == '0.1'
    assert ns['release'] == '0.1'
    assert ns['html_static_path'] == ['_static']
    assert ns['latex_documents'] == [
        ('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
         'Georg Brandl', 'manual')]

    assert (tempdir / '_static').isdir()
    assert (tempdir / '_templates').isdir()
    assert (tempdir / 'index.rst').isfile()
    assert (tempdir / 'Makefile').isfile()
    assert (tempdir / 'make.bat').isfile()
コード例 #12
0
def test_quickstart_and_build(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': u'Fullwidth characters: \u30c9\u30a4\u30c4',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    app = application.Sphinx(
        tempdir,  # srcdir
        tempdir,  # confdir
        (tempdir / '_build' / 'html'),  # outdir
        (tempdir / '_build' / '.doctree'),  # doctreedir
        'html',  # buildername
        status=StringIO(),
        warning=warnfile)
    app.builder.build_all()
    warnings = warnfile.getvalue()
    assert not warnings
コード例 #13
0
ファイル: test_quickstart.py プロジェクト: Felix-neko/sphinx
def test_quickstart_and_build(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': u'Fullwidth characters: \u30c9\u30a4\u30c4',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    app = application.Sphinx(
        tempdir,  # srcdir
        tempdir,  # confdir
        (tempdir / '_build' / 'html'),  # outdir
        (tempdir / '_build' / '.doctree'),  # doctreedir
        'html',  # buildername
        status=StringIO(),
        warning=warnfile)
    app.builder.build_all()
    warnings = warnfile.getvalue()
    assert not warnings
コード例 #14
0
ファイル: test_quickstart.py プロジェクト: qsnake/sphinx
def test_quickstart_defaults(tempdir):
    answers = {
        "Root path": tempdir,
        "Project name": "Sphinx Test",
        "Author name": "Georg Brandl",
        "Project version": "0.1",
    }
    qs.term_input = mock_raw_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / "conf.py"
    assert conffile.isfile()
    ns = {}
    f = open(conffile, "U")
    try:
        code = compile(f.read(), conffile, "exec")
    finally:
        f.close()
    exec code in ns
    assert ns["extensions"] == []
    assert ns["templates_path"] == ["_templates"]
    assert ns["source_suffix"] == ".rst"
    assert ns["master_doc"] == "index"
    assert ns["project"] == "Sphinx Test"
    assert ns["copyright"] == "%s, Georg Brandl" % time.strftime("%Y")
    assert ns["version"] == "0.1"
    assert ns["release"] == "0.1"
    assert ns["html_static_path"] == ["_static"]
    assert ns["latex_documents"] == [("index", "SphinxTest.tex", "Sphinx Test Documentation", "Georg Brandl", "manual")]

    assert (tempdir / "_static").isdir()
    assert (tempdir / "_templates").isdir()
    assert (tempdir / "index.rst").isfile()
    assert (tempdir / "Makefile").isfile()
    assert (tempdir / "make.bat").isfile()
コード例 #15
0
ファイル: hooks.py プロジェクト: gawel/mr.boby.rodriguez
def post_render(config):

    target_directory = os.path.abspath(config.target_directory)
    pkg = config.variables['package.directory']

    pkg_dir = os.path.join(target_directory, pkg)
    if not test.d(pkg_dir):
        mkdir(pkg_dir)
        with open(os.path.join(pkg_dir, '__init__.py'), 'wb') as fd:
            fd.write('#  package\n')

    doc_root = os.path.join(target_directory, 'docs')
    vars = config.variables
    d = dict(path=doc_root, author=vars['author.name'],
             project=vars['package.name'],
             version='', ext_autodoc='y', ext_viewcode='y',
             batchfile=False)

    quickstart_do_prompt = quickstart.do_prompt

    def do_prompt(d, key, text, default=None, validator=quickstart.nonempty):
        print(key)
        if key in use_defaults:
            if default == 'y':
                default = True
            elif default == 'n':
                default = False
            d[key] = default
        elif key not in d:
            quickstart_do_prompt(d, key, text, default, validator)

    quickstart.do_prompt = do_prompt

    if not os.path.isdir(doc_root):
        # launch sphinx
        quickstart.ask_user(d)
        quickstart.generate(d)
        filename = os.path.join(doc_root, 'conf.py')

        # patch some files
        with open(filename, 'ab') as fd:
            fd.write('''
html_theme = 'nature'
import pkg_resources
version = pkg_resources.get_distribution("%s").version
release = version
''' % vars['package.name'])
        filename = os.path.join(doc_root, 'Makefile')
        with open(filename, 'rb') as fd:
            data = fd.read()
        data = data.replace('sphinx-build', '../bin/sphinx-build')
        with open(filename, 'wb') as fd:
            fd.write(data)

    # launch buildout
    cd(target_directory)
    if not test.f('bootstrap.py'):
        wget('-O bootstrap.py',
             'https://bootstrap.pypa.io/bootstrap-buildout.py') > 1
        chmod('+x bootstrap.py')

    sh.python('bootstrap.py --allow-site-packages') > 1
    if test.f('bin/buildout'):
        sh.python('bin/buildout') > 1
コード例 #16
0
def test_quickstart_all_answers(tempdir):
    answers = {
        'Root path': tempdir,
        'Separate source and build': 'y',
        'Name prefix for templates': '.',
        'Project name': u'STASI™'.encode('utf-8'),
        'Author name': u'Wolfgang Schäuble & G\'Beckstein'.encode('utf-8'),
        'Project version': '2.0',
        'Project release': '2.0.1',
        'Project language': 'de',
        'Source file suffix': '.txt',
        'Name of your master document': 'contents',
        'autodoc': 'y',
        'doctest': 'yes',
        'intersphinx': 'no',
        'todo': 'y',
        'coverage': 'no',
        'imgmath': 'N',
        'mathjax': 'no',
        'ifconfig': 'no',
        'viewcode': 'no',
        'githubpages': 'no',
        'Create Makefile': 'no',
        'Create Windows command file': 'no',
        'Do you want to use the epub builder': 'yes',
    }
    qs.term_input = mock_input(answers, needanswer=True)
    qs.TERM_ENCODING = 'utf-8'
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / 'source' / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['extensions'] == [
        'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo'
    ]
    assert ns['templates_path'] == ['.templates']
    assert ns['source_suffix'] == '.txt'
    assert ns['master_doc'] == 'contents'
    assert ns['project'] == u'STASI™'
    assert ns['copyright'] == u'%s, Wolfgang Schäuble & G\'Beckstein' % \
        time.strftime('%Y')
    assert ns['version'] == '2.0'
    assert ns['release'] == '2.0.1'
    assert ns['todo_include_todos'] is True
    assert ns['html_static_path'] == ['.static']
    assert ns['latex_documents'] == [
        ('contents', 'STASI.tex', u'STASI™ Documentation',
         u'Wolfgang Schäuble \\& G\'Beckstein', 'manual')]
    assert ns['epub_author'] == u'Wolfgang Schäuble & G\'Beckstein'
    assert ns['man_pages'] == [
        ('contents', 'stasi', u'STASI™ Documentation',
         [u'Wolfgang Schäuble & G\'Beckstein'], 1)]
    assert ns['texinfo_documents'] == [
        ('contents', 'STASI', u'STASI™ Documentation',
         u'Wolfgang Schäuble & G\'Beckstein', 'STASI',
         'One line description of project.', 'Miscellaneous')]

    assert (tempdir / 'build').isdir()
    assert (tempdir / 'source' / '.static').isdir()
    assert (tempdir / 'source' / '.templates').isdir()
    assert (tempdir / 'source' / 'contents.txt').isfile()
コード例 #17
0
"ext_pngmath": true,
"sep": true,
"ext_todo": false,
"ext_coverage": false,
"ext_viewcode": false,
"batchfile": true,
"master": "index",
"epub": false,
"ext_intersphinx": false,
"dot": "_",
"ext_doctest": false
}'''

# Load the options from the json string into a Python dict
options = json.loads(json_conf)

# Everything below is copied from quickstart.py: you need not understand it
# unless noted

if not color_terminal():
    nocolor()

try:
    #Ask the user for the rest of the options
    qs.ask_user(options)
except (KeyboardInterrupt, EOFError):
    print
    print '[Interrupted.]'
    exit()
qs.generate(options)
コード例 #18
0
ファイル: test_quickstart.py プロジェクト: qsnake/sphinx
def test_quickstart_all_answers(tempdir):
    answers = {
        "Root path": tempdir,
        "Separate source and build": "y",
        "Name prefix for templates": ".",
        "Project name": u"STASI™".encode("utf-8"),
        "Author name": u"Wolfgang Schäuble & G'Beckstein".encode("utf-8"),
        "Project version": "2.0",
        "Project release": "2.0.1",
        "Source file suffix": ".txt",
        "Name of your master document": "contents",
        "autodoc": "y",
        "doctest": "yes",
        "intersphinx": "no",
        "todo": "n",
        "coverage": "no",
        "pngmath": "N",
        "mathjax": "no",
        "ifconfig": "no",
        "viewcode": "no",
        "Create Makefile": "no",
        "Create Windows command file": "no",
        "Do you want to use the epub builder": "yes",
    }
    qs.term_input = mock_raw_input(answers, needanswer=True)
    qs.TERM_ENCODING = "utf-8"
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    conffile = tempdir / "source" / "conf.py"
    assert conffile.isfile()
    ns = {}
    f = open(conffile, "U")
    try:
        code = compile(f.read(), conffile, "exec")
    finally:
        f.close()
    exec code in ns
    assert ns["extensions"] == ["sphinx.ext.autodoc", "sphinx.ext.doctest"]
    assert ns["templates_path"] == [".templates"]
    assert ns["source_suffix"] == ".txt"
    assert ns["master_doc"] == "contents"
    assert ns["project"] == u"STASI™"
    assert ns["copyright"] == u"%s, Wolfgang Schäuble & G'Beckstein" % time.strftime("%Y")
    assert ns["version"] == "2.0"
    assert ns["release"] == "2.0.1"
    assert ns["html_static_path"] == [".static"]
    assert ns["latex_documents"] == [
        ("contents", "STASI.tex", u"STASI™ Documentation", u"Wolfgang Schäuble \\& G'Beckstein", "manual")
    ]
    assert ns["epub_author"] == u"Wolfgang Schäuble & G'Beckstein"
    assert ns["man_pages"] == [("contents", "stasi", u"STASI™ Documentation", [u"Wolfgang Schäuble & G'Beckstein"], 1)]
    assert ns["texinfo_documents"] == [
        (
            "contents",
            "STASI",
            u"STASI™ Documentation",
            u"Wolfgang Schäuble & G'Beckstein",
            "STASI",
            "One line description of project.",
            "Miscellaneous",
        )
    ]

    assert (tempdir / "build").isdir()
    assert (tempdir / "source" / ".static").isdir()
    assert (tempdir / "source" / ".templates").isdir()
    assert (tempdir / "source" / "contents.txt").isfile()