Commit 3932cb1c authored by André Anjos's avatar André Anjos 💬
Browse files

Merge branch 'termcolor' into 'master'

Terminal colors

See merge request !17
parents 178d4b6a 48ae05ae
Pipeline #26974 failed with stages
in 8 minutes and 21 seconds
......@@ -5,12 +5,13 @@
import io
import datetime
import logging
logger = logging.getLogger(__name__)
import pytz
import dateutil.parser
from .log import get_logger
logger = get_logger(__name__)
def parse_date(d):
'''Parses any date supported by :py:func:`dateutil.parser.parse`'''
......
......@@ -4,12 +4,12 @@
'''Tools to help CI-based builds and artifact deployment'''
import logging
logger = logging.getLogger(__name__)
import git
import distutils.version
from .log import get_logger
logger = get_logger(__name__)
def is_master(refname, tag, repodir):
'''Tells if we're on the master branch via ref_name or tag
......
......@@ -6,11 +6,11 @@
import os
import pkg_resources
import logging
logger = logging.getLogger(__name__)
from . import bootstrap
from .log import get_logger
logger = get_logger(__name__)
BASE_CONDARC = bootstrap._BASE_CONDARC
'''Default setup for conda builds'''
......
......@@ -7,6 +7,10 @@
import sys
import logging
import click
import termcolor
# get the default root logger of Bob
_logger = logging.getLogger('bob')
......@@ -28,6 +32,87 @@ _debug_info.addFilter(_InfoFilter())
_logger.addHandler(_debug_info)
COLORMAP = dict(
debug=dict(),
info=dict(attrs=['bold']),
warn=dict(color='yellow', attrs=['bold']),
warning=dict(color='yellow', attrs=['bold']),
error=dict(color='red'),
exception=dict(color='red', attrs=['bold']),
critical=dict(color='red', attrs=['bold']),
)
'''Default color map for homogenized color display'''
def _supports_color():
"""
Returns True if the running system's terminal supports color, and False
otherwise.
"""
plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
'ANSICON' in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
if not supported_platform or not is_a_tty:
return False
return True
class ColorLog(object):
'''Colorizes logging colors'''
def __init__(self, logger):
self._log = logger
def __getattr__(self, name):
if name in ['debug', 'info', 'warn', 'warning', 'error', 'exception',
'critical']:
if _supports_color():
return lambda s, *args: getattr(self._log, name)(
termcolor.colored(s, **COLORMAP[name]), *args)
else:
return lambda s, *args: getattr(self._log, name)(s, *args)
return getattr(self._log, name)
def get_logger(name):
"""Returns the default logger as setup by this module"""
return ColorLog(logging.getLogger(name))
def _echo(text, *args, **kwargs):
"""Provides a colorized version of :py:func:`click.echo` (for terminals)
The color is stripped off if outputting to a file or piping the results of
a command using this function.
Parameters:
text (str): The text to be printed
args (tuple): Tuple of attributes directly passed to
:py:func:`termcolor.colored`
kwargs (dict): Dictionary of attributes directly passed to
:py:func:`termcolor.colored`
"""
click.echo(termcolor.colored(text, *args, **kwargs))
def echo_normal(text):
"""Color preset for normal text output for :py:func:`click.echo`"""
_echo(text, 'green')
def echo_warning(text):
"""Color preset for normal warning output for :py:func:`click.echo`"""
_echo(text, **COLORMAP['warn'])
# helper functions to instantiate and set-up logging
def setup(logger_name,
format="%(levelname)s:%(name)s@%(asctime)s: %(message)s"):
......@@ -68,7 +153,7 @@ def setup(logger_name,
for handler in _logger.handlers:
handler.setFormatter(formatter)
return logger
return ColorLog(logger)
def set_verbosity_level(logger, level):
......
......@@ -9,8 +9,8 @@ import time
import shutil
import gitlab
import logging
logger = logging.getLogger(__name__)
from .log import get_logger
logger = get_logger(__name__)
from distutils.version import StrictVersion
......
......@@ -3,8 +3,6 @@
import os
import sys
import logging
logger = logging.getLogger(__name__)
import yaml
import click
......@@ -12,7 +10,6 @@ import pkg_resources
import conda_build.api
from . import bdt
from ..log import verbosity_option
from ..build import next_build_number, conda_arch, should_skip_build, \
get_rendered_metadata, get_parsed_recipe, make_conda_config, \
get_docserver_setup, get_env_directory
......@@ -20,6 +17,9 @@ from ..constants import CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \
SERVER, MATPLOTLIB_RCDIR, BASE_CONDARC
from ..bootstrap import set_environment, get_channels
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......
#!/usr/bin/env python
import os
import logging
logger = logging.getLogger(__name__)
import click
from . import bdt
from ..log import verbosity_option
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
......
......@@ -4,17 +4,16 @@ import os
import sys
import datetime
import logging
logger = logging.getLogger(__name__)
import click
from . import bdt
from ..log import verbosity_option
from ..changelog import get_last_tag_date, write_tags_with_commits
from ..changelog import parse_date
from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......
......@@ -3,8 +3,6 @@
import os
import re
import glob
import logging
logger = logging.getLogger(__name__)
import yaml
import click
......@@ -13,9 +11,11 @@ import conda_build.api
from click_plugins import with_plugins
from . import bdt
from ..log import verbosity_option
from ..constants import SERVER
from ..log import verbosity_option, get_logger, echo_normal
logger = get_logger(__name__)
@with_plugins(pkg_resources.iter_entry_points('bdt.ci.cli'))
@click.group(cls=bdt.AliasedGroup)
......@@ -363,11 +363,11 @@ def base_build(order, python, dry_run):
recipes = list(itertools.product([None], recipes))
for order, (pyver, recipe) in enumerate(recipes):
click.echo('\n' + (80*'='))
echo_normal('\n' + (80*'='))
pytext = 'for python-%s ' % pyver if pyver is not None else ''
click.echo('Building "%s" %s(%d/%d)' % \
echo_normal('Building "%s" %s(%d/%d)' % \
(recipe, pytext, order+1, len(recipes)))
click.echo((80*'=') + '\n')
echo_normal((80*'=') + '\n')
if not os.path.exists(os.path.join(recipe, 'meta.yaml')):
logger.info('Ignoring directory "%s" - no meta.yaml found' % recipe)
continue
......
#!/usr/bin/env python
import os
import logging
logger = logging.getLogger(__name__)
import click
from . import bdt
from ..log import verbosity_option
from ..release import get_gitlab_instance, update_files_with_mr
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......
......@@ -3,20 +3,20 @@
import os
import sys
import logging
logger = logging.getLogger(__name__)
import pkg_resources
import click
import yaml
from . import bdt
from ..log import verbosity_option
from ..build import parse_dependencies, conda_create, make_conda_config
from ..constants import BASE_CONDARC, CONDA_BUILD_CONFIG, \
CONDA_RECIPE_APPEND, SERVER
from ..bootstrap import set_environment, get_channels
from ..log import verbosity_option, get_logger, echo_normal
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......@@ -138,4 +138,4 @@ def create(name, recipe_dir, python, overwrite, condarc, use_local, config,
deps = parse_dependencies(recipe_dir, conda_config)
status = conda_create(conda, name, overwrite, condarc_options, deps,
dry_run, use_local)
click.echo('Execute on your shell: "conda activate %s"' % name)
echo_normal('Execute on your shell: "conda activate %s"' % name)
......@@ -2,15 +2,14 @@
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger(__name__)
from sphinx.ext import intersphinx
import click
from . import bdt
from ..log import verbosity_option
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
......
#!/usr/bin/env python
import os
import logging
logger = logging.getLogger(__name__)
import click
from . import bdt
from ..log import verbosity_option
from ..release import get_gitlab_instance, download_path
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......
#!/usr/bin/env python
import os
import logging
logger = logging.getLogger(__name__)
import click
import gitlab
from . import bdt
from ..log import verbosity_option
from ..changelog import get_last_tag, parse_date
from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger, echo_normal, echo_warning
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......@@ -38,11 +39,16 @@ def lasttag(package):
gl = get_gitlab_instance()
# we lookup the gitlab package once
use_package = gl.projects.get(package)
logger.info('Found gitlab project %s (id=%d)',
use_package.attributes['path_with_namespace'], use_package.id)
tag = get_last_tag(use_package)
date = parse_date(tag.commit['committed_date'])
click.echo('Lastest tag for %s is %s (%s)' % \
(package, tag.name, date.strftime('%Y-%m-%d %H:%M:%S')))
try:
use_package = gl.projects.get(package)
logger.info('Found gitlab project %s (id=%d)',
use_package.attributes['path_with_namespace'], use_package.id)
tag = get_last_tag(use_package)
date = parse_date(tag.commit['committed_date'])
echo_normal('%s: %s (%s)' % \
(package, tag.name, date.strftime('%Y-%m-%d %H:%M:%S')))
except gitlab.GitlabGetError as e:
logger.warn('Gitlab access error - package %s does not exist?',
package)
echo_warning('%s: unknown' % (package,))
......@@ -2,16 +2,16 @@
import os
import shutil
import logging
import datetime
logger = logging.getLogger(__name__)
import click
import jinja2
import pkg_resources
from . import bdt
from ..log import verbosity_option
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
def copy_file(template, output_dir):
......
......@@ -4,17 +4,17 @@
import os
import logging
logger = logging.getLogger(__name__)
import click
from . import bdt
from ..log import verbosity_option
from ..release import release_bob, parse_and_process_package_changelog
from ..release import release_package, wait_for_pipeline_to_finish
from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......
......@@ -6,13 +6,12 @@ import sys
import click
import gitlab
import logging
logger = logging.getLogger(__name__)
from . import bdt
from ..log import verbosity_option
from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger, echo_normal, echo_warning
logger = get_logger(__name__)
@click.command(epilog='''
Examples:
......@@ -48,12 +47,12 @@ def visibility(target, group):
# reads package list or considers name to be a package name
if os.path.exists(target) and os.path.isfile(target):
logger.info('Reading package names from file %s...', target)
logger.debug('Reading package names from file %s...', target)
with open(target, 'rt') as f:
packages = [k.strip() for k in f.readlines() if k.strip() and not \
k.strip().startswith('#')]
else:
logger.info('Assuming %s is a package name (file does not ' \
logger.debug('Assuming %s is a package name (file does not ' \
'exist)...', target)
packages = [target]
......@@ -66,11 +65,11 @@ def visibility(target, group):
# retrieves the gitlab package object
try:
use_package = gl.projects.get(package)
logger.info('Found gitlab project %s (id=%d)',
logger.debug('Found gitlab project %s (id=%d)',
use_package.attributes['path_with_namespace'], use_package.id)
click.echo('%s: %s' % (package,
echo_normal('%s: %s' % (package,
use_package.attributes['visibility'].lower()))
except gitlab.GitlabGetError as e:
logger.warn('Gitlab access error - package %s does not exist?',
package)
click.echo('%s: unknown' % (package,))
echo_warning('%s: unknown' % (package,))
# -*- coding: utf-8
import functools
import logging
import os
import shutil
import threading
......@@ -15,6 +14,10 @@ from .connection import *
from .exceptions import *
from .urn import Urn
from ..log import get_logger
logger = get_logger(__name__)
try:
from urllib.parse import unquote, urlsplit
except ImportError:
......@@ -22,7 +25,6 @@ except ImportError:
from urlparse import urlsplit
__version__ = "0.2"
log = logging.getLogger(__name__)
def listdir(directory):
......
......@@ -47,6 +47,7 @@ requirements:
- twine
- lxml
- jinja2
- termcolor
test:
requires:
......
......@@ -21,6 +21,7 @@ requires = [
'twine',
'lxml',
'jinja2',
'termcolor',
]
setup(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment