当前位置: 首页>>代码示例>>Python>>正文


Python Template.splitlines方法代码示例

本文整理汇总了Python中jinja2.Template.splitlines方法的典型用法代码示例。如果您正苦于以下问题:Python Template.splitlines方法的具体用法?Python Template.splitlines怎么用?Python Template.splitlines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2.Template的用法示例。


在下文中一共展示了Template.splitlines方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: stage

# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import splitlines [as 别名]
def stage(draft, release_name='', release_description=''):
    repository = changes.project_settings.repository

    release = changes.release_from_pull_requests()
    release.name = release_name
    release.description = release_description

    if not repository.pull_requests_since_latest_version:
        error("There aren't any changes to release since {}".format(release.version))
        return

    info(
        'Staging [{}] release for version {}'.format(
            release.release_type, release.version
        )
    )

    # Bumping versions
    if BumpVersion.read_from_file(Path('.bumpversion.cfg')).current_version == str(
        release.version
    ):
        info('Version already bumped to {}'.format(release.version))
    else:
        bumpversion_arguments = (
            BumpVersion.DRAFT_OPTIONS if draft else BumpVersion.STAGE_OPTIONS
        ) + [release.bumpversion_part]

        info('Running: bumpversion {}'.format(' '.join(bumpversion_arguments)))
        bumpversion.main(bumpversion_arguments)

    # Release notes generation
    info('Generating Release')
    release.notes = Release.generate_notes(
        changes.project_settings.labels, repository.pull_requests_since_latest_version
    )

    # TODO: if project_settings.release_notes_template is None
    release_notes_template = pkg_resources.resource_string(
        changes.__name__, 'templates/release_notes_template.md'
    ).decode('utf8')

    release_notes = Template(release_notes_template).render(release=release)

    releases_directory = Path(changes.project_settings.releases_directory)
    if not releases_directory.exists():
        releases_directory.mkdir(parents=True)

    release_notes_path = releases_directory.joinpath(
        '{}.md'.format(release.release_note_filename)
    )

    if draft:
        info('Would have created {}:'.format(release_notes_path))
        debug(release_notes)
    else:
        info('Writing release notes to {}'.format(release_notes_path))
        if release_notes_path.exists():
            release_notes_content = release_notes_path.read_text(encoding='utf-8')
            if release_notes_content != release_notes:
                info(
                    '\n'.join(
                        difflib.unified_diff(
                            release_notes_content.splitlines(),
                            release_notes.splitlines(),
                            fromfile=str(release_notes_path),
                            tofile=str(release_notes_path),
                        )
                    )
                )
                if click.confirm(
                    click.style(
                        '{} has modified content, overwrite?'.format(
                            release_notes_path
                        ),
                        **STYLES['error']
                    )
                ):
                    release_notes_path.write_text(release_notes, encoding='utf-8')
        else:
            release_notes_path.write_text(release_notes, encoding='utf-8')
开发者ID:michaeljoseph,项目名称:changes,代码行数:82,代码来源:stage.py


注:本文中的jinja2.Template.splitlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。