Example #1
0
def gen(skipdirhtml=False):
    """Generate html and dirhtml output."""
    docs_changelog = 'docs/changelog.rst'
    check_git_unchanged(docs_changelog)
    pandoc('--from=markdown', '--to=rst', '--output=' + docs_changelog, 'CHANGELOG.md')
    if not skipdirhtml:
        call(['sphinx-build', '-b', 'dirhtml', '-W', '-E', 'docs', 'docs/_build/dirhtml'])
    call(['sphinx-build', '-b', 'html', '-W', '-E', 'docs', 'docs/_build/html'])
Example #2
0
def gen(skipdirhtml=False):
    """Generate html and dirhtml output."""
    docs_changelog = 'docs/changelog.rst'
    check_git_unchanged(docs_changelog)
    pandoc('--from=markdown', '--to=rst', '--output=' + docs_changelog, 'CHANGELOG.md')
    if not skipdirhtml:
        sphinx_build['-b', 'dirhtml', '-W', '-E', 'docs', 'docs/_build/dirhtml'] & FG
    sphinx_build['-b', 'html', '-W', '-E', 'docs', 'docs/_build/html'] & FG
Example #3
0
def make_documentation(yes=False):
    """Use the templates defined above to create the astrodynamics.constants
    documentation.
    """
    constants = get_constants_from_data()
    docfile = Path('doc', 'modules', 'constants.rst')

    pythondir = Path('astrodynamics', 'constants')
    for pythonfile in pythondir.glob('*.py'):
        if pythonfile.stem not in constants:
            # Skip non-definition files: __init__.py, constant.py
            continue

        with pythonfile.open() as f:
            exec(f.read())

    # Sort constants by key
    constants = OrderedDict(sorted(constants.items(), key=lambda t: t[0]))

    # Hide individual modules from constants documentation
    flat_constants = chain.from_iterable(constants.values())

    value_table_data = []
    value_table_headers = ['Constant', 'Value', 'Uncertainty']

    details_table_data = []
    details_table_headers = ['Constant', 'Full name', 'Reference']

    for constant in flat_constants:
        name = constant.name
        value = eval(name)
        latex = value._repr_latex_()[1:-1]
        if isinstance(value, Constant):
            value_table_data.append(
                [name,
                 ':math:`{latex}`'.format(latex=latex),
                 value.uncertainty])
            details_table_data.append([name, value.name, value.reference])
        else:
            value_table_data.append(
                [name,
                 ':math:`{latex}`'.format(latex=latex),
                 'N/A'])

    if docfile.exists():
        check_git_unchanged(str(docfile), yes=yes)

    with docfile.open('w', encoding='utf-8') as f:
        f.write(DOC_TEMPLATE.format(
            value_table=tabulate(value_table_data, value_table_headers,
                                 tablefmt='rst'),
            details_table=tabulate(details_table_data, details_table_headers,
                                   tablefmt='rst')))
Example #4
0
def make_documentation(yes=False):
    """Use the templates defined above to create the astrodynamics.constants
    documentation.
    """
    constants = get_constants_from_data()
    docfile = Path('docs', 'modules', 'constants.rst')

    pythondir = Path('astrodynamics', 'constants')
    for pythonfile in pythondir.glob('*.py'):
        if pythonfile.stem not in constants:
            # Skip non-definition files: __init__.py, constant.py
            continue

        with pythonfile.open() as f:
            exec(f.read())

    # Sort constants by key
    constants = OrderedDict(sorted(constants.items(), key=lambda t: t[0]))

    # Hide individual modules from constants documentation
    flat_constants = chain.from_iterable(constants.values())

    value_table_data = []
    value_table_headers = ['Constant', 'Value', 'Uncertainty']

    details_table_data = []
    details_table_headers = ['Constant', 'Full name', 'Reference']

    for constant in flat_constants:
        name = constant.name
        value = eval(name)
        latex = value._repr_latex_()[1:-1]
        if isinstance(value, Constant):
            value_table_data.append(
                [name,
                 ':math:`{latex}`'.format(latex=latex),
                 value.uncertainty])
            details_table_data.append([name, value.name, value.reference])
        else:
            value_table_data.append(
                [name,
                 ':math:`{latex}`'.format(latex=latex),
                 'N/A'])

    if docfile.exists():
        check_git_unchanged(str(docfile), yes=yes)

    with docfile.open('w', encoding='utf-8') as f:
        f.write(DOC_TEMPLATE.format(
            value_table=tabulate(value_table_data, value_table_headers,
                                 tablefmt='rst'),
            details_table=tabulate(details_table_data, details_table_headers,
                                   tablefmt='rst')))
