pygtksourceview r83 - trunk



Author: pborelli
Date: Mon Apr 28 18:08:16 2008
New Revision: 83
URL: http://svn.gnome.org/viewvc/pygtksourceview?rev=83&view=rev

Log:
2008-04-28  Paolo Borelli  <pborelli katamail com>

	* setup.py:
	* pygtksourceview_postinstall.py:

	add an unofficial distutils based buildsystem that alllows to create
	win32 installers.



Added:
   trunk/pygtksourceview_postinstall.py   (contents, props changed)
   trunk/setup.py   (contents, props changed)
Modified:
   trunk/ChangeLog

Added: trunk/pygtksourceview_postinstall.py
==============================================================================
--- (empty file)
+++ trunk/pygtksourceview_postinstall.py	Mon Apr 28 18:08:16 2008
@@ -0,0 +1,100 @@
+
+"""pygtksourceview is now installed on your machine.
+
+Local configuration files were successfully updated."""
+
+import os, os.path, re, sys
+import distutils.sysconfig
+import distutils.file_util
+import distutils.errors
+
+PYGOBJECT_XSL_DIR = os.path.join('share', 'pygobject','xsl')
+PYGOBJECT_HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygobject')
+HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygtksourceview2')
+
+prefix_pattern=re.compile("^prefix=.*")
+exec_pattern=re.compile("^exec\s.*")
+codegendir_pattern=re.compile("^codegendir=.*")
+
+def replace_prefix(s):
+    if prefix_pattern.match(s):
+        s='prefix='+sys.prefix.replace("\\","/")+'\n'
+    if exec_pattern.match(s):
+        s=('exec '+sys.prefix+'\\python.exe '+
+           '$codegendir/codegen.py \"$ \"\n').replace("\\","/")
+    if codegendir_pattern.match(s):
+        s=('codegendir='
+           +distutils.sysconfig.get_python_lib().replace("\\","/")+
+           '/gtk-2.0/codegen' + '\n')
+    return s
+
+def copy_pygobject_css():
+    # Copy style.css from pygobject docs to pygtk docs
+    try:
+        distutils.file_util.copy_file(
+            os.path.normpath(os.path.join(sys.prefix, PYGOBJECT_HTML_DIR,
+                                          'style.css')),
+            os.path.normpath(os.path.join(sys.prefix,HTML_DIR)))
+    except distutils.errors.DistutilsFileError:
+        # probably pygobject has not been installed yet
+        pass
+        
+    
+
+def html_fixxref():
+    sys.path.insert(0, os.path.normpath(os.path.join(sys.prefix,
+                                                     PYGOBJECT_XSL_DIR)))
+    try:
+        import fixxref
+        fixxref.fix_xrefs(os.path.normpath(os.path.join(sys.prefix,
+                                                        HTML_DIR)))
+    except ImportError, e:
+        pass
+
+# TODO : Check that shortcuts are created system-wide when the user
+# has admin rights (hint: see pywin32 postinstall)
+def create_shortcuts():
+    progs_folder= get_special_folder_path("CSIDL_COMMON_PROGRAMS")
+    site_packages_dir = os.path.join(sys.prefix , 'lib','site-packages')
+   
+    pygtk_shortcuts = os.path.join(progs_folder, 'PyGtkSourceView')
+    if not os.path.isdir(pygtk_shortcuts):
+        os.mkdir(pygtk_shortcuts)
+       
+    pygtk_doc_link=os.path.join(pygtk_shortcuts,
+                                'PyGtkSourceView Documentation.lnk')
+    if os.path.isfile(pygtk_doc_link):   
+        os.remove(pygtk_doc_link)
+    
+    create_shortcut(os.path.join(sys.prefix,'share','gtk-doc','html',
+                                 'pygtksourceview2','index.html'),
+                    'PyGtkSourceView Documentation', pygtk_doc_link)
+   
+def remove_shortcuts():
+    pygtk_shortcuts = os.path.join(
+        get_special_folder_path('CSIDL_COMMON_PROGRAMS'), 'PyGtkSourceView')
+    os.remove(os.path.join(pygtk_shortcuts,'PyGtkSourceView Documentation.lnk'))
+    try:
+        os.rmdir(pygtk_shortcuts)
+    except OSError, e:
+        # Directory is not empty, so leave it like that !
+        pass
+
+if len(sys.argv) == 2:
+    if sys.argv[1] == "-install":
+        filenames=['lib/pkgconfig/pygtksourceview-2.0.pc']
+        for filename in filenames: 
+            pkgconfig_file = os.path.normpath(
+                os.path.join(sys.prefix,filename))
+
+            lines=open(pkgconfig_file).readlines()
+            open(pkgconfig_file, 'w').writelines(map(replace_prefix,lines))
+        copy_pygobject_css()
+        html_fixxref()
+        # TODO: Add an installer option for shortcut creation 
+        # create_shortcuts()
+        print __doc__
+    elif sys.argv[1] == "-remove":
+        # remove_shortcuts()
+        os.remove(os.path.normpath(
+            os.path.join(sys.prefix,HTML_DIR,'style.css')))

