darwin / firepython

Python logging console for Firebug

This URL has Read+Write access

firepython / pavement.py
100644 148 lines (118 sloc) 3.601 kb
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# -*- coding: utf-8 -*-
import os
import re
import sys
 
from paver.easy import *
from paver.setuputils import setup, find_packages
 
ROOT = path.getcwd()
sys.path.insert(0, ROOT) # use firepython from current folder
 
from firepython._setup_common import SETUP_ARGS
 
ADDON = ROOT.parent/'firelogger'
# ^--- firelogger is expected to be at same directory
# level as firepython project
FIREFOX = ADDON/'firefox'
INSTALL_RDF = FIREFOX/'install.rdf'
BUILD_DIR = ROOT/'build'
DIST_DIR = ROOT/'dist'
FPY = ROOT/'firepython'
FPY_EGG_INFO = ROOT/'FirePython.egg-info'
CRUFT = [
    BUILD_DIR,
    DIST_DIR,
    FPY_EGG_INFO,
    ROOT/'paver-minilib.zip',
]
API_VERSION = re.compile(r'<em:version>([^<]*)<\/em:version>')
PY_API_VERSION_DEF_RE = re.compile('__api_version__ = [\'"][^\'"]+[\'"]')
PY_API_VERSION_DEF = '__api_version__ = \'%s\''
 
 
SETUP_ARGS['packages'] = find_packages(exclude=['tests'])
setup(**SETUP_ARGS)
 
 
def get_version_from_install_rdf():
    match = API_VERSION.search(INSTALL_RDF.bytes())
    if match:
        return match.groups(1)[0].strip()
    else:
        raise Exception('failed to determine API version from %s'
                        % INSTALL_RDF)
 
 
@task
def xpi():
    """Prepare XPI"""
    assert ADDON.exists(), "firelogger addon not found!\n " \
                           "expected to be in %s" % ADDON
    os.chdir(ADDON)
    sh('rake')
 
 
@task
@needs(['sdist'])
def pypi():
    """Update PyPI index and upload library sources"""
    sh('python setup.py register')
    sh('python setup.py sdist --formats=gztar,bztar,zip upload')
 
 
@task
def update_api_version():
    """Resets API version in the firepython package base"""
    assert INSTALL_RDF.exists(), \
        "%s not found!, cannot extract version." % INSTALL_RDF
 
    ver = get_version_from_install_rdf()
    info('found API version %r from %s' % (ver, INSTALL_RDF))
    init = FPY/'__init__.py'
    old_bytes = init.bytes()
    ver_string = PY_API_VERSION_DEF % ver
    new_bytes = PY_API_VERSION_DEF_RE.sub(ver_string, old_bytes)
    if old_bytes != new_bytes:
        init.write_bytes(new_bytes)
    else:
        info('API version is the same, not updating...')
 
 
@task
def clean():
    """Clean up generated cruft"""
    for cruft_path in CRUFT:
        if cruft_path.isfile():
            cruft_path.remove()
        elif cruft_path.isdir():
            cruft_path.rmtree()
 
 
@task
@needs(['update_api_version', 'minilib', 'distutils.command.sdist'])
def sdist():
    """Combines paver minilib with setuptools' sdist"""
    pass
 
 
_TESTS_INSTALL_PKG = """\
Tests require `%(mod)s`.
Please `easy_install` or `pip install` the `%(pkg)s` package'
"""
 
@task
def _pretest_check():
    had_fail = False
 
    for mod, pkg in (('mock', 'Mock'), ('webtest', 'WebTest')):
        try:
            import mock
        except ImportError:
            info(_TESTS_INSTALL_PKG % dict(mod=mod, pkg=pkg))
            had_fail = True
 
    if had_fail:
        raise ImportError
 
 
@task
@needs(['_pretest_check', 'setuptools.command.test'])
def test():
    """make sure we have test dependencies, possibly alert user
about what to do to resolve, then run setuptools' `test`
"""
    pass
 
 
@task
def testall():
    """run *all* of the tests (requires nose)"""
    try:
        import nose
    except ImportError:
        info(_TESTS_INSTALL_PKG % dict(mod='nose', pkg='nose'))
        raise
 
    args = [
        'nosetests',
        '-i',
        '^itest',
        '-v',
        ROOT/'tests',
        '--with-coverage',
        '--cover-package',
        'firepython',
    ]
    nose.run(argv=args)