aboutsummaryrefslogtreecommitdiffstats
path: root/dodo.py
blob: e350afecc24b564f0a14fc4789c3e87527920fc2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

import os
import fnmatch
import locale
import subprocess

DOIT_CONFIG = {
    'default_tasks': ['flake8', 'test'],
    'reporter': 'executed-only',
}


def recursive_glob(path, pattern):
    """recursively walk path directories and return files matching the pattern"""
    for root, dirnames, filenames in os.walk(path, followlinks=True):
        for filename in fnmatch.filter(filenames, pattern):
            yield os.path.join(root, filename)


def task_flake8():
    """flake8 - static check for python files"""
    yield {
        'name': os.path.join(os.getcwd(), 'nikola'),
        'actions': ['flake8 nikola/'],
    }

def task_pep257():
    """pep257 -- static check for docstring style"""
    yield {
        'name': os.path.join(os.getcwd(), 'nikola'),
        'actions': ["pep257 --count --match-dir='(?!^\.)(?!data).*' nikola/"],
    }


def task_locale():
    """set environ locale vars used in nikola tests"""
    def set_nikola_test_locales():
        try:
            out = subprocess.check_output(['locale', '-a'])
            out = out.decode('utf-8')
            locales = []
            languages = set()
            for line in out.splitlines():
                if (line.endswith('.utf8') or line.endswith('.UTF-8')) and '_' in line:
                    lang = line.split('_')[0]
                    if lang not in languages:
                        try:
                            locale.setlocale(locale.LC_ALL, str(line))
                        except:
                            continue
                        languages.add(lang)
                        locales.append((lang, line))
                        if len(locales) == 2:
                            break
            if len(locales) != 2:
                return False  # task failed
            else:
                os.environ['NIKOLA_LOCALE_DEFAULT'] = ','.join(locales[0])
                os.environ['NIKOLA_LOCALE_OTHER'] = ','.join(locales[1])
        finally:
            # restore to default locale
            locale.resetlocale()

    return {'actions': [set_nikola_test_locales], 'verbosity': 2}


def task_doctest():
    """run doctests with py.test"""
    return {
        'actions': ['py.test --doctest-modules nikola/'],
        'verbosity': 2,
    }


def task_test():
    """run unit-tests using py.test"""
    return {
        'task_dep': ['locale', 'doctest'],
        'actions': ['py.test tests/'],
    }


def task_coverage():
    """run unit-tests using py.test, with coverage reporting"""
    return {
        'task_dep': ['locale', 'doctest'],
        'actions': ['py.test --cov nikola --cov-report term-missing tests/'],
        'verbosity': 2,
    }


def task_gen_completion():
    """generate tab-completion scripts"""
    cmd = 'nikola tabcompletion --shell {0} --hardcode-tasks > _nikola_{0}'
    for shell in ('bash', 'zsh'):
        yield {
            'name': shell,
            'actions': [cmd.format(shell)],
            'targets': ['_nikola_{0}'.format(shell)],
        }