def print_failed():
    # generated on http://patorjk.com/software/taag/#p=display&f=Small&t=FAILED
    print_failure_message(r'''  ___ _   ___ _    ___ ___
 | __/_\ |_ _| |  | __|   \
 | _/ _ \ | || |__| _|| |) |
 |_/_/ \_\___|____|___|___/
''')
Exemplo n.º 2
0
def coverage():
    """Run tests and show test coverage report."""
    try:
        import pytest_cov  # NOQA
    except ImportError:
        print_failure_message("Install the pytest coverage plugin to use this task, " "i.e., `pip install pytest-cov'.")
        raise SystemExit(1)
    import pytest

    pytest.main(PYTEST_FLAGS + ["--cov", CODE_DIRECTORY, "--cov-report", "term-missing", TESTS_DIRECTORY])
 def on_modified(self, event):
     print_failure_message('Modification detected. Rebuilding docs.')
     # # Strip off the path prefix.
     # import os
     # if event.src_path[len(os.getcwd()) + 1:].startswith(
     #         CODE_DIRECTORY):
     #     # sphinx-build doesn't always pick up changes on code files,
     #     # even though they are used to generate the documentation. As
     #     # a workaround, just clean before building.
     doc_html()
     print_success_message('Docs have been rebuilt.')
Exemplo n.º 4
0
def doc_open():
    """Build the HTML docs and open them in a web browser."""
    doc_index = os.path.join(DOCS_DIRECTORY, "build", "html", "index.html")
    if sys.platform == "darwin":
        # Mac OS X
        subprocess.check_call(["open", doc_index])
    elif sys.platform == "win32":
        # Windows
        subprocess.check_call(["start", doc_index], shell=True)
    elif sys.platform == "linux2":
        # All freedesktop-compatible desktops
        subprocess.check_call(["xdg-open", doc_index])
    else:
        print_failure_message("Unsupported platform. Please open `{0}' manually.".format(doc_index))
