示例#1
0
    :type version_str: str
    :param project_package: the root package
    :type project_package: str
    """

    try:
        _edit_package_version(version_str=version_str, project_package=project_package)
        file_name = _file_spec('VERSION.txt', project_package)
        if os.path.exists(file_name):
            os.remove(file_name)
    except (AttributeError, IOError) as ex:
        error(ex)
        _replace_version_txt_file(version_str=version_str, project_package=project_package)


with namespace('version'):
    @task()
    def bump():
        """
        Bumps the Tiny (Major.Minor.Tiny.Tiny2) version in VERSION file up by one.
        If the VERSION file does not exist, then create it and initialize the version to '0.0.0'.
        """
        return bump_tiny()

    @task(private=True)
    def bump_tiny():
        """
        Bumps the Minor (Major.Minor.Tiny.Tiny2) version in VERSION file up by one.
        If the VERSION file does not exist, then create it and initialize the version to '0.0.0'.
        """
        return bump_field('Tiny')
示例#2
0
    # or if not defined, then in Project.wheel_python_versions.  If neither are defined, then
    # run the test in the current environment.

    venvs = VirtualenvInfo('metrics_python_versions', 'wheel_python_versions')

    if not venvs.in_virtualenv and venvs.defined:
        for venv_info in venvs.infos():
            info('Running metrics using the {venv} virtual environment.'.format(venv=venv_info.venv))
            venv_info.run('herring metrics::all_metrics')
    else:
        info('Running metrics using the current python environment')
        task_execute('metrics::all_metrics')


# if packages_required(required_packages):
with namespace('metrics'):

    def _sloc_totals_by_language():
        totals_by_language = {}

        with LocalShell() as local:
            output = local.run("sloccount --wide {src}".format(src=Project.package))
            for line in output.splitlines():
                match = re.match(r"(\S+):\s+(\d+)\s+\(([\d.]+)%\)", line)
                if match:
                    totals_by_language[match.group(1)] = (int(match.group(2)), float(match.group(3)))
        return totals_by_language


    # @task()
    # def cloc():
示例#3
0
# noinspection PyUnresolvedReferences
from herring.herring_app import task, namespace, task_execute

from herringlib.run_python import run_python
from herringlib.is_newer import is_newer
from herringlib.simple_logger import info, warning, debug
from herringlib.mkdir_p import mkdir_p
from herringlib.project_settings import Project

from herringlib.cd import cd
from herringlib.executables import executables_available

__docformat__ = 'restructuredtext en'

with namespace('doc'):

    # noinspection PyUnusedLocal,PyArgumentEqualDefault
    def _create_module_diagrams(path):
        """
        create module UML diagrams

        :param path: the module path
         :type path: str
        """
        info("_create_module_diagrams")
        if not executables_available(['pyreverse']):
            warning('pyreverse not available')
            return

        with open(os.path.join(Project.docs_dir, "pyreverse.log"), "w") as outputter:
示例#4
0
    @task()
    @venv_decorator(attr_name="doc_python_version")
    def doc_watch():
        """generate project documentation"""
        venvs = VirtualenvInfo("doc_python_version")
        info("venvs: {venvs}".format(venvs=repr(venvs.__dict__)))
        if not venvs.in_virtualenv and venvs.defined:
            for venv_info in venvs.infos():
                venv_info.run(
                    "{herring} doc::watch --python-tag py{ver}".format(herring=Project.herring, ver=venv_info.ver)
                )
        else:
            info("Generating documentation using the current python environment")
            task_execute("doc::watch")

    with namespace("doc"):

        @task(depends=["clean"], private=True)
        def clean():
            """Remove documentation artifacts"""
            recursively_remove(os.path.join(Project.docs_dir, "_src"), "*")
            recursively_remove(os.path.join(Project.docs_dir, "_epy"), "*")
            recursively_remove(os.path.join(Project.docs_dir, "_build"), "*")
            doc.doc_errors = []

        def _name_dict(file_name):
            """extract the name dictionary from the automodule lines in the sphinx src file"""
            name_dict = {}
            # noinspection PyArgumentEqualDefault
            with open(file_name, "r") as in_file:
                for line in in_file.readlines():
示例#5
0
    # refactoring.
    # @task(depends=['doc::post_clean'])
    @task()
    def build():
        """Build the project both sdist and wheels"""

        # Note, you must disable universal in setup.cfg::
        #     [wheel]
        #     universal=0

        if Project.version == '0.0.0':
            bump()
        task_execute('build::sdist')
        task_execute('build::wheels')

    with namespace('build'):

        @task(private=False)
        @venv_decorator(attr_name='wheel_python_versions')
        def wheels():
            """build wheels"""
            info('')
            info("=" * 70)
            info('building wheels')

            venvs = VirtualenvInfo('wheel_python_versions')
            if not venvs.in_virtualenv and venvs.defined:
                value = setup_cfg_value(section='wheel', key='universal')
                if value is None or value != '0':
                    warning('To use wheels, you must disable universal in setup.cfg:\n    [wheel]\n    universal=0\n')
                    return
示例#6
0
    # noinspection PyUnresolvedReferences
    from herringlib.local_shell import LocalShell
    # noinspection PyUnresolvedReferences
    from herringlib.simple_logger import error
    # noinspection PyUnresolvedReferences
    from herringlib.prompt import query_yes_no
except ImportError as ex:
    # noinspection PyUnresolvedReferences
    from herringlib.simple_logger import error
    error("Problem importing:  {msg}".format(msg=str(ex)))

# noinspection PyUnusedName
__docformat__ = 'restructuredtext en'

if Project.package:
    with namespace('release'):
        # noinspection PyUnusedFunction
        @task()
        def changes_since_last_tag():
            """show the changes since the last tag"""
            with LocalShell() as local:
                last_tag = local.run('git describe --tags --abbrev=0').strip()
                print("\n" + local.run(['git', 'log', '{tag}..HEAD'.format(tag=last_tag), '--oneline']))


        @task()
        def github():
            """tag it with the current version"""
            with LocalShell() as local:
                local.run('git tag {name}-{ver} -m "Adds a tag so we can put this on PyPI"'.format(
                    name=Project.package,
示例#7
0
    # or if not defined, then in Project.wheel_python_versions.  If neither are defined, then
    # run the test in the current environment.

    venvs = VirtualenvInfo('python_versions', 'wheel_python_versions')

    if not venvs.in_virtualenv and venvs.defined:
        for venv_info in venvs.infos():
            info('Running security using the {venv} virtual environment.'.format(venv=venv_info.venv))
            venv_info.run('herring security::all_securities')
    else:
        info('Running security using the current python environment')
        task_execute('security::all_securities')


# if packages_required(required_packages):
with namespace('security'):
    @task()
    def bandit():
        """ scan source code for possible security vulnerabilities """
        mkdir_p(Project.quality_dir)
        bandit_filename = qd("security.txt")
        with LocalShell() as local:
            output = local.run("bandit -r {src}".format(src=Project.package), verbose=True)
            if os.path.isfile(bandit_filename):
                os.remove(bandit_filename)
            with open(bandit_filename, 'w') as sloc_file:
                sloc_file.write(output)


    @task(namespace='security',
          depends=['bandit'],
示例#8
0
    @task()
    def build():
        """Build the project both sdist and wheels"""

        # Note, you must disable universal in setup.cfg::
        #     [wheel]
        #     universal=0

        if Project.version == '0.0.0':
            bump()
        task_execute('build::sdist')
        task_execute('build::wheels')
        task_execute('build::installer')


    with namespace('build'):

        @task(private=False)
        @venv_decorator(attr_name='wheel_python_versions')
        def wheels():
            """build wheels"""
            info('')
            info("=" * 70)
            info('building wheels')

            venvs = VirtualenvInfo('wheel_python_versions')
            if not venvs.in_virtualenv and venvs.defined:
                value = setup_cfg_value(section='wheel', key='universal')
                if value is None or value != '0':
                    warning('To use wheels, you must disable universal in setup.cfg:\n    [wheel]\n    universal=0\n')
                    return
示例#9
0
文件: doc.py 项目: royw/herringlib
    if not venvs.in_virtualenv and venvs.defined:
        for venv_info in venvs.infos():
            venv_info.run('{herring} doc::watch --python-tag py{ver}'.format(herring=Project.herring,
                                                                             ver=venv_info.ver))
    else:
        info('Generating documentation using the current python environment')
        task_execute('doc::watch')


@task()
def publish():
    """ copy latest docs to a linux base web server """
    task_execute('doc::publish')


with namespace('doc'):
    @task(depends=['clean'], private=True)
    def clean():
        """Remove documentation artifacts"""
        global doc_errors
        recursively_remove(os.path.join(Project.docs_dir, '_src'), '*')
        recursively_remove(os.path.join(Project.docs_dir, '_epy'), '*')
        recursively_remove(os.path.join(Project.docs_dir, '_build'), '*')
        for filename in glob.glob(os.path.join(Project.docs_dir, '*.log')):
            os.remove(filename)
        doc.doc_errors = []


    @task(depends=['clean'], private=True)
    def api():
        """Generate API sphinx source files from code"""
示例#10
0
from herring.herring_app import namespace, task
from herringlib.cd import cd
from herringlib.local_shell import LocalShell
from herringlib.mkdir_p import mkdir_p
from herringlib.project_settings import Project
from herringlib.prompt import prompt
from herringlib.simple_logger import info
from herringlib.split_all import split_all
from herringlib.touch import touch

DOCKERFILE = 'Dockerfile'

DOCKERFILE_TEMPLATE = os.path.join(os.path.dirname(__file__), 'dockerfile.template')

with namespace('docker'):
    @task(arg_prompt="Enter the image's name:")
    def new_image():
        """Create a new image directory and populate with a default Dockerfile."""
        names = list(task.argv)
        if not names:
            if Project.prompt and task.arg_prompt is not None:
                name = prompt(task.arg_prompt)
                if name is not None and name.strip():
                    names.append(name)

        for name in names:
            container_dir = os.path.join(Project.docker_dir, Project.docker_containers_dir, name)
            mkdir_p(container_dir)
            # populate container dir with Dockerfile and .dockerignore
            dockerfile = os.path.join(container_dir, 'Dockerfile')
示例#11
0
# coding=utf-8

"""
Herring tasks for publishing ReST files to a wordpress blog.
"""

# noinspection PyUnresolvedReferences
from herring.herring_app import task, namespace
# noinspection PyUnresolvedReferences
from herringlib.project_settings import Project
# noinspection PyUnresolvedReferences
from herringlib.local_shell import LocalShell

__docformat__ = 'restructuredtext en'

with namespace('blog'):

    @task()
    def init():
        """establish connection with wordpress blog"""
        with LocalShell() as local:
            local.run('restblog init "{name}" "{url}/xmlrpc.php" {user}'.format(name=Project.blog_name,
                                                                                url=Project.blog_url,
                                                                                user=Project.blog_user))

    @task()
    def create():
        """create a new article"""
        pass

    @task()