Ejemplo n.º 1
0
def tag(options):
    """Tag the version"""
    default_options = Config()
    default_options._load('./.tagitrc')
    default_options._use('TAGIT')
    default_options.update(vars(options['c']))
    publish = default_options.get('publish', False)
    #changelog = default_options.get('changelog', '')
    increment = default_options.get('increment', 'patch')
    versource = default_options.get('versource', '')
    vertoml = default_options.get('vertoml', '')
    #checksource = default_options.get('checksource', True)
    #checktoml = default_options.get('checktoml', True)
    extra = default_options.get('extra', '')

    specver = options[POSITIONAL] or None
    ret = status(default_options, specver, True)

    if not ret:
        return

    tagver = _get_version_from_gittag() or Tag((0, 0, 0))
    specver = specver or tagver.increment(increment)

    if versource:
        _log('Updating version in source file ...')
        _update_version_to_source(_getsrcfile(versource), specver)

    if vertoml:
        _log('Updating version in pyproject.toml ...')
        _update_version_to_toml(specver, vertoml)

    if extra:
        cmd = bash(c=extra).fg
        if cmd.rc != 0:
            raise RuntimeError('Failed to run %r' % extra)
    _log('Committing the change ...')
    try:
        git.commit({'allow-empty': True}, a=True, m=str(specver)).fg
    except CmdyReturnCodeError:
        # pre-commit fails, do it again
        _log('Pre-commit failed, try again ...')
        git.add('.')
        git.commit({'allow-empty': True}, a=True, m=str(specver)).fg

    _log('Pushing the commit to remote ...')
    git.push().fg

    _log('Adding tag %r ...' % specver)
    git.tag(str(specver)).fg
    _log('Pushing the tag to remote ...')
    git.push(tag=True).fg

    if publish:
        _log('Building the release ...')
        poetry.build().fg
        _log('Publishing the release ...')
        poetry.publish().fg
    _log('Done!')
Ejemplo n.º 2
0
def status(options, specver=None, ret=False):
    """Get the status of the project"""
    tagver = _get_version_from_gittag()

    exception = None
    gitstatus = git.status(s=True).str()
    cherry = git.cherry(v=True).str()
    if gitstatus or cherry:
        exception = UncleanRepoException(
            'You have changes uncommitted or unpushed.\n\n' +
            git.status().str())
    lastmsg = git.log('-1', pretty="format:%s", _sep='=').strip()

    if lastmsg == str(tagver):
        raise NoChangesSinceLastTagException('No changes since last tag.')

    tagver = tagver or Tag((0, 0, 0))

    rcoptions = Config()
    rcoptions._load('./.tagitrc')
    rcoptions._use('TAGIT')
    rcoptions.update(vars(options))
    changelog = rcoptions.get('changelog', '')
    increment = rcoptions.get('increment', 'patch')
    versource = rcoptions.get('versource', '')
    vertoml = rcoptions.get('vertoml', '')
    checksource = rcoptions.get('checksource', True)
    checktoml = rcoptions.get('checktoml', True)

    _log('Current version: %s' % str(tagver))

    if ret:
        nextver = tagver.increment(increment)
        _log('New version received: %r' % (specver or nextver))
        if exception:
            raise exception
        return _checkver(specver or nextver, changelog, versource, vertoml,
                         checksource, checktoml)

    nextver = tagver.increment('patch')
    _log('Next auto patch version is: %s' % nextver)

    if _checkver(nextver, changelog, versource, vertoml, checksource,
                 checktoml):
        _log('  You are good to go with this version.')
        shortcmd = '`tagit tag`, ' if increment == 'patch' else ''
        _log('  Run %s`tagit tag -c.i patch` or `tagit tag %s`' %
             (shortcmd, nextver))

    nextver = tagver.increment('minor')
    _log('Next auto minor version is: %s' % nextver)

    if _checkver(nextver, changelog, versource, vertoml, checksource,
                 checktoml):
        _log('  You are good to go with this version.')
        shortcmd = '`tagit tag`, ' if increment == 'minor' else ''
        _log('  Run %s`tagit tag -c.i minor` or `tagit tag %s`' %
             (shortcmd, nextver))

    nextver = tagver.increment('major')
    _log('Next auto major version is: %s' % nextver)

    if _checkver(nextver, changelog, versource, vertoml, checksource,
                 checktoml):
        _log('  You are good to go with this version.')
        shortcmd = '`tagit tag`, ' if increment == 'major' else ''
        _log('  Run %s`tagit tag -c.i major` or `tagit tag %s`' %
             (shortcmd, nextver))

    if exception:
        raise exception