Exemplo n.º 5
0
def doc_watch():
    """Watch for changes in the docs and rebuild HTML docs when changed."""
    try:
        from watchdog.events import FileSystemEventHandler
        from watchdog.observers import Observer
    except ImportError:
        print_failure_message('Install the watchdog package to use this task, '
                              "i.e., `pip install watchdog'.")
        raise SystemExit(1)

    class RebuildDocsEventHandler(FileSystemEventHandler):

        def __init__(self, base_paths):
            self.base_paths = base_paths

        def dispatch(self, event):
            """Dispatches events to the appropriate methods.
            :param event: The event object representing the file system event.
            :type event: :class:`watchdog.events.FileSystemEvent`
            """
            for base_path in self.base_paths:
                if event.src_path.endswith(base_path):
                    super(RebuildDocsEventHandler, self).dispatch(event)
                    # We found one that matches. We're done.
                    return

        def on_modified(self, event):
            print_failure_message('Modification detected. Rebuilding docs.')
            # # Strip off the path prefix.
            # import os
            # if event.src_path[len(os.getcwd()) + 1:].startswith(
            #         CODE_DIRECTORY):
            #     # sphinx-build doesn't always pick up changes on code files,
            #     # even though they are used to generate the documentation. As
            #     # a workaround, just clean before building.
            doc_html()
            print_success_message('Docs have been rebuilt.')

    print_success_message(
        'Watching for changes in project files, press Ctrl-C to cancel...')
    handler = RebuildDocsEventHandler(get_project_files())
    observer = Observer()
    observer.schedule(handler, path='.', recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
        observer.join()
Exemplo n.º 6
0
def coverage():
    """Run tests and show test coverage report."""
    try:
        import pytest_cov  # NOQA
    except ImportError:
        print_failure_message(
            'Install the pytest coverage plugin to use this task, '
            "i.e., `pip install pytest-cov'.")
        raise SystemExit(1)
    import pytest
    pytest.main(PYTEST_FLAGS + [
        '--cov', CODE_DIRECTORY,
        '--cov-report', 'term-missing',
        '--junit-xml', 'test-report.xml',
        TESTS_DIRECTORY])
def doc_open():
    """Build the HTML docs and open them in a web browser."""
    doc_index = os.path.join(DOCS_DIRECTORY, 'build', 'html', 'index.html')
    if sys.platform == 'darwin':
        # Mac OS X
        subprocess.check_call(['open', doc_index])
    elif sys.platform == 'win32':
        # Windows
        subprocess.check_call(['start', doc_index], shell=True)
    elif sys.platform == 'linux2':
        # All freedesktop-compatible desktops
        subprocess.check_call(['xdg-open', doc_index])
    else:
        print_failure_message(
            "Unsupported platform. Please open `{0}' manually.".format(
                doc_index))
Exemplo n.º 8
0
def doc_open():
    """Build the HTML docs and open them in a web browser."""
    doc_index = os.path.join(DOCS_DIRECTORY, 'build', 'html', 'index.html')
    if sys.platform == 'darwin':
        # Mac OS X
        subprocess.check_call(['open', doc_index])
    elif sys.platform == 'win32':
        # Windows
        subprocess.check_call(['start', doc_index], shell=True)
    elif sys.platform == 'linux2':
        # All freedesktop-compatible desktops
        subprocess.check_call(['xdg-open', doc_index])
    else:
        print_failure_message(
            "Unsupported platform. Please open `{0}' manually.".format(
                doc_index))
Exemplo n.º 9
0
def doc_open():
    """Build the HTML docs and open them in a web browser."""
    doc_index = os.path.join(DOCS_DIRECTORY, "build", "html", "index.html")
    if sys.platform == "darwin":
        # Mac OS X
        subprocess.check_call(["open", doc_index])
    elif sys.platform == "win32":
        # Windows
        subprocess.check_call(["start", doc_index], shell=True)
    elif sys.platform in ["linux", "linux2"]:
        # All freedesktop-compatible desktops
        subprocess.check_call(["xdg-open", doc_index])
    else:
        print_failure_message(
            "Unsupported platform. Please open `{0}' manually.".format(
                doc_index))
Exemplo n.º 10
0
def doc_watch():
    """Watch for changes in the docs and rebuild HTML docs when changed."""
    try:
        from watchdog.events import FileSystemEventHandler
        from watchdog.observers import Observer
    except ImportError:
        print_failure_message('Install the watchdog package to use this task, '
                              "i.e., `pip install watchdog'.")
        raise SystemExit(1)

    class RebuildDocsEventHandler(FileSystemEventHandler):
        def __init__(self, base_paths):
            self.base_paths = base_paths

        def dispatch(self, event):
            """Dispatches events to the appropriate methods.
            :param event: The event object representing the file system event.
            :type event: :class:`watchdog.events.FileSystemEvent`
            """
            for base_path in self.base_paths:
                if event.src_path.endswith(base_path):
                    super(RebuildDocsEventHandler, self).dispatch(event)
                    # We found one that matches. We're done.
                    return

        def on_modified(self, event):
            print_failure_message('Modification detected. Rebuilding docs.')
            # # Strip off the path prefix.
            #     # sphinx-build doesn't always pick up changes on code files,
            #     # even though they are used to generate the documentation. As
            #     # a workaround, just clean before building.
            doc_html()
            print_success_message('Docs have been rebuilt.')

    print_success_message(
        'Watching for changes in project files, press Ctrl-C to cancel...')
    handler = RebuildDocsEventHandler(get_project_files())
    observer = Observer()
    observer.schedule(handler, path='.', recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
        observer.join()
Exemplo n.º 11
0
def dep_check():
    """Check if any installed dependencies have newer versions."""
    try:
        import pip
    except ImportError:
        print_failure_message(
            'Install pip to use this task, '
            "i.e., `sudo apt-get install python-pip`.")
        raise SystemExit(1)
    f = BytesIO()
    with stdout_redirector(f):
        pip.main(['list', '--outdated'])
    if not f.getvalue():
        print_passed()
    else:
        print('Outdated pip dependencies:')
        print('{0}'.format(f.getvalue()))
        print_failed()
    raise SystemExit(len(f.getvalue()))
Exemplo n.º 12
0
def git_check_remote():
    local = subprocess.check_output(
        ['git', 'rev-parse', '@'])
    remote = subprocess.check_output(
        ['git', 'rev-parse', '@{u}'])
    base = subprocess.check_output(
        ['git', 'merge-base', '@', '@{u}'])
    if local == remote:
        print('Local and remote are the same.')
    elif local == base:
        print_failure_message(
            'The current branch is behind the remote. '
            'Use `git pull` to bring the local branch current. ')
        raise SystemExit(1)
    elif remote == base:
        print_failure_message(
            'The current branch is ahead of the remote. '
            'Use `git push` to bring the remote branch current. ')
        raise SystemExit(1)
    else:
        print_failure_message(
            'The current branch has diverged from remote. '
            'Use `git pull` to bring the remote branch current, '
            'then merge and use `git push` to synchronize branches.')
        raise SystemExit(1)
Exemplo n.º 13
0
def commit():
    """Commit only if all the tests pass."""
    if _test_all() == 0:
        subprocess.check_call(['git', 'commit'])
    else:
        print_failure_message('\nTests failed, not committing.')
Exemplo n.º 14
0
def commit():
    """Commit only if all the tests pass."""
    if _test_all() == 0:
        subprocess.check_call(["git", "commit"])
    else:
        print_failure_message("\nTests failed, not committing.")
Exemplo n.º 15
0
def cov():
    """ Get test coverage """
    retcode = subprocess.call(
        'py.test --cov-report term-missing --cov pyres', shell=True)
    if retcode != 0:
        print_failure_message('Failed running pytest')
def commit():
    """Commit only if all the tests pass."""
    if _test_all() == 0:
        subprocess.check_call(['git', 'commit'])
    else:
        print_failure_message('\nTests failed, not committing.')
Exemplo n.º 17
0
def commit():
    """Commit only if all the tests pass."""
    if _test_all() == 0:
        subprocess.check_call(["git", "commit"])
    else:
        print_failure_message("\nTests failed, not committing.")