Example #5
0
def make_module(yes=False):
    """Use the templates defined above to create the astrodynamics.constants
    module.
    """
    constants = get_constants_from_data()
    init_imports = dict()
    pythondir = Path('astrodynamics', 'constants')

    for modulename, constants_list in constants.items():
        pythonfile = pythondir / '{}.py'.format(modulename)
        if pythonfile.exists():
            check_git_unchanged(str(pythonfile), yes=yes)

        all_lines = ("    '{}',".format(c.name) for c in constants_list)
        all_string = '\n'.join(all_lines)

        init_import_lines = ('    {},'.format(c.name) for c in constants_list)
        init_import_string = '\n'.join(init_import_lines)

        init_imports[modulename] = IMPORT_TEMPLATE.format(
            modulename=modulename,
            import_string=init_import_string)

        line = '{c.name} = {c.value}'
        constant_lines = (line.format(c=c) for c in constants_list)
        constant_string = '\n'.join(constant_lines)

        with pythonfile.open('w', encoding='utf-8') as f:
            f.write(TEMPLATE.format(all_string=all_string,
                                    constant_string=constant_string))

    initfile = pythondir / '__init__.py'
    if initfile.exists():
        check_git_unchanged(str(initfile), yes=yes)

    # Sort init_imports and constants by key
    init_imports = OrderedDict(sorted(init_imports.items(), key=lambda t: t[0]))
    imports = '\n'.join(init_imports.values())

    constants = OrderedDict(sorted(constants.items(), key=lambda t: t[0]))
    flat_constants = chain.from_iterable(constants.values())
    all_lines = ("    '{}',".format(c.name) for c in flat_constants)
    all_string = '\n'.join(all_lines)

    with initfile.open('w', encoding='utf-8') as f:
        f.write(INIT_TEMPLATE.format(imports=imports, all_string=all_string))
Example #6
0
def make_module(yes=False):
    """Use the templates defined above to create the astrodynamics.constants
    module.
    """
    constants = get_constants_from_data()
    init_imports = dict()
    pythondir = Path('astrodynamics', 'constants')

    for modulename, constants_list in constants.items():
        pythonfile = pythondir / '{}.py'.format(modulename)
        if pythonfile.exists():
            check_git_unchanged(str(pythonfile), yes=yes)

        all_lines = ("    '{}',".format(c.name) for c in constants_list)
        all_string = '\n'.join(all_lines)

        init_import_lines = ('    {},'.format(c.name) for c in constants_list)
        init_import_string = '\n'.join(init_import_lines)

        init_imports[modulename] = IMPORT_TEMPLATE.format(
            modulename=modulename,
            import_string=init_import_string)

        line = '{c.name} = {c.value}'
        constant_lines = (line.format(c=c) for c in constants_list)
        constant_string = '\n'.join(constant_lines)

        with pythonfile.open('w', encoding='utf-8') as f:
            f.write(TEMPLATE.format(all_string=all_string,
                                    constant_string=constant_string))

    initfile = pythondir / '__init__.py'
    if initfile.exists():
        check_git_unchanged(str(initfile), yes=yes)

    # Sort init_imports and constants by key
    init_imports = OrderedDict(sorted(init_imports.items(), key=lambda t: t[0]))
    imports = '\n'.join(init_imports.values())

    constants = OrderedDict(sorted(constants.items(), key=lambda t: t[0]))
    flat_constants = chain.from_iterable(constants.values())
    all_lines = ("    '{}',".format(c.name) for c in flat_constants)
    all_string = '\n'.join(all_lines)

    with initfile.open('w', encoding='utf-8') as f:
        f.write(INIT_TEMPLATE.format(imports=imports, all_string=all_string))