# Path: bts_tools/core.py
# def run(cmd, capture_io=False, verbose=True, log_on_fail=True,
#         run_dir=None, forward_signals=False, pidfile=None, shell=False):
#     r = _run(cmd, capture_io=capture_io, verbose=verbose,
#              run_dir=run_dir, forward_signals=forward_signals, pidfile=pidfile, shell=shell)
#     if r.status != 0:
#         if log_on_fail:
#             log.warning('Failed running: %s' % cmd)
#             if capture_io:
#                 log.warning('\nSTDOUT:\n{}\nSTDERR:\n:{}'.format(r.stdout, r.stderr))
#         raise RuntimeError('Failed running: %s' % cmd)
#     return r


from bts_tools.core import run
from jinja2 import Template
import sys
import re
                    r"VERSION = '\S*'",
                    r"VERSION = '%s'" % version)

    major_minor = '.'.join(version
                           .split('a')[0].split('b')[0].split('rc')[0]  # remove alpha/beta/rc tags
                           .split('.')[:2])  # keep 2 leftmost digits

    replace_version('docs/conf.py',
                    r"version = '\S*'",
                    r"version = '%s'" % major_minor)

    replace_version('docs/conf.py',
                    r"release = '\S*'",
                    r"release = '%s'" % version)


def task_set_version():
    """Set the version in the appropriate places (docs, setup.py, ...)"""
    return {'actions': [set_version],
            'pos_arg': 'pos',
            'verbosity': 2}


def task_upload_pypi():
    """Build and upload the package on PyPI"""
    # FIXME: only apply "git stash apply" if "git stash" did stash something.
    #git stash && rm -fr dist/ && python setup.py sdist upload && git stash apply && python setup.py develop

    def check_valid_git_state():
        # check that we are on a git tag before uploading a dev version number...

# Path: bts_tools/core.py
# def run(cmd, capture_io=False, verbose=True, log_on_fail=True,
#         run_dir=None, forward_signals=False, pidfile=None, shell=False):
#     r = _run(cmd, capture_io=capture_io, verbose=verbose,
#              run_dir=run_dir, forward_signals=forward_signals, pidfile=pidfile, shell=shell)
#     if r.status != 0:
#         if log_on_fail:
#             log.warning('Failed running: %s' % cmd)
#             if capture_io:
#                 log.warning('\nSTDOUT:\n{}\nSTDERR:\n:{}'.format(r.stdout, r.stderr))
#         raise RuntimeError('Failed running: %s' % cmd)
#     return r


# Path: dodo.py
from bts_tools.core import run
from jinja2 import Template
import sys
import re

                    r"VERSION = '\S*'",
                    r"VERSION = '%s'" % version)

    major_minor = '.'.join(version
                           .split('a')[0].split('b')[0].split('rc')[0]  # remove alpha/beta/rc tags
                           .split('.')[:2])  # keep 2 leftmost digits

    replace_version('docs/conf.py',
                    r"version = '\S*'",
                    r"version = '%s'" % major_minor)

    replace_version('docs/conf.py',
                    r"release = '\S*'",
                    r"release = '%s'" % version)


def task_set_version():
    """Set the version in the appropriate places (docs, setup.py, ...)"""
    return {'actions': [set_version],
            'pos_arg': 'pos',
            'verbosity': 2}


def task_upload_pypi():
    """Build and upload the package on PyPI"""
    # FIXME: only apply "git stash apply" if "git stash" did stash something.
    #git stash && rm -fr dist/ && python setup.py sdist upload && git stash apply && python setup.py develop

    def check_valid_git_state():
        # check that we are on a git tag before uploading a dev version number...

        tag_version = run('git describe --tags', capture_io=True, verbose=False).stdout