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

Revision 265, 12.9 kB (checked in by arjanmol, 4 years ago)

*** empty log message ***

  • 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 # vim:sw=4:et
6 """Gaphor
7 """
8
9 MAJOR_VERSION = 0
10 MINOR_VERSION = 3
11 MICRO_VERSION = 0
12
13 VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION )
14
15 GCONF_DOMAIN='/apps/gaphor/' # don't forget trailing slash
16
17 import sys, os
18 from glob import glob
19 from commands import getoutput, getstatus, getstatusoutput
20 from distutils.core import setup, Command
21 from distutils.command.build_py import build_py
22 from distutils.command.install_lib import install_lib
23 from distutils.dep_util import newer
24 from utils.build_mo import build, build_mo
25 from utils.build_pot import build_pot
26 from utils.install_mo import install, install_mo
27 from utils.dist_mo import Distribution
28
29 str_version = sys.version[:3]
30 version = map(int, str_version.split('.'))
31 if version < [2, 2]:
32     raise SystemExit, \
33         "Python 2.2 or higher is required, %s found" % str_version
34
35
36 class config_Gaphor(Command):
37     description="Configure Gaphor"
38
39     user_options = [
40         #('pkg-config=', None, 'Path to pkg-config'),
41     ]
42
43     #pkg_config_checked=False
44     config_failed=[]
45
46     def initialize_options(self):
47         #self.pkg_config = 'pkg-config'
48         pass
49
50     def finalize_options(self):
51         # Check for existence of pkg-config
52         #status, output = getstatusoutput('%s --version' % self.pkg_config)
53         #if status != 0:
54         #    print 'pkg-config not found.'
55         #    raise SystemExit
56         #print 'Found pkg-config version %s' % output
57         pass
58
59     def run(self):
60         import pygtk
61         pygtk.require('2.0')
62
63         #self.pkg_config_check('gobject-2.0', '2.0.0')
64         #self.pkg_config_check('gtk+-2.0', '2.0.0')
65         #self.pkg_config_check('pygtk-2.0', '1.99.15')
66         #self.pkg_config_check('gconf-2.0', '2.0.0')
67         #self.pkg_config_check('libbonobo-2.0', '2.0.0')
68         #self.pkg_config_check('libbonoboui-2.0', '2.0.0')
69         #self.pkg_config_check('diacanvas2', '0.9.1')
70
71         self.module_check('xml.parsers.expat')
72         #self.module_check('gobject', 'glib_version', (2, 0))
73         self.module_check('gtk', ('gtk_version', (2, 0)),
74                                  ('pygtk_version', (1, 99, 16)))
75         self.module_check('gnome')
76         self.module_check('gnome.canvas')
77         #self.module_check('gconf')
78         self.module_check('diacanvas', ('diacanvas_version', (0, 12, 0)))
79
80         print ''
81         if self.config_failed:
82             print 'Config failed.'
83             print 'The following modules can not be found or are to old:'
84             print ' ', str(self.config_failed)[1:-1]
85             print ''
86             raise SystemExit
87         else:
88             print 'Config succeeded.'
89             print 'You can run Gaphor by typing: python setup.py run'
90
91     def pkg_config_check(self, package, version):
92         """Check for availability of a package via pkg-config."""
93         retval = os.system('%s --exists %s' % (self.pkg_config, package))
94         if retval:
95             print '!!! Required package %s not found.' % package
96             self.config_failed.append(package)
97             return
98         pkg_version_str = getoutput('%s --modversion %s' % (self.pkg_config, package))
99         pkg_version = map(int, pkg_version_str.split('.'))
100         req_version = map(int, version.split('.'))
101         if pkg_version >= req_version:
102             print "Found '%s', version %s." % (package, pkg_version_str)
103         else:
104             print "!!! Package '%s' has version %s, should have at least version %s." % ( package, pkg_version_str, version )
105             self.config_failed.append(package)
106
107     def module_check(self, module, *version_checks):
108         """Check for the availability of a module.
109
110         version_checks is a set of ket/version pairs that should be true.
111         """
112         import string
113         try:
114             mod = __import__(module)
115         except ImportError:
116             print "!!! Required module '%s' not found." % module
117             self.config_failed.append(module)
118         else:
119             print "Module '%s' found." % module
120             for key, ver in version_checks:
121                 s_ver = string.join(map(str, ver), '.')
122                 print "  Checking key '%s.%s' >= %s..." % (module, key, s_ver),
123                 try:
124                     modver = getattr(mod, key)
125                 except:
126                     print "Not found." % key
127                     self.config_failed.append(module)
128                 else:
129                     s_modver = string.join(map(str, modver), '.')
130                     if modver >= ver:
131                         print "Okay (%s)." % s_modver
132                     else:
133                         print "Failed (%s)" % s_modver
134                         self.config_failed.append(module)
135
136
137 class version_py:
138
139     def generate_version(self, dir, data_dir):
140         """Create a file gaphor/version.py which contains the current version.
141         """
142         outfile = os.path.join(dir, 'gaphor', 'version.py')
143         print 'generating %s' % outfile
144         self.mkpath(os.path.dirname(outfile))
145         f = open(outfile, 'w')
146         f.write('VERSION=\'%s\'\n' % VERSION)
147         f.write('DATA_DIR=\'%s\'\n' % data_dir)
148         f.close()
149         self.byte_compile([outfile])
150
151
152 class build_py_Gaphor(build_py, version_py):
153
154     description = "build_py and generate gaphor/UML/uml2.py."
155
156     def run(self):
157         build_py.run(self)
158         sys.path.insert(0, self.build_lib)
159         # All data is stored in the local data directory
160         data_dir = os.path.join(os.getcwd(), 'data')
161         self.generate_version(self.build_lib, data_dir)
162         self.generate_uml2()
163
164     def generate_uml2(self):
165         """Generate gaphor/UML/uml2.py in the build directory."""
166         import utils.genUML2
167         gen = 'utils/genUML2.py'
168         overrides = 'gaphor/UML/uml2.override'
169         model = 'gaphor/UML/uml2.gaphor'
170         py_model = 'gaphor/UML/uml2.py'
171         outfile = os.path.join(self.build_lib, py_model)
172         self.mkpath(os.path.dirname(outfile))
173         if self.force or newer(model, outfile) \
174                       or newer(overrides, outfile) \
175                       or newer(gen, outfile):
176             print 'generating %s from %s...' % (py_model, model)
177             utils.genUML2.generate(model, outfile, overrides)
178         else:
179             print 'not generating %s (up-to-date)' % py_model
180         self.byte_compile([outfile])
181
182
183 class install_lib_Gaphor(install_lib, version_py):
184
185     def initialize_options(self):
186         install_lib.initialize_options(self)
187         self.install_data= None
188
189     def finalize_options(self):
190         install_lib.finalize_options(self)
191         self.set_undefined_options('install_data',
192                                    ('install_dir', 'install_data'))
193
194     def run(self):
195         install_lib.run(self)
196         # Install a new version.py with install_data as data_dir:
197         self.generate_version(self.install_dir, self.install_data)
198
199
200 class install_schemas(Command):
201     """Do something like this:
202
203         GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
204             gconftool --makefile-install-rule data/gaphor.schemas
205
206     in a pythonic way.
207     """
208
209     description = "Install a configuration (using GConf)."
210
211     user_options = [
212         ('install-data=', None, 'installation directory for data files'),
213         ('gconftool', None, 'The gconftool to use for installation'),
214         ('gconf-config-source', None, 'Overrule the GConf config source'),
215         ('force', 'f', 'force installation (overwrite existing keys)')
216     ]
217
218     boolean_options = ['force']
219
220     def initialize_options(self):
221         self.install_data = None
222         self.gconftool = 'gconftool-2'
223         self.gconf_config_source = ''
224         self.force = None
225         self.schemas_file = 'data/gaphor.schemas'
226
227     def finalize_options(self):
228         self.set_undefined_options('install',
229                                    ('force', 'force'),
230                                    ('install_data', 'install_data'))
231
232     def run(self):
233         getstatus('GCONF_CONFIG_SOURCE="%s" %s --makefile-install-rule %s' % (self.gconf_config_source, self.gconftool, self.schemas_file))
234
235         self._set_value('/schemas/apps/gaphor/data_dir', self.install_data, 'string')
236
237     def _set_value(self, key, value, type):
238         print "setting gconf value '%s' to '%s'" % (key, value)
239         #apply(getattr(self.gconf_client, 'set_' + type),
240         #      (GCONF_DOMAIN + key, value))
241         getstatus('%s --type=%s --set %s %s' % (self.gconftool, type, key, value))
242
243 #install.sub_commands.append(('install_schemas', None))
244
245
246 class run_Gaphor(Command):
247
248     description = 'Launch Gaphor from the local directory'
249
250     user_options = [
251         ('build-dir=', None, ''),
252         ('command=', 'c', 'execute command'),
253         ('file=', 'f', 'execute file'),
254         ('testfile=', 't', 'execute unittest file'),
255     ]
256
257     def initialize_options(self):
258         self.build_lib = None
259         self.command = None
260         self.file = None
261         self.testfile = None
262         self.verbosity = 2
263
264     def finalize_options(self):
265         self.set_undefined_options('build',
266                                    ('build_lib', 'build_lib'))
267
268     def run(self):
269         print 'Starting gaphor...'
270         self.run_command('build')
271
272         import os.path
273         import gaphor
274         #os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
275         if self.command:
276             print 'Executing command: %s...' % self.command
277             exec self.command
278         elif self.testfile:
279             # Running a unit test is done by opening the unit test file
280             # as a module and running the tests within that module.
281             print 'Running test cases in unittest file: %s...' % self.testfile
282             import imp, unittest
283             fp = open(self.testfile)
284             test_module = imp.load_source('gaphor_test', self.testfile, fp)
285             test_suite = unittest.TestLoader().loadTestsFromModule(test_module)
286             test_runner = unittest.TextTestRunner(verbosity=self.verbosity)
287             result = test_runner.run(test_suite)
288             sys.exit(not result.wasSuccessful())
289         elif self.file:
290             print 'Executing file: %s...' % self.file
291             execfile(self.file, {})
292         else:
293             print 'Launching Gaphor...'
294             gaphor.main()
295
296 try:
297     from dsextras import TemplateExtension, BuildExt, GLOBAL_INC
298 except ImportError:
299     import pygtk
300     pygtk.require('2.0')
301     from gtk.dsextras import TemplateExtension, BuildExt, GLOBAL_INC
302
303 pygtkincludedir = getoutput('pkg-config --variable pygtkincludedir pygtk-2.0')
304 codegendir = getoutput('pkg-config --variable codegendir pygtk-2.0')
305 defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0')
306
307 sys.path.append(codegendir)
308
309 GLOBAL_INC.append(pygtkincludedir)
310 GLOBAL_INC.append('.')
311 GTKDEFS = [os.path.join(defsdir, 'gtk-types.defs')]
312
313 ext_modules = []
314 gtkwrapbox = TemplateExtension(name='wrapbox',
315                                pkc_name='gtk+-2.0',
316                                pkc_version='2.0.0',
317                                output='gaphor.misc.wrapbox',
318                                defs='src/wrapbox.defs',
319                                sources=['src/gtkwrapbox.c',
320                                         'src/gtkhwrapbox.c',
321                                         'src/gtkvwrapbox.c',
322                                         'src/wrapbox.c',
323                                         'src/wrapboxmodule.c'],
324                                register=GTKDEFS,
325                                override='src/wrapbox.override')
326
327 if gtkwrapbox.can_build():
328     ext_modules.append(gtkwrapbox)
329 else:
330     pass
331
332 setup(name='gaphor',
333       version=VERSION,
334       description="Gaphor is a UML modeling tool",
335       url='http://gaphor.sourceforge.net',
336       author='Arjan J. Molenaar',
337       author_email='arjanmol@users.sourceforge.net',
338       license="GNU General Public License (GPL, see COPYING)",
339       long_description="Gaphor is a UML modeling tool written in Python. "
340       "It uses the GNOME2 environment for user interaction.",
341       platforms=['GNOME2'],
342       all_linguas=['nl'],
343       packages=['gaphor',
344                 'gaphor.UML',
345                 'gaphor.diagram',
346                 'gaphor.ui',
347                 'gaphor.misc'
348       ],
349       ext_modules=ext_modules,
350       # data files are relative to <prefix>/share/gaphor (see setup.cfg)
351       data_files=[('', ['data/gaphor-main-ui.xml',
352                         'data/gaphor-diagram-ui.xml',
353                         'data/gaphor-editor-ui.xml',
354                         'data/gaphor.dtd']),
355                   ('pixmaps', glob('data/pixmaps/*.png'))
356       ],
357       scripts=['bin/gaphor'],
358
359       distclass=Distribution,
360       cmdclass={'config': config_Gaphor,
361                 'build_py': build_py_Gaphor,
362                 #'install_schemas': install_schemas,
363                 'build': build,
364                 'build_ext': BuildExt,
365                 'build_mo': build_mo,
366                 'build_pot': build_pot,
367                 'install': install,
368                 'install_lib': install_lib_Gaphor,
369                 'install_mo': install_mo,
370                 'run': run_Gaphor
371       }
372 )
373
Note: See TracBrowser for help on using the browser.