repos/MysteryMachine

view pavement.py @ 313:d7591777a9f6

New installer,README and version bump for 0.14
author Roger Gammans <rgammans@computer-surgery.co.uk>
date Thu Apr 07 20:53:16 2011 +0100 (13 months ago)
parents c7d01e387ccb
children
line source
1 #!/usr/bin/env python
2 # paverment.py - Copyright Roger Gammans
3 #
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19 # d
22 #
23 # Find the current state of setuptools..
24 #
27 existing_setuptools_available = False
28 try:
29 import setuptools
30 existing_setuptools_available = True
31 except:
32 pass
34 ez_setup_available = False
35 try:
36 import ez_setup
37 version = ez_setup.DEFAULT_VERSION
38 if existing_setuptools_available:
39 version = setuptools.__version__
40 ez_setup.use_setuptools(version = version)
41 ez_setup_available = True
42 except ImportError:
43 pass
45 easy_install_available = False
46 try:
47 import setuptools.command.easy_install
48 easy_install_available = True
49 except ImportError:
50 pass
53 DIST_PACKAGES = [ "yapsy" , "MysteryMachine","MysteryMachine.schema",
54 "MysteryMachine.store","MysteryMachine.parsetools",
55 "MysteryMachine.Ui",
56 "MysteryMachine.Ui.wx","MysteryMachine.Ui.wx.dialogs",
57 "MysteryMachine.utils",
58 "MysteryMachine.policies" , "MysteryMachine.document" ]
60 PY_MODULES = [ 'pyparsing' ]
62 #Mercurial and pyaprsing (as of 1.5.2 ) don't install with easy_install.
63 EZ_PACKAGES = ["docutils" ,
64 # "mercurial" ,
65 # "bpython" , # We add bpython back in later...
66 # "pyparsing > 1.5" ,
67 "PyYaml"]
70 TESTSDIR = "tests"
71 FILES = [ "AUTHORS", "CodingGuidelines", "OriginalDesign" ,"README",
72 "paver-minilib.zip" ]
73 DIRS = ["docs" , "examples" ,"graphics", "scripts" ,"patches" ,
74 "MysteryMachine/TrustedPlugIns", TESTSDIR ]
75 SCRIPTS = [ 'setup.py' , 'ez_setup.py' ]
77 VENVSCRIPT = 'install.py'
79 PYTHONS= [ "python" ]
81 import sys
82 import os
83 import shutil
84 import atexit
86 from paver.easy import *
87 from paver.setuputils import setup
89 def find_all(path,dirname):
90 for dir,dirs,files in os.walk(path):
91 for file in files:
92 if re.search("~$",file): continue
93 if re.search("\.pyc$",file): continue
94 if re.search("^\.",file): continue
95 if re.search("\.orig$",file): continue
96 filename = os.path.join(dir,file)
97 yield filename
100 #
101 # Redefine minilib so that it includes the virtual module
102 #
103 @task
104 def minilib(options):
105 #paver seems to complain if this is already there..
106 if 'extra_files' not in options:
107 options['extra_files']= [ ]
108 options['extra_files'] += ['virtual']
109 paver.misctasks.minilib(options)
112 @task
113 @needs('generate_setup','minilib','src_environ')
114 def sdist():
115 """Create a source distribution (tarball, zip file, etc.)"""
116 global SCRIPTS
118 pkgs = {}
119 path = sys.path
120 path.insert(0,".")
121 for pkg in DIST_PACKAGES:
122 pkgdir = pkg.split(".")
123 for dir in sys.path:
124 if os.path.isdir(os.path.join(dir,*pkgdir)):
125 try:
126 #Put all our need packages in the local directory.
127 os.symlink(os.path.join(dir,*pkgdir),os.path.join(pkgdir[0],*pkgdir[1:]))
128 except:
129 pass
131 for pkg in PY_MODULES:
132 filedir = pkg.split(".")
133 filedir[-1] = filedir[-1]+ ".py"
134 for dir in sys.path:
135 #Check for package as standalone file
136 if os.path.exists(os.path.join(dir,*filedir)):
137 try:
138 #Put all our need packages in the local directory
139 shutil.copy(os.path.join(dir,*filedir),os.path.join(filedir[0],*filedir[1:]))
140 #Register deletion of new filefor when we've finished..
141 atexit.register(os.remove,os.path.join(filedir[0],*filedir[1:]))
142 except:
143 pass
145 #Create find data files scripts etc needed for sdist.
146 for dir in DIRS:
147 for file in find_all(dir,dir):
148 SCRIPTS += [ file ]
150 SCRIPTS += FILES
151 SCRIPTS += VENVSCRIPT
153 #If ez_setup.py is not on our sys.path.
154 if not ez_setup_available:
155 import urllib
156 urllib.urlretrieve("http://peak.telecommunity.com/dist/ez_setup.py","ez_setup.py")
159 paver.virtual.bootstrap()
160 call_task("setuptools.command.sdist")
162 import re
163 STRIP = re.compile('\.py$')
165 @task
166 def test():
167 """Run MysteryMachine units tests from the source distribution
168 with the default python"""
169 _do_test( [ os.curdir ] )
171 @task
172 def test_installed():
173 """Run MysteryMachine units tests on the Installed MysteryMachine distribution
174 with the current python"""
175 global PYTHONS
176 PYTHONS = [ sys.executable ]
177 _do_test()
179 def _do_test(path_prefix=[]):
180 path=os.getenv("PYTHONPATH")
181 add_path = os.pathsep.join(path_prefix)
182 if path == None:
183 path = add_path
184 else:
185 path = path+os.pathsep+add_path
187 if path: os.putenv("PYTHONPATH",path)
189 for python in PYTHONS:
190 sys.stderr.write( "Testing under %s:\n" % python )
191 #TODO: should this inner loop go inside tests/__init__.py ?
192 for module in os.listdir('tests/'):
193 #Turn filenmae into module name
194 testname , replaced =re.subn(STRIP,"",module)
195 # SKip invalid module names
196 if not replaced: continue
197 #run tests.
198 sys.stderr.write("Running %s (%s)" % (module,python) )
199 os.system("%s %s/%s" % ( python, TESTSDIR, module))
203 def relaunch_self(extra_args):
204 """Relaunches this process with additional arguments"""
205 args = [ sys.executable ] + sys.argv + extra_args
206 #Start again,
207 os.execv(sys.executable,args)
209 @task
210 #should install mercurial
211 def dst_environ(options):
212 """Install MysteryMachine dependencies that setuptools can't handle without help"""
213 #Check whether we need pyparsing...
214 try:
215 import pyparsing
216 v = pyparsing.__version__.split(".")
217 for existing,minimum in zip(v,['1','5','0']):
218 if existing < minimum: raise ImportError()
219 #pyparsing exists in a usable version - don't override.
220 options.setup.py_modules.remove('pyparsing')
221 except ImportError:
222 #We need the shipping version of pyparsing with mysterymachine
223 # So the standard options are ok.
224 pass
226 #TODO Install mercurial
228 @task
229 @cmdopts([('srcenv-loop=', 'l' ,'internal use only - used to detect infinite loops')])
230 def src_environ(options):
231 """Install packages necessary for the installer in the source environment"""
232 print "verifying src environment"
233 try:
234 import virtualenv
235 print "virtual env already here - nothing to do"
236 except ImportError:
237 if int(options.src_environ.get('srcenv_loop',0)) == 1:
238 raise LogicError("Virualenv install loop detected")
239 print "trying to install virtualenv"
240 if easy_install_available:
241 print ".with easy_install"
242 print "calling easy_install"
243 old_args = sys.argv
244 sys.argv = ['fake', 'virtualenv']
245 import setuptools.command.easy_install
246 setuptools.command.easy_install.main()
247 sys.argv = old_args
248 else:
249 print "...giving up - can't install virtualenv"
251 #Hope all is well
252 print "importing paver virtual"
253 import paver.virtual
254 if not paver.virtual.has_virtualenv:
255 relaunch_self(["--srcenv-loop","1"])
256 #**** NEVER GETS HERE - Relaunch DOES NOT RETURN****
258 if sys.platform[:3] == 'win':
259 try:
260 ##This is a workaround for issue 40 in virtualenv
261 import FixTk
262 #Fix Tk sets some useful envvars that the virtual env will need
263 tk=open("FixTk.py","w")
264 tk.write("import os\n")
265 tk.write("os.environ[\"TCL_LIBRARY\"]=\"%s\"\n" % os.environ["TCL_LIBRARY"])
266 tk.write("os.environ[\"TK_LIBRARY\"] =\"%s\"\n" % os.environ["TK_LIBRARY"])
267 tk.write("os.environ[\"TIX_LIBRARY\"]=\"%s\"\n" % os.environ["TIX_LIBRARY"])
268 tk.close()
269 options.setup.py_modules += ['FixTk']
270 except ImportError:
271 pass
272 else:
273 #Bpython is worth install on the Unix & Macs.
274 if 'bpython' not in options.virtualenv.packages_to_install:
275 options.virtualenv.packages_to_install.append('bpython')
277 @task
278 @needs('dst_environ')
279 def install_here():
280 """Install everything from the build dir into t)he current env.
282 This does the usual install thing installing all of the MysteryMachine
283 packages and there dependencies into the current environment.
285 If you wish to install MysteryMachine into your global environement
286 this /might/ be want you want.
287 """
288 call_task('setuptools.command.install')
289 #Check the plugins (TrustedPlugins directory has been installed.
291 ##We do this here since the MysteryMachine directory should have been
292 ## created by now, and by using the import we can hopefully, ensure
293 ## consistency.
294 oldpath = sys.path
295 if sys.path[0] == "paver-minilib.zip":
296 sys.path = sys.path[2:]
297 from MysteryMachine.ExtensionLib import DEFAULT_TRUSTEDPLUGIN_PATH
298 print DEFAULT_TRUSTEDPLUGIN_PATH
299 shutil.copytree("MysteryMachine/TrustedPlugIns", DEFAULT_TRUSTEDPLUGIN_PATH)
300 sys.path = oldpath
302 #Do a final test of the installation.
303 call_task('test_installed')
306 @task
307 @needs('src_environ')
308 @cmdopts([('installdir=', 'd' ,'Directory to install MysteryMachine into')])
309 def install(options):
310 """Create a virtual environment and install into it.
312 You problably want this option as it ensures MysteryMachine doesn't
313 touch your systemwide yapsy install.
315 MysteryMachine currently requires a patched version of ypasy, so
316 installing mysterrymachine virtually means we don't break any
317 existing python scripts on your system.
318 """
319 #options(virtualenv = Bunch(dest_dir = options.install.installdir,
320 # paver_command_line = "install_here"))
322 # We can't add this a a dependencies - because it needs virtualenv
323 # which might not exist and dependency resolution.
324 call_task('paver.virtual.bootstrap')
326 here = os.getcwd()
327 try:
328 os.mkdir(options.install.installdir)
329 except OSError, e:
330 if e.errno != 17: raise e
332 os.chdir(options.install.installdir)
333 #call Pre built install file , creates virtual environment etc..
334 import subprocess
335 subprocess.call([sys.executable , os.path.join(here,"install.py")])
336 os.chdir(here)
337 #Relaunch paver to install ourself into the newly setup virtualenv.
338 # -but first find our paver executable..
339 paver =os.path.join(options.install.installdir,"bin","paver")
340 try:
341 os.stat(paver)
342 except (WindowsError,OSError):
343 paver = os.path.join(options.install.installdir,"scripts","paver")
344 subprocess.call([paver,"-f",os.path.join(here,"pavement.py"),"install_here" ])
347 setup(name ="MysteryMachine",
348 packages = DIST_PACKAGES ,
349 scripts = SCRIPTS ,
350 py_modules =PY_MODULES,
351 version = "0.1.4",
352 install_requires = EZ_PACKAGES,
353 url="http://trac.backslashat.org/MysteryMachine",
354 author="Roger Gammans",
355 author_email="rgammans@computer-surgery.co.uk",
356 license = "GPLv2",
357 entry_points={ 'console_scripts': [
358 "mysterymachine = MysteryMachine.Main:main",
359 "mmcli = MysteryMachine.Ui.cli:main",
360 "mmwx = MysteryMachine.Ui.wx:main"
361 ]},
362 package_data= paver.setuputils.find_package_data(".", package="paver",
363 only_in_packages=False),
364 )
366 options(
367 virtualenv = Bunch(
368 script_name = VENVSCRIPT,
369 packages_to_install = EZ_PACKAGES,
370 )
371 )