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
13 from dsextras
import get_m4_define
, getoutput
, have_pkgconfig
, \
14 GLOBAL_INC
, GLOBAL_MACROS
, InstallLib
, InstallData
, BuildExt
, \
17 if '--yes-i-know-its-not-supported' in sys
.argv
:
18 sys
.argv
.remove('--yes-i-know-its-not-supported')
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"
26 print "Build fixes are of course welcome and should be filed in bugzilla"
28 input = raw_input('Not supported, ok [y/N]? ')
29 if not input.startswith('y'):
32 if sys
.version_info
[:3] < (2, 3, 5):
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
))
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
):
64 # Install pygtk.pth, pygtk.py[c] and templates
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
)
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
):
92 self
.add_template_option('VERSION', VERSION
)
93 self
.add_template_option('FFI_LIBS', '')
97 self
.install_templates()
101 def install_templates(self
):
102 self
.install_template('pygobject-2.0.pc.in',
103 os
.path
.join(self
.install_dir
,
105 self
.install_template('docs/xsl/fixxref.py.in',
106 os
.path
.join(self
.install_dir
, XSL_DIR
))
108 class PyGObjectBuild(build
):
110 PyGObjectBuild
.user_options
.append(('enable-threading', None,
111 'enable threading support'))
114 gobject
= PkgConfigExtension(name
='gobject._gobject', pkc_name
='gobject-2.0',
115 pkc_version
=GOBJECT_REQUIRED
,
117 sources
=['gobject/gobjectmodule.c',
118 'gobject/pygboxed.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',
129 'gobject/pygsource.c',
130 'gobject/pygiochannel.c',
136 py_modules
.append('dsextras')
138 if not have_pkgconfig():
139 print "Error, could not find pkg-config"
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')))
151 print 'ERROR: Nothing to do, gobject could not be found and is essential.'
155 if '--disable-threading' in sys
.argv
:
156 sys
.argv
.remove('--disable-threading')
157 enable_threading
= False
159 if '--enable-threading' in sys
.argv
:
160 sys
.argv
.remove('--enable-threading')
164 print "Warning: Could not import thread module, disabling threading"
165 enable_threading
= False
167 enable_threading
= True
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:])
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:])
183 module
.extra_compile_args
.append(arg
)
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/',
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"],
206 cmdclass
={'install_lib': PyGObjectInstallLib
,
207 'install_data': PyGObjectInstallData
,
208 'build_ext': BuildExt
,
209 'build': PyGObjectBuild
})