forked from aarongarrett/inspyred
/
pavement.py
157 lines (133 loc) · 4.57 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
#!/usr/bin/python2.6
# Standard library
import os
import sys
# Set up Paver
import paver
import paver.doctools
import paver.misctasks
from paver.path import path
from paver.easy import *
import paver.setuputils
paver.setuputils.install_distutils_tasks()
try:
from sphinxcontrib import paverutils
except:
paverutils = None
PROJECT = 'inspyred'
VERSION = '1.0'
# The sphinx templates expect the VERSION in the shell environment
os.environ['VERSION'] = VERSION
# Read the long description to give to setup
README = path('README.rst').text()
# Scan the input for package information
# to grab any data files (text, images, etc.)
# associated with sub-packages.
PACKAGE_DATA = paver.setuputils.find_package_data(PROJECT,
package=PROJECT,
only_in_packages=False
)
options(
setup=Bunch(
name = PROJECT,
version = VERSION,
description='A framework for creating bio-inspired computational intelligence algorithms in Python.',
long_description=README,
author='Aaron Garrett',
author_email='aaron.lee.garrett@gmail.com',
url='http://%s.github.com' % PROJECT,
download_url='https://github.com/{0}/{0}/downloads/{0}-{1}.tar.gz'.format(PROJECT, VERSION),
license='GPLv3+',
platforms=('Any'),
keywords=('python', 'optimization', 'evolutionary computation', 'genetic algorithm',
'particle swarm', 'estimation of distribution', 'differential evolution',
'nsga', 'paes', 'island model', 'multiobjective', 'ant colony'),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Artificial Intelligence'
],
packages = [PROJECT, '%s.ec' % PROJECT, '%s.ec.variators' % PROJECT, '%s.swarm' % PROJECT],
package_data=PACKAGE_DATA,
),
sdist = Bunch(
),
sphinx = Bunch(
sourcedir='docs',
docroot = '.',
builder = 'html',
doctrees='docs/_build/doctrees',
confdir = 'docs',
),
html = Bunch(
builddir='docs',
outdir='html',
templates='pkg',
),
# Some of the files include [[[ as part of a nested list data structure,
# so change the tags cog looks for to something less likely to appear.
cog=Bunch(
beginspec='{{{cog',
endspec='}}}',
endoutput='{{{end}}}',
),
minilib=Bunch(
extra_files=['doctools']
),
)
def run_script(input_file, script_name, interpreter='python'):
"""Run a script in the context of the input_file's directory,
return the text output formatted to be included as an rst
literal text block.
"""
from paver.easy import sh
from paver.path import path
rundir = path(input_file).dirname()
output_text = sh('cd %(rundir)s && %(interpreter)s %(script_name)s 2>&1' % vars(), capture=True)
response = '\n::\n\n\t$ %(interpreter)s %(script_name)s\n\t' % vars()
response += '\n\t'.join(output_text.splitlines())
while not response.endswith('\n\n'):
response += '\n'
return response
# Stuff run_script() into the builtins so we don't have to
# import it in all of the cog blocks where we want to use it.
__builtins__['run_script'] = run_script
def remake_directories(*dirnames):
"""Remove the directories and recreate them.
"""
for d in dirnames:
d = path(d)
if d.exists():
d.rmtree()
d.mkdir()
return
@task
@needs(['cog'])
def html(options):
if paverutils is None:
raise RuntimeError('Could not find sphinxcontrib.paverutils, will not be able to build HTML output.')
paverutils.html(options)
return
@task
@needs(['generate_setup', 'minilib',
'html_clean',
'setuptools.command.sdist'
])
def sdist(options):
"""Create a source distribution.
"""
pass
@task
def html_clean(options):
"""Remove sphinx output directories before building the HTML.
"""
remake_directories(options.sphinx.doctrees, options.html.outdir)
html(options)
return