forked from guessit-io/guessit
/
fabfile.py
128 lines (104 loc) · 3.79 KB
/
fabfile.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
from fabric.api import *
from fabric.tasks import Task
@task
def doctests():
"""Run the doctests found in GuessIt classes"""
local('nosetests --with-doctest -vv guessit')
class TestTask(Task):
name = 'testtask'
def __init__(self, testname, docstring):
super(Task, self).__init__()
self.name = 'test_' + testname
self.__doc__ = 'Run the unittests for %s' % docstring
def run(self):
local('PYTHONPATH=.:$PYTHONPATH python guessit/test/%s.py' % self.name)
test_ep = TestTask('episode', 'episodes')
test_movie = TestTask('movie', 'movies')
test_auto = TestTask('autodetect', 'autodetected files')
test_auto_all = TestTask('autodetect_all', 'all files using autodetected type')
test_lang = TestTask('language', 'languages')
test_utils = TestTask('utils', 'utility functions')
test_matchtree = TestTask('matchtree', 'MatchTree')
@task
def unittests():
"""Run all the unittests"""
EXCLUDE = ['test_pypi_sdist']
def is_unittest(t):
return t[0].startswith('test_') and t[0] not in EXCLUDE
alltests = filter(is_unittest, globals().items())
for name, testcase in alltests:
testcase.run()
@task
def tests():
"""Run both the doctests and the unittests"""
unittests()
doctests()
@task
def clean_pyc():
"""Removes all the *.pyc files found in the repository"""
local('find . -iname "*.pyc" -delete')
@task
def pylint():
"""Runs pylint on GuessIt's source code. Only show problems, no report"""
local('pylint --reports=n --include-ids=y --disable=C,I,W0703 guessit')
@task
def pylint_report():
"""Runs pylint on GuessIt's source code, full report"""
local('pylint --include-ids=y --disable=C0103,C0111 guessit')
def open_file(filename):
"""Open the given file using the OS's native programs"""
if sys.platform.startswith('linux'):
local('xdg-open "%s"' % filename)
elif sys.platform == 'darwin':
local('open "%s"' % filename)
else:
print 'Platform not supported:', sys.platform
@task
def doc():
"""Build the Sphinx documentation and open it in a web browser"""
with lcd('docs'):
local('make html')
open_file('_build/html/index.html')
@task
def pypi_doc():
"""Builds the main page that will be uploaded to PyPI and open it in a
web browser"""
local('python setup.py --long-description | rst2html.py > /tmp/guessit_pypi_doc.html')
open_file('/tmp/guessit_pypi_doc.html')
# Release management functions
@task
def set_version(version):
"""Set the version in the guessit/__init__.py file"""
initfile = open('guessit/__init__.py').read()
initfile = re.sub(r"__version__ = '\S*'",
r"__version__ = '%s'" % version,
initfile)
open('guessit/__init__.py', 'w').write(initfile)
@task
def upload_pypi():
"""Build and upload the package on PyPI"""
local('python setup.py register sdist upload')
@task
def test_pypi_sdist():
"""Build the PyPI package and test whether it is installable and passes
the tests"""
d = '_tmp_pypi_guessit'
local('rm -fr dist %s' % d)
local('python setup.py sdist')
local('virtualenv %s' % d)
with lcd(d):
with prefix('source bin/activate'):
local('pip install ../dist/*')
local('pip install PyYaml') # to be able to run the tests
local('python -m guessit.test.test_autodetect')
local('python -m guessit.test.test_autodetect_all')
local('python -m guessit.test.test_movie')
local('python -m guessit.test.test_episode')
local('python -m guessit.test.test_language')
local('python -m guessit.test.test_matchtree')
local('python -m guessit.test.test_utils')
local('rm -fr %s' % d)