當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。