summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <zilch@src.gnome.org>2003-01-21 02:15:30 +0000
committerJohan Dahlin <zilch@src.gnome.org>2003-01-21 02:15:30 +0000
commit29b58e79cb8252536cb0b22855ab2f1c9de73e87 (patch)
tree376d4f91df0fc7218a809263f2de01bccaacbcd1
parent9fa90b15fdbc1d8a527c59f12f77e7bf68eb1859 (diff)
downloadpygtk-29b58e79cb8252536cb0b22855ab2f1c9de73e87.tar.gz
Splitted out from setup.py. It should be reusable for gnome-python and
* dsextras.py: Splitted out from setup.py. It should be reusable for gnome-python and other extensions that uses pygtk. Fixes #103615
-rw-r--r--ChangeLog4
-rw-r--r--dsextras.py213
-rwxr-xr-xsetup.py269
3 files changed, 258 insertions, 228 deletions
diff --git a/ChangeLog b/ChangeLog
index 136fdf17..79cf875f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2003-01-21 Johan Dahlin <jdahlin@async.com.br>
+ * dsextras.py: Splitted out from setup.py. It should be reusable
+ for gnome-python and other extensions that uses pygtk.
+ Fixes #103615
+
* gtk/gtk.override (quit_handler_marshal): Added to here, was
generated before. This version handle threads better. Patch from
John Finlay, Fixes #103851.
diff --git a/dsextras.py b/dsextras.py
new file mode 100644
index 00000000..9e7e9a2c
--- /dev/null
+++ b/dsextras.py
@@ -0,0 +1,213 @@
+from commands import getoutput, getstatusoutput
+from distutils.command.build_ext import build_ext
+from distutils.command.install_lib import install_lib
+from distutils.extension import Extension
+import fnmatch
+import os
+import string
+import sys
+
+from codegen.override import Overrides
+from codegen.defsparser import DefsParser
+from codegen.codegen import register_types, write_source, FileOutput
+
+GLOBAL_INC = []
+GLOBAL_MACROS = []
+
+class InstallLib(install_lib):
+ local_outputs = []
+ local_inputs = []
+ template_options = {}
+ def prepare(self):
+ self.prefix = os.sep.join(self.install_dir.split(os.sep)[:-4])
+ self.exec_prefix = os.path.join(self.prefix, 'bin')
+ self.includedir = os.path.join(self.prefix, 'include')
+ self.libdir = os.path.join(self.prefix, 'lib')
+ self.datadir = os.path.join(self.prefix, 'share')
+
+ self.add_template_option('prefix', self.prefix)
+ self.add_template_option('exec_prefix', self.exec_prefix)
+ self.add_template_option('includedir', self.includedir)
+ self.add_template_option('libdir', self.libdir)
+ self.add_template_option('datadir', self.datadir)
+ self.add_template_option('PYTHON', sys.executable)
+
+ def set_install_dir(self, install_dir):
+ self.install_dir = install_dir
+
+ def add_template_option(self, name, value):
+ self.template_options['@%s@'] = value
+
+ def install_template(self, filename, install_dir):
+ """Install template filename into target directory install_dir."""
+ output_file = os.path.split(filename)[-1][:-3]
+
+ template = open(filename).read()
+ for key, value in self.template_options.items():
+ template = template.replace(key, value)
+
+ output = os.path.join(install_dir, output_file)
+ self.mkpath(install_dir)
+ open(output, 'w').write(template)
+ self.local_inputs.append(filename)
+ self.local_outputs.append(output)
+ return output
+
+ def get_outputs(self):
+ return install_lib.get_outputs(self) + self.local_outputs
+
+ def get_inputs(self):
+ return install_lib.get_inputs(self) + self.local_inputs
+
+class PkgConfigExtension(Extension):
+ can_build_ok = None
+ def __init__(self, **kwargs):
+ name = kwargs['pkc_name']
+ kwargs['include_dirs'] = self.get_include_dirs(name) + GLOBAL_INC
+ kwargs['define_macros'] = GLOBAL_MACROS
+ kwargs['libraries'] = self.get_libraries(name)
+ kwargs['library_dirs'] = self.get_library_dirs(name)
+ self.pkc_name = kwargs['pkc_name']
+ self.pkc_version = kwargs['pkc_version']
+ del kwargs['pkc_name'], kwargs['pkc_version']
+ Extension.__init__(self, **kwargs)
+
+ def get_include_dirs(self, name):
+ output = getoutput('pkg-config --cflags-only-I %s' % name)
+ return output.replace('-I', '').split()
+
+ def get_libraries(self, name):
+ output = getoutput('pkg-config --libs-only-l %s' % name)
+ return output.replace('-l', '').split()
+
+ def get_library_dirs(self, name):
+ output = getoutput('pkg-config --libs-only-L %s' % name)
+ return output.replace('-L', '').split()
+
+ def can_build(self):
+ """If the pkg-config version found is good enough"""
+ if self.can_build_ok != None:
+ return self.can_build_ok
+
+ retval = os.system('pkg-config --exists %s' % self.pkc_name)
+ if retval:
+ print "* Could not find %s." % self.pkc_name
+ self.can_build_ok = 0
+ return 0
+
+ orig_version = getoutput('pkg-config --modversion %s' % self.pkc_name)
+ version = map(int, orig_version.split('.'))
+ pkc_version = map(int, self.pkc_version.split('.'))
+
+ if version >= pkc_version:
+ self.can_build_ok = 1
+ return 1
+ else:
+ print "Warning: Too old version of %s" % self.pkc_name
+ print " Need %s, but %s is installed" % \
+ (self.pkc_version, orig_version)
+ self.can_build_ok = 0
+ return 0
+
+ def generate(self):
+ pass
+
+class Template:
+ def __init__(self, override, output, defs, prefix, register=[]):
+ self.override = override
+ self.defs = defs
+ self.register = register
+ self.output = output
+ self.prefix = prefix
+
+ def check_dates(self):
+ if not os.path.exists(self.output):
+ return 0
+
+ files = self.register[:]
+ files.append(self.override)
+# files.append('setup.py')
+ files.append(self.defs)
+
+ newest = 0
+ for file in files:
+ test = os.stat(file)[8]
+ if test > newest:
+ newest = test
+
+ if newest < os.stat(self.output)[8]:
+ return 1
+ return 0
+
+ def generate(self):
+ if self.check_dates():
+ return
+
+ for item in self.register:
+ dp = DefsParser(item)
+ dp.startParsing()
+ register_types(dp)
+
+ dp = DefsParser(self.defs)
+ dp.startParsing()
+ register_types(dp)
+
+ fd = open(self.output, 'w')
+ write_source(dp,
+ Overrides(self.override),
+ self.prefix,
+ FileOutput(fd, self.output))
+ fd.close()
+
+class TemplateExtension(PkgConfigExtension):
+ def __init__(self, **kwargs):
+ name = kwargs['name']
+ defs = kwargs['defs']
+ output = defs[:-5] + '.c'
+ override = kwargs['override']
+ self.templates = []
+ self.templates.append(Template(override, output, defs, 'py' + name,
+ kwargs['register']))
+
+ del kwargs['register'], kwargs['override'], kwargs['defs']
+
+ if kwargs.has_key('output'):
+ kwargs['name'] = kwargs['output']
+ del kwargs['output']
+
+ PkgConfigExtension.__init__(self, **kwargs)
+
+ def generate(self):
+ map(lambda x: x.generate(), self.templates)
+
+class BuildExt(build_ext):
+ def build_extension(self, ext):
+ # Generate eventual templates before building
+ if hasattr(ext, 'generate'):
+ ext.generate()
+ build_ext.build_extension(self, ext)
+
+def list_files(dir):
+ """List all files in a dir, with filename match support:
+ for example: glade/*.glade will return all files in the glade directory
+ that matches *.glade. It also looks up the full path"""
+ if dir.find(os.sep) != -1:
+ parts = dir.split(os.sep)
+ dir = string.join(parts[:-1], os.sep)
+ pattern = parts[-1]
+ else:
+ pattern = dir
+ dir = '.'
+
+ dir = os.path.abspath(dir)
+ retval = []
+ for file in os.listdir(dir):
+ if fnmatch.fnmatch(file, pattern):
+ retval.append(os.path.join(dir, file))
+ return retval
+
+def have_pkgconfig():
+ """Checks for the existence of pkg-config"""
+ status = getstatusoutput('pkg-config')[0]
+ if status == 256:
+ return 1
diff --git a/setup.py b/setup.py
index c828cef7..141c5dcb 100755
--- a/setup.py
+++ b/setup.py
@@ -8,25 +8,19 @@
# win32 testing
# install *.pyc for codegen
# GtkGL
+#
"""Python Bindings for the GTK Widget Set.
PyGTK is a set of bindings for the GTK widget set. It provides an object oriented interface that is slightly higher level than the C one. It automatically does all the type casting and reference counting that you would have to do normally with the C API. You can find out more on the official homepage, http://www.daa.com.au/~james/pygtk/"""
-from commands import getoutput
-import fnmatch
-import os
-import string
-import sys
-
from distutils.command.build import build
-from distutils.command.build_ext import build_ext
-from distutils.command.install_lib import install_lib
from distutils.core import setup
-from distutils.extension import Extension
+import os
+import sys
-from codegen.override import Overrides
-from codegen.defsparser import DefsParser
-from codegen.codegen import register_types, write_source, FileOutput
+from dsextras import list_files, have_pkgconfig, GLOBAL_INC, GLOBAL_MACROS
+from dsextras import InstallLib, BuildExt, PkgConfigExtension
+from dsextras import Template, TemplateExtension
MAJOR_VERSION = 1
MINOR_VERSION = 99
@@ -45,11 +39,11 @@ LIBGLADE_REQUIRED = '2.0.0'
PYGTK_SUFFIX = '2.0'
PYGTK_SUFFIX_LONG = 'gtk-' + PYGTK_SUFFIX
-GLOBAL_INC = ['.', 'gtk']
-GLOBAL_MACROS = [('VERSION', '"%s"' % VERSION),
- ('PYGTK_MAJOR_VERSION', MAJOR_VERSION),
- ('PYGTK_MINOR_VERSION', MINOR_VERSION),
- ('PYGTK_MICRO_VERSION', MICRO_VERSION)]
+GLOBAL_INC += ['.', 'gtk']
+GLOBAL_MACROS += [('VERSION', '"%s"' % VERSION),
+ ('PYGTK_MAJOR_VERSION', MAJOR_VERSION),
+ ('PYGTK_MINOR_VERSION', MINOR_VERSION),
+ ('PYGTK_MICRO_VERSION', MICRO_VERSION)]
DEFS_DIR = os.path.join('share', 'pygtk', PYGTK_SUFFIX, 'defs')
CODEGEN_DIR = os.path.join('share', 'pygtk', PYGTK_SUFFIX, 'codegen')
@@ -60,231 +54,51 @@ version = map(int, str_version.split('.'))
if version < [2, 2]:
raise SystemExit, \
"Python 2.2 or higher is required, %s found" % str_version
-
-class PyGtkInstallLib(install_lib):
- local_outputs = []
- local_inputs = []
- def run(self):
- install_dir = self.install_dir
- self.prefix = os.sep.join(install_dir.split(os.sep)[:-4])
-
- # Install everything in site-packages/gtk-2.0
- self.install_dir = os.path.join(self.install_dir, PYGTK_SUFFIX_LONG)
- install_lib.run(self)
-
- # Except these three
- self.install_codegen(install_dir)
- self.install_pc(install_dir)
- self.install_pth(install_dir)
- self.install_pygtk(install_dir)
-
- def install_template(self, filename, install_dir):
- """Install template filename into target directory install_dir."""
- output_file = os.path.split(filename)[-1][:-3]
- exec_prefix = os.path.join(self.prefix, 'bin')
- includedir = os.path.join(self.prefix, 'include')
- datadir = os.path.join(self.prefix, 'share')
- template = open(filename).read()
- template = template.replace('@datadir@', datadir)
- template = template.replace('@exec_prefix@', exec_prefix)
- template = template.replace('@includedir@', includedir)
- template = template.replace('@prefix@', self.prefix)
- template = template.replace('@PYTHON@', sys.executable)
- template = template.replace('@VERSION@', VERSION)
-
- output = os.path.join(install_dir, output_file)
- self.mkpath(install_dir)
- open(output, 'w').write(template)
- self.local_inputs.append(filename)
- self.local_outputs.append(output)
- return output
-
- def install_codegen(self, install_dir):
- codegen = os.path.join('codegen', 'pygtk-codegen-2.0.in')
- file = self.install_template(codegen,
- os.path.join(self.prefix, 'bin'))
+class PyGtkInstallLib(InstallLib):
+ def run(self):
+ self.add_template_option('VERSION', VERSION)
+ self.prepare()
+
+ # Install pygtk.pth, pygtk.py[c] and templates
+ self.install_pth()
+ self.install_pygtk()
+ self.install_templates()
+
+ # Modify the base installation dir
+ install_dir = os.path.join(self.install_dir, PYGTK_SUFFIX_LONG)
+ self.set_install_dir(install_dir)
+
+ InstallLib.run(self)
+
+ def install_templates(self):
+ file = self.install_template('codegen/pygtk-codegen-2.0.in',
+ self.exec_prefix)
os.chmod(file, 0755)
-
- def install_pc(self, install_dir):
- install_dir = os.path.join(self.prefix, 'lib', 'pkgconfig')
- self.install_template('pygtk-2.0.pc.in', install_dir)
+ self.install_template('pygtk-2.0.pc.in',
+ os.path.join(self.libdir, 'pkgconfig'))
- def install_pth(self, install_dir):
+ def install_pth(self):
"""Write the pygtk.pth file"""
- file = os.path.join(install_dir, 'pygtk.pth')
+ file = os.path.join(self.install_dir, 'pygtk.pth')
+ self.mkpath(self.install_dir)
open(file, 'w').write(PYGTK_SUFFIX_LONG)
self.local_outputs.append(file)
self.local_inputs.append('pygtk.pth')
- def install_pygtk(self, install_dir):
+ def install_pygtk(self):
"""install pygtk.py in the right place."""
- self.copy_file('pygtk.py', install_dir)
- self.local_outputs.append(os.path.join(install_dir, 'pygtk.py'))
+ self.copy_file('pygtk.py', self.install_dir)
+ pygtk = os.path.join(self.install_dir, 'pygtk.py')
+ self.byte_compile([pygtk])
+ self.local_outputs.append(pygtk)
self.local_inputs.append('pygtk.py')
- def get_outputs(self):
- return install_lib.get_outputs(self) + self.local_outputs
-
- def get_inputs(self):
- return install_lib.get_inputs(self) + self.local_inputs
-
class PyGtkBuild(build):
enable_threading = 0
PyGtkBuild.user_options.append(('enable-threading', None,
'enable threading support'))
-class PyGtkBuildExt(build_ext):
- def build_extension(self, ext):
- # Generate eventual templates before building
- ext.generate()
- build_ext.build_extension(self, ext)
-
-class PkgConfigExtension(Extension):
- can_build_ok = None
- def __init__(self, **kwargs):
- name = kwargs['pkc_name']
- kwargs['include_dirs'] = self.get_include_dirs(name) + GLOBAL_INC
- kwargs['define_macros'] = GLOBAL_MACROS
- kwargs['libraries'] = self.get_libraries(name)
- kwargs['library_dirs'] = self.get_library_dirs(name)
- self.pkc_name = kwargs['pkc_name']
- self.pkc_version = kwargs['pkc_version']
- del kwargs['pkc_name'], kwargs['pkc_version']
- Extension.__init__(self, **kwargs)
-
- def get_include_dirs(self, name):
- output = getoutput('pkg-config --cflags-only-I %s' % name)
- return output.replace('-I', '').split()
-
- def get_libraries(self, name):
- output = getoutput('pkg-config --libs-only-l %s' % name)
- return output.replace('-l', '').split()
-
- def get_library_dirs(self, name):
- output = getoutput('pkg-config --libs-only-L %s' % name)
- return output.replace('-L', '').split()
-
- def can_build(self):
- """If the pkg-config version found is good enough"""
- if self.can_build_ok != None:
- return self.can_build_ok
-
- retval = os.system('pkg-config --exists %s' % self.pkc_name)
- if retval:
- print "* Could not find %s." % self.pkc_name
- self.can_build_ok = 0
- return 0
-
- orig_version = getoutput('pkg-config --modversion %s' % self.pkc_name)
- version = map(int, orig_version.split('.'))
- pkc_version = map(int, self.pkc_version.split('.'))
-
- if version >= pkc_version:
- self.can_build_ok = 1
- return 1
- else:
- print "Warning: Too old version of %s" % self.pkc_name
- print " Need %s, but %s is installed" % \
- (self.pkc_version, orig_version)
- self.can_build_ok = 0
- return 0
-
- def generate(self):
- pass
-
-class Template:
- def __init__(self, override, output, defs, prefix, register=[]):
- self.override = override
- self.defs = defs
- self.register = register
- self.output = output
- self.prefix = prefix
-
- def check_dates(self):
- if not os.path.exists(self.output):
- return 0
-
- files = self.register[:]
- files.append(self.override)
-# files.append('setup.py')
- files.append(self.defs)
-
- newest = 0
- for file in files:
- test = os.stat(file)[8]
- if test > newest:
- newest = test
-
- if newest < os.stat(self.output)[8]:
- return 1
- return 0
-
- def generate(self):
- if self.check_dates():
- return
-
- for item in self.register:
- dp = DefsParser(item)
- dp.startParsing()
- register_types(dp)
-
- dp = DefsParser(self.defs)
- dp.startParsing()
- register_types(dp)
-
- fd = open(self.output, 'w')
- write_source(dp,
- Overrides(self.override),
- self.prefix,
- FileOutput(fd, self.output))
- fd.close()
-
-class TemplateExtension(PkgConfigExtension):
- def __init__(self, **kwargs):
- name = kwargs['name']
- defs = kwargs['defs']
- output = defs[:-5] + '.c'
- override = kwargs['override']
- self.templates = []
- self.templates.append(Template(override, output, defs, 'py' + name,
- kwargs['register']))
-
- del kwargs['register'], kwargs['override'], kwargs['defs']
-
- if kwargs.has_key('output'):
- kwargs['name'] = kwargs['output']
- del kwargs['output']
-
- PkgConfigExtension.__init__(self, **kwargs)
-
- def generate(self):
- map(lambda x: x.generate(), self.templates)
-
-def list_files(dir):
- """List all files in a dir, with filename match support:
- for example: glade/*.glade will return all files in the glade directory
- that matches *.glade. It also looks up the full path"""
- if dir.find(os.sep) != -1:
- parts = dir.split(os.sep)
- dir = string.join(parts[:-1], os.sep)
- pattern = parts[-1]
- else:
- pattern = dir
- dir = '.'
-
- dir = os.path.abspath(dir)
- retval = []
- for file in os.listdir(dir):
- if fnmatch.fnmatch(file, pattern):
- retval.append(os.path.join(dir, file))
- return retval
-
-def have_pkgconfig():
- """Checks for the existence of pkg-config"""
- if os.system('pkg-config 2> /dev/null') == 256:
- return 1
-
# GObject
gobject = PkgConfigExtension(name='gobject', pkc_name='gobject-2.0',
pkc_version=GOBJECT_REQUIRED,
@@ -341,7 +155,6 @@ libglade = TemplateExtension(name='libglade', pkc_name='libglade-2.0',
'gtk/libglade.defs'],
override='gtk/libglade.override')
-
data_files = []
ext_modules = []
py_modules = []
@@ -405,5 +218,5 @@ setup(name="pygtk",
ext_modules=ext_modules,
data_files=data_files,
cmdclass={'install_lib': PyGtkInstallLib,
- 'build_ext': PyGtkBuildExt,
+ 'build_ext': BuildExt,
'build': PyGtkBuild})