Ejemplo n.º 1
0
    def generate_project_files(self, sub_dir=''):
        """Generate the project files (`*.rst` files).

        :param str sub_dir: A sub-directory of the :attr:`project_source_dir`
            where the module documentation will be generated in.
        """
        self.validate_project_and_package()

        from sphinx.apidoc import main
        argv = [
            '',  # Will be skipped.
            '-e',  # Separate pages/files for every module
            '-o',
            str(self.project_source_dir / sub_dir),
            str(self.package_dir),  # Package to document
        ]

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except:
            raise SphinxError
        finally:
            sys.argv = old_argv
Ejemplo n.º 2
0
    def generate_project_files(self, sub_dir=''):
        """Generate the project files (`*.rst` files).

        :param str sub_dir: A sub-directory of the :attr:`project_source_dir`
            where the module documentation will be generated in.
        """
        self.validate_project_and_package()

        from sphinx.apidoc import main
        argv = [
            '',  # Will be skipped.
            '-e',  # Separate pages/files for every module
            '-o',
            str(self.project_source_dir / sub_dir),
            str(self.package_dir),  # Package to document
        ]

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except:
            raise SphinxError
        finally:
            sys.argv = old_argv
Ejemplo n.º 3
0
    def build(self, clean=False):
        """Build the Sphinx project.

        :param bool clean: If True a clean build will be created.
        """
        self.validate_project_and_package()
        if clean:
            self.project_build_dir.rmtree_p()

        add_to_path = self.package_dir not in sys.path
        if add_to_path:
            sys.path.append(str(self.package_dir.parent))

        from sphinx import main
        argv = [
            '',  # Will be skipped.
            str(self.project_source_dir),
            str(self.project_build_dir),
        ]

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except SystemExit as e:
            if e.code != 0:
                raise SphinxError
        finally:
            sys.argv = old_argv
            if add_to_path:
                sys.path.remove(str(self.package_dir.parent))
Ejemplo n.º 4
0
    def build(self, clean=False):
        """Build the Sphinx project.

        :param bool clean: If True a clean build will be created.
        """
        self.validate_project_and_package()
        if clean:
            self.project_build_dir.rmtree_p()

        add_to_path = self.package_dir not in sys.path
        if add_to_path:
            sys.path.append(str(self.package_dir.parent))

        from sphinx import main
        argv = [
            '',  # Will be skipped.
            str(self.project_source_dir),
            str(self.project_build_dir),
        ]

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except SystemExit as e:
            if e.code != 0:
                raise SphinxError
        finally:
            sys.argv = old_argv
            if add_to_path:
                sys.path.remove(str(self.package_dir.parent))
Ejemplo n.º 5
0
def test_extensions(tempdir):
    qs.main(['-q', '-p', 'project_name', '-a', 'author',
             '--extensions', 'foo,bar,baz', tempdir])

    conffile = tempdir / 'conf.py'
    assert conffile.isfile()
    ns = {}
    execfile_(conffile, ns)
    assert ns['extensions'] == ['foo', 'bar', 'baz']
Ejemplo n.º 6
0
def main():
    parser = ArgumentParser()
    parser.add_argument('hieroglyph', nargs='?', help="Run hieroglyph -q to start a presentation")
    parser.add_argument('-v', '--version', action='store_true', help="Print current version of hieroglyph")
    parser.add_argument('-q', '--quickstart', action='store_true', help="Start a hieroglyph project")
    args = vars(parser.parse_args())
    if (args['version']):
        print(version())
    elif (args['quickstart']):
        sphinx_quickstart.main()
Ejemplo n.º 7
0
    def create(self, author, project_name=None, version='1'):
        """Create a new Sphinx project.

        :param str author: Name of the package author.
        :param str project_name: Name of the project that is displayed in the
            documentation. If None, it will be the name of the package.
        :param str version: Project/package version.
        """
        if self.project_exists():
            raise ValueError('The project already exists.')

        self.validate_package()
        self.project_dir.mkdir()

        from sphinx.quickstart import main

        argv = [
            '',  # Will be skipped.
            '-q',  # Don't start the interactive mode
        ]

        if project_name is None:
            project_name = self.package_dir.namebase

        argv.append('-p {0}'.format(project_name))
        argv.append('-a {0}'.format(author))
        argv.append('-v {0}'.format(version))

        argv.extend([
            str(self.project_dir),
            '--sep',  # Separate source and build directory
            '--ext-autodoc',  # Enable autodoc
            '--no-makefile',
            '--no-batchfile'
        ])

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except:
            raise SphinxError
        finally:
            sys.argv = old_argv
Ejemplo n.º 8
0
    def create(self, author, project_name=None, version='1'):
        """Create a new Sphinx project.

        :param str author: Name of the package author.
        :param str project_name: Name of the project that is displayed in the
            documentation. If None, it will be the name of the package.
        :param str version: Project/package version.
        """
        if self.project_exists():
            raise ValueError('The project already exists.')

        self.validate_package()
        self.project_dir.mkdir()

        from sphinx.quickstart import main

        argv = [
            '',  # Will be skipped.
            '-q',  # Don't start the interactive mode
        ]

        if project_name is None:
            project_name = self.package_dir.namebase

        argv.append('-p {0}'.format(project_name))
        argv.append('-a {0}'.format(author))
        argv.append('-v {0}'.format(version))

        argv.extend([
            str(self.project_dir),
            '--sep',  # Separate source and build directory
            '--ext-autodoc',  # Enable autodoc
            '--no-makefile',
            '--no-batchfile'
        ])

        # Hacky, but required, because sphinx is reading sys.argv even if you
        # pass a list to main()
        old_argv = sys.argv
        sys.argv = argv
        try:
            main(sys.argv)
        except:
            raise SphinxError
        finally:
            sys.argv = old_argv
