Пример #1
0
def main(args: Dict[str, str]) -> None:
    logger = logging.getLogger('build_docs')
    logger.info('create the README.rst')
    travis_repo_slug = args['<TRAVIS_REPO_SLUG>']
    repository = travis_repo_slug.split('/')[1]
    repository_dashed = repository.replace('_', '-')

    project_specific(travis_repo_slug, repository, repository_dashed)

    """
    paths absolute, or relative to the location of the config file
    the notation for relative files is like on windows or linux - not like in python.
    so You might use ../../some/directory/some_document.rst to go two levels back.
    avoid absolute paths since You never know where the program will run.
    """

    logger.info('include the include blocks')
    rst_include.rst_inc(source='./.docs/README_template.rst',
                        target='./README.rst')

    logger.info('replace repository related strings')
    rst_include.rst_str_replace(source='./README.rst', target='', str_pattern='{repository_slug}', str_replace=travis_repo_slug, inplace=True)
    rst_include.rst_str_replace(source='./README.rst', target='', str_pattern='{repository}', str_replace=repository, inplace=True)
    rst_include.rst_str_replace(source='./README.rst', target='', str_pattern='{repository_dashed}', str_replace=repository_dashed, inplace=True)
    rst_include.rst_str_replace(source='./README.rst', target='', str_pattern='{last_update_yyyy}', str_replace=str(datetime.date.today().year + 1), inplace=True)
    rst_include.rst_str_replace(source='./README.rst', target='', str_pattern='{codeclimate_link_hash}', str_replace=codeclimate_link_hash, inplace=True)
    logger.info('done')
    sys.exit(0)
Пример #2
0
def main(args: Dict[str, str]) -> None:

    rst_template = pathlib.Path('./.docs/README_template.rst')
    rst_template_tmp = pathlib.Path('./.docs/README_template_tmp.rst')
    rst_target = pathlib.Path('./README.rst')

    # noinspection PyBroadException
    try:
        lib_log_utils.log_info('create the README.rst')
        travis_repo_slug = args['<TRAVIS_REPO_SLUG>']
        repository = travis_repo_slug.split('/')[1]
        repository_dashed = repository.replace('_', '-')
        """
        paths absolute, or relative to the location of the config file
        the notation for relative files is like on windows or linux - not like in python.
        so You might use ../../some/directory/some_document.rst to go two levels back.
        avoid absolute paths since You never know where the program will run.
        """

        if project_conf.badges_with_jupiter:
            rst_include.rst_str_replace(
                source=rst_template,
                target=rst_template_tmp,
                str_pattern='{try_in_jupyter}',
                str_replace='.. include:: ./try_in_jupyter.rst')
        else:
            rst_include.rst_str_replace(source=rst_template,
                                        target=rst_template_tmp,
                                        str_pattern='{try_in_jupyter}',
                                        str_replace='')

        lib_log_utils.log_info('include the include blocks')
        rst_include.rst_inc(source=rst_template_tmp, target=rst_target)

        lib_log_utils.log_info('replace repository related strings')
        rst_include.rst_str_replace(source=rst_target,
                                    target='',
                                    str_pattern='{repository_slug}',
                                    str_replace=travis_repo_slug,
                                    inplace=True)
        rst_include.rst_str_replace(source=rst_target,
                                    target='',
                                    str_pattern='{repository}',
                                    str_replace=repository,
                                    inplace=True)
        rst_include.rst_str_replace(
            source=rst_target,
            target='',
            str_pattern='{double_underline_repository}',
            str_replace='=' * len(repository),
            inplace=True)
        rst_include.rst_str_replace(source=rst_target,
                                    target='',
                                    str_pattern='{repository_dashed}',
                                    str_replace=repository_dashed,
                                    inplace=True)
        rst_include.rst_str_replace(
            source=rst_target,
            target='',
            str_pattern='{last_update_yyyy}',
            str_replace=str(datetime.date.today().year + 1),
            inplace=True)
        rst_include.rst_str_replace(
            source=rst_target,
            target='',
            str_pattern='{codeclimate_link_hash}',
            str_replace=project_conf.codeclimate_link_hash,
            inplace=True)

        lib_log_utils.log_info('done')
        sys.exit(0)
    finally:
        rst_template_tmp.unlink(missing_ok=True)