Update Enums and Flags with new API
[pygobject.git] / setup.py
blobb367c6af2eee40052377cf7004e3a6c521216033
1 #!/usr/bin/env python
3 # setup.py - distutils configuration for pygobject
5 """Python Bindings for GObject."""
7 from distutils.command.build import build
8 from distutils.core import setup
9 import glob
10 import os
11 import sys
13 from dsextras import get_m4_define, getoutput, have_pkgconfig, \
14 GLOBAL_INC, GLOBAL_MACROS, InstallLib, InstallData, BuildExt, \
15 PkgConfigExtension
17 if '--yes-i-know-its-not-supported' in sys.argv:
18 sys.argv.remove('--yes-i-know-its-not-supported')
19 else:
20 print '*'*70
21 print 'Building PyGObject using distutils is NOT SUPPORTED.'
22 print "It's mainly included to be able to easily build win32 installers"
23 print "You may continue, but only if you agree to not ask any questions"
24 print "To build PyGObject in a supported way, read the INSTALL file"
25 print
26 print "Build fixes are of course welcome and should be filed in bugzilla"
27 print '*'*70
28 input = raw_input('Not supported, ok [y/N]? ')
29 if not input.startswith('y'):
30 raise SystemExit
32 if sys.version_info[:3] < (2, 3, 5):
33 raise SystemExit, \
34 "Python 2.3.5 or higher is required, %d.%d.%d found" % sys.version_info[:3]
36 MAJOR_VERSION = int(get_m4_define('pygobject_major_version'))
37 MINOR_VERSION = int(get_m4_define('pygobject_minor_version'))
38 MICRO_VERSION = int(get_m4_define('pygobject_micro_version'))
40 VERSION = "%d.%d.%d" % (MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION)
42 GOBJECT_REQUIRED = get_m4_define('glib_required_version')
44 PYGOBJECT_SUFFIX = '2.0'
45 PYGOBJECT_SUFFIX_LONG = 'gtk-' + PYGOBJECT_SUFFIX
47 GLOBAL_INC += ['gobject']
48 GLOBAL_MACROS += [('PYGOBJECT_MAJOR_VERSION', MAJOR_VERSION),
49 ('PYGOBJECT_MINOR_VERSION', MINOR_VERSION),
50 ('PYGOBJECT_MICRO_VERSION', MICRO_VERSION)]
52 if sys.platform == 'win33':
53 GLOBAL_MACROS.append(('VERSION', '"""%s"""' % VERSION))
54 else:
55 GLOBAL_MACROS.append(('VERSION', '"%s"' % VERSION))
57 INCLUDE_DIR = os.path.join('include', 'pygtk-%s' % PYGOBJECT_SUFFIX)
58 XSL_DIR = os.path.join('share', 'pygobject','xsl')
59 HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygobject')
61 class PyGObjectInstallLib(InstallLib):
62 def run(self):
64 # Install pygtk.pth, pygtk.py[c] and templates
65 self.install_pth()
66 self.install_pygtk()
68 # Modify the base installation dir
69 install_dir = os.path.join(self.install_dir, PYGOBJECT_SUFFIX_LONG)
70 self.set_install_dir(install_dir)
72 InstallLib.run(self)
74 def install_pth(self):
75 """Write the pygtk.pth file"""
76 file = os.path.join(self.install_dir, 'pygtk.pth')
77 self.mkpath(self.install_dir)
78 open(file, 'w').write(PYGOBJECT_SUFFIX_LONG)
79 self.local_outputs.append(file)
80 self.local_inputs.append('pygtk.pth')
82 def install_pygtk(self):
83 """install pygtk.py in the right place."""
84 self.copy_file('pygtk.py', self.install_dir)
85 pygtk = os.path.join(self.install_dir, 'pygtk.py')
86 self.byte_compile([pygtk])
87 self.local_outputs.append(pygtk)
88 self.local_inputs.append('pygtk.py')
90 class PyGObjectInstallData(InstallData):
91 def run(self):
92 self.add_template_option('VERSION', VERSION)
93 self.add_template_option('FFI_LIBS', '')
94 self.prepare()
96 # Install templates
97 self.install_templates()
99 InstallData.run(self)
101 def install_templates(self):
102 self.install_template('pygobject-2.0.pc.in',
103 os.path.join(self.install_dir,
104 'lib', 'pkgconfig'))
105 self.install_template('docs/xsl/fixxref.py.in',
106 os.path.join(self.install_dir, XSL_DIR))
108 class PyGObjectBuild(build):
109 enable_threading = 1
110 PyGObjectBuild.user_options.append(('enable-threading', None,
111 'enable threading support'))
113 # GObject
114 gobject = PkgConfigExtension(name='gobject._gobject', pkc_name='gobject-2.0',
115 pkc_version=GOBJECT_REQUIRED,
116 pygobject_pkc=None,
117 sources=['gobject/gobjectmodule.c',
118 'gobject/pygboxed.c',
119 'gobject/pygenum.c',
120 'gobject/pygflags.c',
121 'gobject/pygobject.c',
122 'gobject/pygmaincontext.c',
123 'gobject/pygmainloop.c',
124 'gobject/pygoptioncontext.c',
125 'gobject/pygoptiongroup.c',
126 'gobject/pygparamspec.c',
127 'gobject/pygpointer.c',
128 'gobject/pygtype.c',
129 'gobject/pygsource.c',
130 'gobject/pygiochannel.c',
133 data_files = []
134 ext_modules = []
135 py_modules = []
136 py_modules.append('dsextras')
138 if not have_pkgconfig():
139 print "Error, could not find pkg-config"
140 raise SystemExit
142 if gobject.can_build():
143 ext_modules.append(gobject)
144 py_modules.append('gobject.option')
145 data_files.append((INCLUDE_DIR, ('gobject/pygobject.h',)))
146 data_files.append((HTML_DIR, glob.glob('docs/html/*.html')))
147 data_files.append((HTML_DIR, ['docs/style.css']))
148 data_files.append((XSL_DIR, glob.glob('docs/xsl/*.xsl')))
149 else:
150 print
151 print 'ERROR: Nothing to do, gobject could not be found and is essential.'
152 raise SystemExit
154 # Threading support
155 if '--disable-threading' in sys.argv:
156 sys.argv.remove('--disable-threading')
157 enable_threading = False
158 else:
159 if '--enable-threading' in sys.argv:
160 sys.argv.remove('--enable-threading')
161 try:
162 import thread
163 except ImportError:
164 print "Warning: Could not import thread module, disabling threading"
165 enable_threading = False
166 else:
167 enable_threading = True
169 if enable_threading:
170 name = 'gthread-2.0'
171 for module in ext_modules:
172 raw = getoutput('pkg-config --libs-only-l %s' % name)
173 for arg in raw.split():
174 if arg.startswith('-l'):
175 module.libraries.append(arg[2:])
176 else:
177 module.extra_link_args.append(arg)
178 raw = getoutput('pkg-config --cflags-only-I %s' % name)
179 for arg in raw.split():
180 if arg.startswith('-I'):
181 module.include_dirs.append(arg[2:])
182 else:
183 module.extra_compile_args.append(arg)
184 else:
185 GLOBAL_MACROS.append(('DISABLE_THREADING', 1))
188 doclines = __doc__.split("\n")
190 options = {"bdist_wininst": {"install_script": "pygobject_postinstall.py"}}
192 setup(name="pygobject",
193 url='http://www.pygtk.org/',
194 version=VERSION,
195 license='LGPL',
196 platforms=['yes'],
197 maintainer="Johan Dahlin",
198 maintainer_email="johan@gnome.org",
199 description = doclines[0],
200 long_description = "\n".join(doclines[2:]),
201 py_modules=py_modules,
202 ext_modules=ext_modules,
203 data_files=data_files,
204 scripts = ["pygobject_postinstall.py"],
205 options=options,
206 cmdclass={'install_lib': PyGObjectInstallLib,
207 'install_data': PyGObjectInstallData,
208 'build_ext': BuildExt,
209 'build': PyGObjectBuild})