root/gaphor/tags/gaphor-0.9.1/setup.py

Revision 1127, 16.7 kB (checked in by arjanmol, 2 years ago)

Version updated to 0.9.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env python
2 #
3 # setup.py for Gaphor
4 #
5 """
6 Gaphor
7 """
8
9 MAJOR_VERSION = 0
10 MINOR_VERSION = 9
11 MICRO_VERSION = 1
12
13 VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION )
14
15 LINGUAS = [ 'ca', 'es', 'nl', 'sv' ]
16
17 TESTS = [
18     'gaphor.actions.tests.test_itemactions',
19     'gaphor.actions.tests.test_placementactions',
20     'gaphor.adapters.tests.test_connector',
21     'gaphor.adapters.tests.test_editor',
22     'gaphor.diagram.tests.test_diagramitem',
23     'gaphor.diagram.tests.test_class',
24     'gaphor.diagram.tests.test_action',
25     'gaphor.diagram.tests.test_handletool',
26     'gaphor.diagram.tests.test_interfaces',
27     'gaphor.diagram.tests.test_style',
28     'gaphor.ui.tests.test_diagramtab',
29     'gaphor.ui.tests.test_mainwindow',
30     'gaphor.UML.tests.test_elementfactory',
31     ]
32
33 #GCONF_DOMAIN='/apps/gaphor/' # don't forget trailing slash
34
35 import sys, os
36 from glob import glob
37 from commands import getoutput, getstatus, getstatusoutput
38
39 # Py2App should be imported before the utils classes are loaded
40 try:
41     import py2app
42 except ImportError:
43     print "No py2app, can't create application bundle"
44 else:
45     from modulegraph.modulegraph import AddPackagePath
46     AddPackagePath('gaphor', 'build/lib/gaphor')
47     AddPackagePath('gaphor.UML', 'build/lib/gaphor/UML')
48
49 from distutils.core import setup, Command
50 from distutils.command.build_py import build_py
51 from distutils.command.install_lib import install_lib
52 from distutils.dep_util import newer
53 from utils.build_mo import build, build_mo
54 from utils.build_pot import build_pot
55 from utils.install_mo import install, install_mo
56
57 str_version = sys.version[:3]
58 version = map(int, str_version.split('.'))
59 if version < [2, 4]:
60     raise SystemExit, \
61         "Python 2.4 or higher is required, %s found" % str_version
62
63
64 class config_Gaphor(Command):
65     description="Configure Gaphor"
66
67     user_options = [
68         #('pkg-config=', None, 'Path to pkg-config'),
69     ]
70
71     #pkg_config_checked=False
72     config_failed=[]
73
74     def initialize_options(self):
75         #self.pkg_config = 'pkg-config'
76         pass
77
78     def finalize_options(self):
79         # Check for existence of pkg-config
80         #status, output = getstatusoutput('%s --version' % self.pkg_config)
81         #if status != 0:
82         #    print 'pkg-config not found.'
83         #    raise SystemExit
84         #print 'Found pkg-config version %s' % output
85         pass
86
87     def run(self):
88         self.module_check('pygtk')
89         import pygtk
90         pygtk.require('2.0')
91
92         self.module_check('xml.parsers.expat')
93         self.module_check('gtk', ('gtk_version', (2, 8)),
94                                  ('pygtk_version', (2, 8)))
95
96         print ''
97         if self.config_failed:
98             print 'Config failed.'
99             print 'The following modules can not be found or are to old:'
100             print ' ', str(self.config_failed)[1:-1]
101             print ''
102             raise SystemExit
103         else:
104             print 'Config succeeded.'
105
106     def pkg_config_check(self, package, version):
107         """Check for availability of a package via pkg-config."""
108         retval = os.system('%s --exists %s' % (self.pkg_config, package))
109         if retval:
110             print '!!! Required package %s not found.' % package
111             self.config_failed.append(package)
112             return
113         pkg_version_str = getoutput('%s --modversion %s' % (self.pkg_config, package))
114         pkg_version = map(int, pkg_version_str.split('.'))
115         req_version = map(int, version.split('.'))
116         if pkg_version >= req_version:
117             print "Found '%s', version %s." % (package, pkg_version_str)
118         else:
119             print "!!! Package '%s' has version %s, should have at least version %s." % ( package, pkg_version_str, version )
120             self.config_failed.append(package)
121
122     def module_check(self, module, *version_checks):
123         """Check for the availability of a module.
124
125         version_checks is a set of ket/version pairs that should be true.
126         """
127         import string
128         try:
129             mod = __import__(module)
130         except ImportError:
131             print "!!! Required module '%s' not found." % module
132             self.config_failed.append(module)
133         else:
134             print "Module '%s' found." % module
135             for key, ver in version_checks:
136                 s_ver = string.join(map(str, ver), '.')
137                 print "  Checking key '%s.%s' >= %s..." % (module, key, s_ver),
138                 try:
139                     modver = getattr(mod, key)
140                 except:
141                     print "Not found." % key
142                     self.config_failed.append(module)
143                 else:
144                     s_modver = string.join(map(str, modver), '.')
145                     if modver >= ver:
146                         print "Okay (%s)." % s_modver
147                     else:
148                         print "Failed (%s)" % s_modver
149                         self.config_failed.append(module)
150
151
152 class build_Gaphor(build):
153
154     def run(self):
155         self.run_command('config')
156         build.run(self)
157
158
159 class version_py:
160
161     def generate_version(self, dir, data_dir):
162         """Create a file gaphor/version.py which contains the current version.
163         """
164         outfile = os.path.join(dir, 'gaphor', 'version.py')
165         print 'generating %s' % outfile, dir, data_dir
166         self.mkpath(os.path.dirname(outfile))
167         f = open(outfile, 'w')
168         f.write('"""\nVersion information generated by setup.py. DO NOT EDIT.\n"""\n\n')
169         f.write('VERSION=\'%s\'\n' % VERSION)
170         # expand backspaces
171         f.write('DATA_DIR=\'%s\'\n' % data_dir.replace('\\', '\\\\'))
172         if os.name == 'nt':
173             home = 'USERPROFILE'
174         else:
175             home = 'HOME'
176         f.write('import os\n')
177         f.write('USER_DATA_DIR=os.path.join(os.getenv(\'%s\'), \'.gaphor\')\n' % home)
178         f.write('del os\n')
179         f.close()
180         self.byte_compile([outfile])
181
182
183 class build_py_Gaphor(build_py, version_py):
184
185     description = "build_py and generate gaphor/UML/uml2.py."
186
187     def run(self):
188         build_py.run(self)
189         sys.path.insert(0, self.build_lib)
190         # All data is stored in the local data directory
191         data_dir = os.path.join(os.getcwd(), 'data')
192         #data_dir = "os.path.join(os.getcwd(), 'data')"
193         self.generate_version(self.build_lib, data_dir)
194         self.generate_uml2()
195
196     def generate_uml2(self):
197         """Generate gaphor/UML/uml2.py in the build directory."""
198         import utils.genUML2
199         gen = os.path.join('utils', 'genUML2.py')
200         overrides = os.path.join('gaphor', 'UML', 'uml2.override')
201         model = os.path.join('gaphor', 'UML', 'uml2.gaphor')
202         py_model = os.path.join('gaphor', 'UML', 'uml2.py')
203         outfile = os.path.join(self.build_lib, py_model)
204         self.mkpath(os.path.dirname(outfile))
205         if self.force or newer(model, outfile) \
206                       or newer(overrides, outfile) \
207                       or newer(gen, outfile):
208             print 'generating %s from %s...' % (py_model, model)
209             print '  (warnings can be ignored)'
210             utils.genUML2.generate(model, outfile, overrides)
211         else:
212             print 'not generating %s (up-to-date)' % py_model
213         self.byte_compile([outfile])
214
215
216 class install_lib_Gaphor(install_lib, version_py):
217
218     def initialize_options(self):
219         install_lib.initialize_options(self)
220         self.install_data= None
221
222     def finalize_options(self):
223         install_lib.finalize_options(self)
224         self.set_undefined_options('install_data',
225                                    ('install_dir', 'install_data'))
226
227     def run(self):
228         # install a new version.py with install_data as data_dir;
229         # get rid of install root directory
230         print 'self', dir(self)
231         print 'self.get_finalized_command("install")', dir(self.get_finalized_command('install'))
232        
233         skip = len(self.get_finalized_command('install').root or '')
234
235         self.generate_version(self.install_dir, self.install_data[skip:])
236         install_lib.run(self)
237
238
239 class install_schemas(Command):
240     """Do something like this:
241
242         GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
243             gconftool --makefile-install-rule data/gaphor.schemas
244
245     in a pythonic way.
246     """
247
248     description = "Install a configuration (using GConf)."
249
250     user_options = [
251         ('install-data=', None, 'installation directory for data files'),
252         ('gconftool', None, 'The gconftool to use for installation'),
253         ('gconf-config-source', None, 'Overrule the GConf config source'),
254         ('force', 'f', 'force installation (overwrite existing keys)')
255     ]
256
257     boolean_options = ['force']
258
259     def initialize_options(self):
260         self.install_data = None
261         self.gconftool = 'gconftool-2'
262         self.gconf_config_source = ''
263         self.force = None
264         self.schemas_file = 'data/gaphor.schemas'
265
266     def finalize_options(self):
267         self.set_undefined_options('install',
268                                    ('force', 'force'),
269                                    ('install_data', 'install_data'))
270
271     def run(self):
272         getstatus('GCONF_CONFIG_SOURCE="%s" %s --makefile-install-rule %s' % (self.gconf_config_source, self.gconftool, self.schemas_file))
273
274         self._set_value('/schemas/apps/gaphor/data_dir', self.install_data, 'string')
275
276     def _set_value(self, key, value, type):
277         print "setting gconf value '%s' to '%s'" % (key, value)
278         #apply(getattr(self.gconf_client, 'set_' + type),
279         #      (GCONF_DOMAIN + key, value))
280         getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value))
281
282 #install.sub_commands.append(('install_schemas', None))
283
284
285 class run_Gaphor(Command):
286
287     description = 'Launch Gaphor from the local directory'
288
289     user_options = [
290         ('build-dir=', None, ''),
291         ('command=', 'c', 'execute command'),
292         ('file=', 'f', 'execute file'),
293         ('doctest=', 'd', 'execute doctests in module (e.g. gaphor.geometry)'),
294         ('unittest=', 'u', 'execute unittest file (e.g. tests/test-ns.py)'),
295         ('model=', 'm', 'load a model file'),
296         ('coverage', None, 'Calculate coverage (utils/coverage.py)'),
297     ]
298
299     def initialize_options(self):
300         self.build_lib = None
301         self.command = None
302         self.file = None
303         self.doctest = None
304         self.unittest = None
305         self.model = None
306         self.coverage = None
307         self.verbosity = 2
308
309     def finalize_options(self):
310         self.set_undefined_options('build',
311                                    ('build_lib', 'build_lib'))
312
313     def run(self):
314         print 'Starting Gaphor...'
315         print 'Starting with model file', self.model
316         self.run_command('build')
317
318         import os.path
319         import gaphor
320         #os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
321         if self.coverage:
322             from utils import coverage
323             coverage.start()
324
325         if self.command:
326             print 'Executing command: %s...' % self.command
327             exec self.command
328
329         elif self.doctest:
330             print 'Running doctest cases in module: %s...' % self.doctest
331             import imp
332             # use zope's one since it handles coverage right
333             from zope.testing import doctest
334
335             # Figure out the file:
336             f = os.path.join(*self.doctest.split('.')) + '.py'
337             fp = open(f)
338             # Prepend module's package path to sys.path
339             pkg = os.path.join(self.build_lib, *self.doctest.split('.')[:-1])
340             if pkg:
341                 sys.path.insert(0, pkg)
342                 print 'Added', pkg, 'to sys.path'
343             # Load the module as local module (without package)
344             test_module = imp.load_source(self.doctest.split('.')[-1], f, fp)
345             failure, tests = doctest.testmod(test_module, name=self.doctest,
346                  optionflags=doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE)
347             if self.coverage:
348                 print
349                 print 'Coverage report:'
350                 coverage.report(f)
351             sys.exit(failure != 0)
352
353         elif self.unittest:
354             # Running a unit test is done by opening the unit test file
355             # as a module and running the tests within that module.
356             print 'Running test cases in unittest file: %s...' % self.unittest
357             import imp, unittest
358             fp = open(self.unittest)
359             test_module = imp.load_source('gaphor_test', self.unittest, fp)
360             test_suite = unittest.TestLoader().loadTestsFromModule(test_module)
361             #test_suite = unittest.TestLoader().loadTestsFromName(self.unittest)
362             test_runner = unittest.TextTestRunner(verbosity=self.verbosity)
363             result = test_runner.run(test_suite)
364             if self.coverage:
365                 print
366                 print 'Coverage report:'
367                 coverage.report(self.unittest)
368             sys.exit(not result.wasSuccessful())
369
370         elif self.file:
371             print 'Executing file: %s...' % self.file
372             dir, f = os.path.split(self.file)
373             print 'Extending PYTHONPATH with %s' % dir
374             sys.path.append(dir)
375             execfile(self.file, {})
376         else:
377             print 'Launching Gaphor...'
378             gaphor.main(self.model)
379
380 class tests_Gaphor(Command):
381
382     description = 'Run the Gaphor test suite.'
383
384     user_options = [
385     ]
386
387     def initialize_options(self):
388         self.verbosity = 9
389
390     def finalize_options(self):
391         pass
392
393     def run(self):
394         print 'Starting Gaphor test-suite...'
395
396         self.run_command('build')
397
398         import unittest
399
400         test_suite = unittest.defaultTestLoader.loadTestsFromNames(TESTS)
401
402         test_runner = unittest.TextTestRunner(verbosity=self.verbosity)
403         result = test_runner.run(test_suite)
404         sys.exit(not result.wasSuccessful())
405
406 def plugin_data(name):
407     return 'plugins/%s' % name, glob('data/plugins/%s/*.*' % name)
408
409
410 setup(name='gaphor',
411       version=VERSION,
412       description="Gaphor is a UML modeling tool",
413       url='http://gaphor.sourceforge.net',
414       author='Arjan J. Molenaar',
415       author_email='arjanmol@users.sourceforge.net',
416       license="GNU General Public License (GPL, see COPYING)",
417       long_description="Gaphor is a UML modeling tool written in Python. "
418       "It uses the GNOME2 environment for user interaction.",
419       platforms=['GNOME2'],
420       packages=['gaphor',
421                 'gaphor.UML',
422                 'gaphor.UML.tests',
423                 'gaphor.diagram',
424                 'gaphor.diagram.tests',
425                 'gaphor.ui',
426                 'gaphor.ui.tests',
427                 'gaphor.misc',
428                 'gaphor.adapters',
429                 'gaphor.adapters.tests',
430                 'gaphor.actions',
431                 'gaphor.actions.tests',
432                 'gaphas',
433                 'zope',
434                 'zope.interface',
435                 'zope.component.bbb',
436                 'zope.component.bbb.tests',
437                 'zope.interface.common',
438                 'zope.component',
439                 'zope.exceptions',
440                 'zope.deprecation',
441                 'zope.testing',
442                
443       ],
444 #      ext_modules=ext_modules,
445       # data files are relative to <prefix>/share/gaphor (see setup.cfg)
446       data_files=[('', ['data/icons.xml']),
447                   ('pixmaps', glob('data/pixmaps/*.png')),
448                   plugin_data('plugineditor'),
449                   plugin_data('alignment'),
450                   plugin_data('checkmetamodel'),
451                   plugin_data('diagramlayout'),
452                   plugin_data('liveobjectbrowser'),
453                   plugin_data('pngexport'),
454                   plugin_data('pynsource'),
455                   plugin_data('svgexport'),
456                   plugin_data('pdfexport'),
457                   plugin_data('xmiexport')
458       ],
459       scripts=['bin/gaphor', 'bin/gaphorconvert'],
460
461 #      distclass=Distribution,
462       cmdclass={'config': config_Gaphor,
463                 'build_py': build_py_Gaphor,
464                 #'install_schemas': install_schemas,
465                 'build': build_Gaphor,
466 #                'build_ext': BuildExt,
467                 'build_mo': build_mo,
468                 'build_pot': build_pot,
469                 'install': install,
470                 'install_lib': install_lib_Gaphor,
471                 'install_mo': install_mo,
472                 'run': run_Gaphor,
473                 'tests': tests_Gaphor
474       },
475 #      app=['gaphor-osx.py'],
476       options = dict(
477          py2app = dict(
478              includes=['atk', 'pango', 'cairo', 'pangocairo'],
479 #             CFBundleDisplayName='Gaphor',
480 #             CFBundleIdentifier='net.sourceforge.gaphor'
481          ),
482          build_pot = dict(
483              all_linguas = ','.join(LINGUAS),
484          ),
485          build_mo = dict(
486              all_linguas = ','.join(LINGUAS),
487          ),
488          install_mo = dict(
489              all_linguas = ','.join(LINGUAS),
490          ),
491      )
492 )
493
494 # vim:sw=4:et
Note: See TracBrowser for help on using the browser.