forked from Flexget/Flexget
/
pavement.py
406 lines (338 loc) · 11.8 KB
/
pavement.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
import os
import re
from paver.easy import *
import paver.virtual
import paver.setuputils
from paver import svn
from paver.setuputils import setup, find_package_data, find_packages
sphinxcontrib = False
try:
from sphinxcontrib import paverutils
sphinxcontrib = True
except ImportError:
pass
sys.path.insert(0, '')
options = environment.options
setup(
name='FlexGet',
version='1.0', # our tasks append the r1234 (current svn revision) to the version number
description='FlexGet is a program aimed to automate downloading or processing content (torrents, podcasts, etc.) from different sources like RSS-feeds, html-pages, various sites and more.',
author='Marko Koivusalo',
author_email='marko.koivusalo@gmail.com',
license='MIT',
url='http://flexget.com',
install_requires=['FeedParser>=5.1', 'SQLAlchemy==0.7.4', 'PyYAML', 'BeautifulSoup>=3.2, <3.3',
'html5lib>=0.11', 'PyRSS2Gen', 'pynzb', 'progressbar', 'jinja2', 'flask', 'cherrypy',
'requests>=0.9.1, <0.10'],
packages=find_packages(exclude=['tests']),
package_data=find_package_data('flexget', package='flexget',
exclude=['FlexGet.egg-info', '*.pyc'],
only_in_packages=False), # NOTE: the exclude does not seem to work
zip_safe=False,
test_suite='nose.collector',
setup_requires=['nose>=0.11'],
extras_require={
'memusage': ['guppy'],
'NZB': ['pynzb'],
'TaskTray': ['pywin32'],
},
entry_points="""
[console_scripts]
flexget = flexget:main
[gui_scripts]
flexget-webui = flexget.ui:main
"""
)
options(
minilib=Bunch(
extra_files=['virtual', 'svn']
),
virtualenv=Bunch(
packages_to_install=['nose>=0.11'],
paver_command_line='develop',
unzip_setuptools=True
),
# sphinxcontrib.paverutils
sphinx=Bunch(
docroot='docs',
builddir='build',
builder='html',
confdir='docs'
),
)
def freplace(name, what_str, with_str):
"""Replaces a :what_str: with :with_str: in file :name:"""
import fileinput
for line in fileinput.FileInput(name, inplace=1):
if what_str in line:
line = line.replace(what_str, with_str)
print line,
def set_init_version(ver):
"""Replaces the version with :ver: in __init__.py"""
import fileinput
for line in fileinput.FileInput('flexget/__init__.py', inplace=1):
if line.startswith('__version__ = '):
line = "__version__ = '%s'\n" % ver
print line,
@task
@cmdopts([
('online', None, 'Run online tests')
])
def test(options):
"""Run FlexGet unit tests"""
options.setdefault('test', Bunch())
import nose
from nose.plugins.manager import DefaultPluginManager
cfg = nose.config.Config(plugins=DefaultPluginManager(), verbosity=2)
args = []
# Adding the -v flag makes the tests fail in python 2.7
#args.append('-v')
args.append('--processes=4')
args.append('-x')
if not options.test.get('online'):
args.append('--attr=!online')
args.append('--where=tests')
# Store current path since --where changes it, restore when leaving
cwd = os.getcwd()
try:
return nose.run(argv=args, config=cfg)
finally:
os.chdir(cwd)
@task
def clean():
"""Cleans up the virtualenv"""
import os, glob
for p in ('bin', 'Scripts', 'build', 'dist', 'include', 'lib', 'man',
'share', 'FlexGet.egg-info', 'paver-minilib.zip', 'setup.py'):
pth = path(p)
if pth.isdir():
pth.rmtree()
elif pth.isfile():
pth.remove()
for pkg in set(options.setup.packages) | set(('tests',)):
for filename in glob.glob(pkg.replace('.', os.sep) + "/*.py[oc~]"):
path(filename).remove()
@task
@cmdopts([
('dist-dir=', 'd', 'directory to put final built distributions in')
])
def sdist(options):
"""Build tar.gz distribution package"""
revision = svn.info().get('last_changed_rev')
print 'Revision: %s' % revision
# clean previous build
print 'Cleaning build...'
for p in ['build']:
pth = path(p)
if pth.isdir():
pth.rmtree()
elif pth.isfile():
pth.remove()
else:
print 'Unable to remove %s' % pth
# remove pre-compiled pycs from tests, I don't know why paver even tries to include them ...
# seems to happen only with sdist though
for pyc in path('tests/').files('*.pyc'):
pyc.remove()
ver = '%sr%s' % (options['version'], revision)
print 'Building %s' % ver
# hack for getting options from release task
if hasattr(options, 'release'):
if options.release.get('dist_dir'):
options.setdefault('sdist', Bunch())['dist_dir'] = options.release.dist_dir
else:
if options.sdist.get('dist_dir'):
options.setdefault('sdist', Bunch())['dist_dir'] = options.sdist.dist_dir
# replace version number
set_init_version(ver)
# hack version number into setup( ... options='1.0' ...)
from paver import tasks
setup_section = tasks.environment.options.setdefault("setup", Bunch())
setup_section.update(version=ver)
for t in ['minilib', 'generate_setup', 'setuptools.command.sdist']:
call_task(t)
# restore version ...
set_init_version('{subversion}')
@task
@cmdopts([
('dist-dir=', 'd', 'directory to put final built distributions in')
])
def make_egg(options):
# naming this task to bdist_egg will make egg installation fail
options.setdefault('release', Bunch())
revision = svn.info().get('last_changed_rev')
ver = '%sr%s' % (options['version'], revision)
# hack version number into setup( ... options='1.0-svn' ...)
from paver import tasks
setup_section = tasks.environment.options.setdefault("setup", Bunch())
setup_section.update(version=ver)
# replace version number
set_init_version(ver)
print 'Making egg release'
import shutil
shutil.copytree('FlexGet.egg-info', 'FlexGet.egg-info-backup')
if options.release.get('dist_dir'):
options.setdefault('bdist_egg', Bunch())['dist_dir'] = options.release.dist_dir
# hack for getting options from release task
if hasattr(options, 'release'):
if options.release.get('dist_dir'):
options.setdefault('bdist_egg', Bunch())['dist_dir'] = options.release.dist_dir
else:
if options.sdist.get('dist_dir'):
options.setdefault('bdist_egg', Bunch())['dist_dir'] = options.sdist.dist_dir
for t in ["minilib", "generate_setup", "setuptools.command.bdist_egg"]:
call_task(t)
# restore version ...
set_init_version('{subversion}')
# restore egg info from backup
print 'Removing FlexGet.egg-info ...'
shutil.rmtree('FlexGet.egg-info')
print 'Restoring FlexGet.egg-info'
shutil.move('FlexGet.egg-info-backup', 'FlexGet.egg-info')
@task
def coverage():
"""Make coverage.flexget.com"""
# --with-coverage --cover-package=flexget --cover-html --cover-html-dir /var/www/flexget_coverage/
import nose
from nose.plugins.manager import DefaultPluginManager
cfg = nose.config.Config(plugins=DefaultPluginManager(), verbosity=2)
argv = ['bin/paver']
argv.extend(['--attr=!online'])
argv.append('--with-coverage')
argv.append('--cover-html')
argv.extend(['--cover-package', 'flexget'])
argv.extend(['--cover-html-dir', '/var/www/flexget_coverage/'])
nose.run(argv=argv, config=cfg)
print 'Coverage generated'
@task
@cmdopts([
('docs-dir=', 'd', 'directory to put the documetation in')
])
def docs():
if not sphinxcontrib:
print 'ERROR: requires sphinxcontrib-paverutils'
sys.exit(1)
from paver import tasks
setup_section = tasks.environment.options.setdefault("sphinx", Bunch())
setup_section.update(outdir=options.docs.get('docs_dir', 'build/sphinx'))
call_task('html')
@task
@cmdopts([
('docs-dir=', 'd', 'directory to put the api documetation in'),
('excludes=', 'x', 'list of packages to exclude'),
])
def epydocs():
"""Create documentation."""
from epydoc import cli
path('build').exists() or path('build').makedirs()
# get package list, without sub-packages
doc_packages = set(options.setup.packages)
for pkg in list(doc_packages):
doc_packages -= set(p for p in doc_packages if str(p).startswith(pkg + '.'))
doc_packages = list(doc_packages)
# get storage path
docs_dir = options.epydocs.get('docs_dir', 'build/apidocs')
# set up excludes
try:
exclude_names = options.epydocs.excludes
except AttributeError:
exclude_names = []
else:
exclude_names = exclude_names.replace(',', ' ').split()
excludes = []
for pkg in exclude_names:
excludes.append("--exclude")
excludes.append('^' + re.escape(pkg))
# call epydoc in-process
sys_argv = sys.argv
try:
sys.argv = [
sys.argv[0] + "::epydoc",
"-v",
"--inheritance", "listed",
"--output", docs_dir,
"--name", "%s %s" % (options.setup.name, options.setup.version),
"--url", options.setup.url,
"--graph", "umlclasstree",
] + excludes + doc_packages
sys.stderr.write("Running '%s'\n" % ("' '".join(sys.argv)))
cli.cli()
finally:
sys.argv = sys_argv
@task
@cmdopts([
('online', None, 'runs online unit tests'),
('dist-dir=', 'd', 'directory to put final built distributions in'),
('no-tests', None, 'skips unit tests'),
('type=', None, 'type of release (src | egg)')
])
def release(options):
"""Make a FlexGet release. Same as bdist_egg but adds version information."""
if options.release.get('type') not in ['src', 'egg']:
print 'Invalid --type, must be src or egg'
return
print 'Cleaning build...'
for p in ['build']:
pth = path(p)
if pth.isdir():
pth.rmtree()
elif pth.isfile():
pth.remove()
else:
print 'Unable to remove %s' % pth
# run unit tests
if options.release.get('online'):
options.setdefault('test', Bunch())['online'] = True
if not options.release.get('no_tests'):
if not test():
print 'Unit tests did not pass'
import sys
sys.exit(1)
if options.release.get('type') == 'egg':
print 'Making egg release'
make_egg(options)
else:
print 'Making src release'
sdist(options)
@task
def install_tools():
"""Install development / hudson tools and dependencies"""
try:
import pip
except:
print 'FATAL: Unable to import pip, please install it and run this again!'
return
try:
import sphinxcontrib
print 'sphinxcontrib INSTALLED'
except:
pip.main(['install', 'sphinxcontrib-paverutils'])
try:
import pylint
print 'Pylint INSTALLED'
except:
pip.main(['install', 'pylint']) # OR instead of pylint logilab.pylintinstaller ?
try:
import coverage
print 'Coverage INSTALLED'
except:
pip.main(['install', 'coverage'])
try:
import nosexcover
print 'Nose-xcover INSTALLED'
except:
pip.main(['install', 'http://github.com/cmheisel/nose-xcover/zipball/master'])
try:
import epydoc
print 'epydoc INSTALLED'
except:
pip.main(['install', 'epydoc'])
@task
def clean_compiled():
import os
for root, dirs, files in os.walk('flexget'):
for name in files:
fqn = os.path.join(root, name)
if fqn[-3:] == 'pyc' or fqn[-3:] == 'pyo' or fqn[-5:] == 'cover':
print 'Deleting %s' % fqn
os.remove(fqn)