Ejemplo n.º 9
0
def main():
    parser = ArgumentParser()
    parser.add_argument('hieroglyph',
                        nargs='?',
                        help="Run hieroglyph -q to start a presentation")
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        help="Print current version of hieroglyph")
    parser.add_argument('-q',
                        '--quickstart',
                        action='store_true',
                        help="Start a hieroglyph project")
    args = vars(parser.parse_args())
    if (args['version']):
        print(version())
    elif (args['quickstart']):
        sphinx_quickstart.main()
Ejemplo n.º 10
0
def main(argv=sys.argv):
    # Patch original generate function
    quickstart.generate = patch_generate

    # Run sphinx-quickstart
    return_code = quickstart.main(argv)

    if return_code:
        return return_code

    # TODO: quickstart.get_parser を拡張する
    # Sphinx 1.6.5 で下記対応がなされているが、pip install した Sphinx 1.6.5 で
    # このコードが存在しないため、反映されたら実装をする
    # https://github.com/sphinx-doc/sphinx/commit/101b2893516dbbfb92767efff1c30488e651ccfc
    # いまいまは直書きで対応する
    #
    # https://github.com/pashango2/sphinx-qsp
    # これにPR送ってもよし
    srcdir = d['sep'] and os.path.join(d['path'], 'source') or d['path']
    conf_path = os.path.join(srcdir, 'conf.py')
    make_path = os.path.join(d['path'], 'Makefile')

    with open(conf_path, 'a') as f:
        f.write(additional_config)

    if d.get('makefile', False):
        with open(make_path, 'a') as f:
            f.write(additional_make)

    # Copy files for pdf print style
    source = d['sep'] and os.path.join(d['path'], 'source') or d['path']
    prefix = d['dot'] or '_'
    shutil.copytree('/files/css', f'{source}/{prefix}static/css')
    shutil.copytree('/files/js', f'{source}/{prefix}static/js')

    return return_code
Ejemplo n.º 11
0
def main():
    sphinx_quickstart.main()
Ejemplo n.º 12
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Sphinx - Python documentation toolchain
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import sys

if __name__ == '__main__':
    from sphinx.quickstart import main
    sys.exit(main(sys.argv))
Ejemplo n.º 13
0
def main(argv=None):
    global hook_d

    hook_d = {}
    argv = sys.argv if argv is None else argv

    # load latest setting.
    if not os.path.isdir(HOME_DIR):
        os.mkdir(HOME_DIR)

    json_path = os.path.join(HOME_DIR, LATEST_SETTING_JSON_NAME)
    if os.path.isfile(json_path):
        hook_d.update(json.load(open(json_path)))

        # for python 2: oh..
        hook_d = {str(key): value for key, value in hook_d.items()}

    # monkey patch
    quickstart.ask_user = monkey_patch_ask_user
    quickstart.generate = monkey_patch_generate

    # do sphinx.quickstart
    quickstart.main(argv)

    # save latest setting.
    save_d = {
        key: value
        for key, value in hook_d.items() if key not in EXCLUDE_VALUE
    }
    dump_setting(save_d, json_path)

    # write ext-extensions
    d = hook_d

    srcdir = d['sep'] and os.path.join(d['path'], 'source') or d['path']
    conf_path = os.path.join(srcdir, "conf.py")

    with open(conf_path, "a+") as fc:
        for ext in qsp_extensions:
            if d.get(ext.key) and ext.conf_py:
                fc.write(ext.extend_conf_py(d))

    if d['makefile'] is True:
        make_path = os.path.join(d['path'], 'Makefile')
        make_mode = d.get("make_mode", True)
        with open(make_path, "a+") as fm:
            makefile_key = "new_makefile" if make_mode else "makefile"
            for ext in qsp_extensions:
                if d.get(ext.key) and getattr(ext, makefile_key):
                    fm.write(ext.extend_makefile(d, make_mode))

    # check install module
    print("check modules...")
    pip_text = check_installed_modules(d)

    if pip_text:
        print()
        print(
            "Module not found, please enter '{0}' and install module.".format(
                pip_text))
    else:
        print("ok")
Ejemplo n.º 14
0
def compatibility():
    sphinx_quickstart.main()
Ejemplo n.º 15
0
def compatibility():
    sphinx_quickstart.main()
Ejemplo n.º 16
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Sphinx - Python documentation toolchain
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import sys

if __name__ == '__main__':
    from sphinx.quickstart import main
    sys.exit(main(sys.argv[1:]))
Ejemplo n.º 17
0
if __name__ == '__main__':
    import sys
    from sphinx.quickstart import main

    sys.exit(main())