Added: trunk/setup.py
==============================================================================
--- (empty file)
+++ trunk/setup.py	Mon Apr 28 18:08:16 2008
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+#
+# setup.py - distutils configuration for pygtksourceview
+#
+"""Python Bindings for GtkSourceView."""
+
+from distutils.command.build import build
+from distutils.core import setup
+import glob
+import os
+import sys
+
+import dsextras
+
+if not dsextras.have_pkgconfig():
+    print "Error, could not find pkg-config"
+    raise SystemExit
+
+# we need this hack to make dsextras Template work since it uses
+# the codegen module:
+# we locate the module path and then reload dsextras.
+codegendir = dsextras.getoutput('pkg-config --variable codegendir pygtk-2.0')
+codegendir = os.path.dirname(codegendir)
+sys.path.append(codegendir)
+try:
+    import codegen.createdefs
+except ImportError:
+    raise SystemExit, \
+'Could not find code generator in %s, do you have installed pygtk correctly?'
+reload(dsextras)
+
+from dsextras import get_m4_define, getoutput, have_pkgconfig, \
+     pkgc_version_check, \
+     GLOBAL_INC, GLOBAL_MACROS, InstallLib, InstallData, BuildExt, \
+     PkgConfigExtension, Template, TemplateExtension
+
+if '--yes-i-know-its-not-supported' in sys.argv:
+    sys.argv.remove('--yes-i-know-its-not-supported')
+else:
+    print '*'*70
+    print 'Building PyGtkSourceView using distutils is NOT SUPPORTED.'
+    print "It's mainly included to be able to easily build win32 installers"
+    print "You may continue, but only if you agree to not ask any questions"
+    print "To build PyGObject in a supported way, read the INSTALL file"
+    print
+    print "Build fixes are of course welcome and should be filed in bugzilla"
+    print '*'*70
+    input = raw_input('Not supported, ok [y/N]? ')
+    if not input.startswith('y'):
+        raise SystemExit
+
+if sys.version_info[:3] < (2, 3, 5):
+    raise SystemExit, \
+          "Python 2.3.5 or higher is required, %d.%d.%d found" % sys.version_info[:3]
+
+MAJOR_VERSION = int(get_m4_define('pygtksourceview_major_version'))
+MINOR_VERSION = int(get_m4_define('pygtksourceview_minor_version'))
+MICRO_VERSION = int(get_m4_define('pygtksourceview_micro_version'))
+
+VERSION = "%d.%d.%d" % (MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION)
+
+GTKSOURCEVIEW_REQUIRED = get_m4_define('gtksourceview_required_version')
+PYGOBJECT_REQUIRED  = get_m4_define('pygobject_required_version')
+PYGTK_REQUIRED  = get_m4_define('pygtk_required_version')
+
+GLOBAL_INC += ['gtksourceview']
+GLOBAL_MACROS += [('PYGTKSOURCEVIEW_MAJOR_VERSION', MAJOR_VERSION),
+                  ('PYGTKSOURCEVIEW_MINOR_VERSION', MINOR_VERSION),
+                  ('PYGTKSOURCEVIEW_MICRO_VERSION', MICRO_VERSION)]
+
+if sys.platform == 'win32':
+    GLOBAL_MACROS.append(('VERSION', '"""%s"""' % VERSION))
+    GLOBAL_MACROS.append(('PLATFORM_WIN32',1))
+    GLOBAL_MACROS.append(('HAVE_BIND_TEXTDOMAIN_CODESET',1))
+else:
+    GLOBAL_MACROS.append(('VERSION', '"%s"' % VERSION))
+
+defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0')
+print "defs dir " + defsdir
+GTKDEFS = [os.path.join(defsdir, 'pango-types.defs'),
+           os.path.join(defsdir, 'gdk-types.defs'),
+           os.path.join(defsdir, 'gtk-types.defs')]
+
+PYGTK_SUFFIX = '2.0'
+DEFS_DIR = os.path.join('share', 'pygtk', PYGTK_SUFFIX, 'defs')
+HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygtksourceview2')
+
+
+class PyGtkSourceViewInstallData(InstallData):
+    def run(self):
+        self.add_template_option('VERSION', VERSION)
+        self.prepare()
+
+        # Install templates
+        self.install_templates()
+
+        InstallData.run(self)
+
+    def install_templates(self):
+        self.install_template('pygtksourceview-2.0.pc.in',
+                              os.path.join(self.install_dir,
+                                           'lib', 'pkgconfig'))
+
+gtksourceview2 = TemplateExtension(name='gtksourceview2',
+				   pkc_name='gtksourceview-2.0',
+                                   pkc_version=GTKSOURCEVIEW_REQUIRED,
+                                   sources=['gtksourceview2module.c', 'gtksourceview2.c'],
+                                   register=GTKDEFS,
+                                   override='gtksourceview2.override',
+                                   defs='gtksourceview2.defs',
+                                   py_ssize_t_clean=True)
+
+data_files = []
+ext_modules = []
+
+if gtksourceview2.can_build():
+    ext_modules.append(gtksourceview2)
+    data_files.append((DEFS_DIR, ('gtksourceview2.defs',)))
+    data_files.append((HTML_DIR, glob.glob('docs/html/*.html')))
+else:
+    raise SystemExit
+
+doclines = __doc__.split("\n")
+
+options = {"bdist_wininst": {"install_script": "pygtksourceview_postinstall.py"}}
+
+setup(name="pygtksourceview",
+      version=VERSION,
+      license='LGPL',
+      platforms=['yes'],
+      description = doclines[0],
+      long_description = '\n'.join(doclines[2:]),
+      ext_modules = ext_modules,
+      data_files = data_files,
+      scripts = ['pygtksourceview_postinstall.py'],
+      options = options,
+      cmdclass = {
+	  'install_data': PyGtkSourceViewInstallData,
+	  'build_ext': BuildExt,
+      }
+)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]