[pygobject] Setup.py cosmetic tidy



commit e580da87f0b2fd36cb5d8008fb2fb0c3b01f456a
Author: John Stowers <john stowers gmail com>
Date:   Thu Apr 15 13:40:39 2010 +1200

    Setup.py cosmetic tidy
    
     * Remove local doc install, point to website instead
     * link to versioned docs

 pygobject_postinstall.py |   43 ++++++++++++++++++++++++++-----------------
 setup.py                 |   39 ++++++++++++++-------------------------
 2 files changed, 40 insertions(+), 42 deletions(-)
---
diff --git a/pygobject_postinstall.py b/pygobject_postinstall.py
index 8ddaa60..487828e 100644
--- a/pygobject_postinstall.py
+++ b/pygobject_postinstall.py
@@ -5,8 +5,12 @@ Local configuration files were successfully updated."""
 
 import os, re, sys
 
-prefix_pattern=re.compile("^prefix=.*")
+pkgconfig_file = os.path.normpath(
+    os.path.join(sys.prefix,
+                 'lib/pkgconfig/pygobject-2.0.pc'))
 
+prefix_pattern=re.compile("^prefix=.*")
+version_pattern=re.compile("Version: ([0-9]+\.[0-9]+\.[0-9]+)")
 
 def replace_prefix(s):
     if prefix_pattern.match(s):
@@ -16,6 +20,16 @@ def replace_prefix(s):
     
     return s
 
+def get_doc_url(pkgconfig_file, base_url):
+    try:
+        f = open(pkgconfig_file).read()
+        ver = version_pattern.search(f).groups()[0]
+        majv,minv,micv = ver.split('.')
+        doc_url = "%s/%s.%s/" % (base_url,majv,minv)
+    except:
+        doc_url = base_url + "/stable/"
+    return doc_url
+
 # TODO : Check that shortcuts are created system-wide when the user
 # has admin rights (hint: see pywin32 postinstall)
 def create_shortcuts():
@@ -25,15 +39,16 @@ def create_shortcuts():
     pygtk_shortcuts = os.path.join(progs_folder, 'PyGTK')
     if not os.path.isdir(pygtk_shortcuts):
         os.mkdir(pygtk_shortcuts)
-       
+
+    # link to specific documentation version by parsing the
+    # pkgconfig file
+    doc_url = get_doc_url(pkgconfig_file,
+                          "http://library.gnome.org/devel/pygobject";)
     pygobject_doc_link=os.path.join(pygtk_shortcuts,
                                     'PyGObject Documentation.lnk')
     if os.path.isfile(pygobject_doc_link):   
         os.remove(pygobject_doc_link)
-    
-    create_shortcut(os.path.join(sys.prefix,'share','gtk-doc','html',
-                                 'pygobject','index.html'),
-                    'PyGObject Documentation', pygobject_doc_link)
+    create_shortcut(doc_url,'PyGObject Documentation',pygobject_doc_link)
 
 def remove_shortcuts():
     pygtk_shortcuts = os.path.join(
@@ -47,17 +62,11 @@ def remove_shortcuts():
 
 if len(sys.argv) == 2:
     if sys.argv[1] == "-install":
-        filenames=['lib/pkgconfig/pygobject-2.0.pc',
-                   'share/pygobject/xsl/fixxref.py']
-        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))
+        # fixup the pkgconfig file
+        lines=open(pkgconfig_file).readlines()
+        open(pkgconfig_file, 'w').writelines(map(replace_prefix,lines))
         # TODO: Add an installer option for shortcut creation 
-        # create_shortcuts()
+        create_shortcuts()
         print __doc__
     elif sys.argv[1] == "-remove":
-        pass
-        # remove_shortcuts()
+        remove_shortcuts()
diff --git a/setup.py b/setup.py
index 50f7abe..0999c00 100755
--- a/setup.py
+++ b/setup.py
@@ -30,11 +30,9 @@ else:
     print '*'*70
     input = raw_input('Not supported, ok [y/N]? ')
     if not input.startswith('y'):
-        raise SystemExit
+        raise SystemExit("Aborted")
 
-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]
+MIN_PYTHON_VERSION = (2, 3, 5)
 
 MAJOR_VERSION = int(get_m4_define('pygobject_major_version'))
 MINOR_VERSION = int(get_m4_define('pygobject_minor_version'))
@@ -55,12 +53,18 @@ GLOBAL_MACROS += [('PYGOBJECT_MAJOR_VERSION', MAJOR_VERSION),
 if sys.platform == 'win32':
     GLOBAL_MACROS.append(('VERSION', '"""%s"""' % VERSION))
 else:
-    GLOBAL_MACROS.append(('VERSION', '"%s"' % VERSION))
+    raise SystemExit("Error: distutils build only supported on windows")
+
+if sys.version_info[:3] < MIN_PYTHON_VERSION:
+    raise SystemExit("Python %s or higher is required, %s found" % (
+        ".".join(map(str,MIN_PYTHON_VERSION)),
+                     ".".join(map(str,sys.version_info[:3]))))
+
+if not have_pkgconfig():
+    raise SystemExit("Error, could not find pkg-config")
 
 DEFS_DIR    = os.path.join('share', 'pygobject', PYGOBJECT_SUFFIX, 'defs')
 INCLUDE_DIR = os.path.join('include', 'pygtk-%s' % PYGOBJECT_SUFFIX)
-XSL_DIR = os.path.join('share', 'pygobject','xsl')
-HTML_DIR = os.path.join('share', 'gtk-doc', 'html', 'pygobject')
 
 class PyGObjectInstallLib(InstallLib):
     def run(self):
@@ -107,8 +111,6 @@ class PyGObjectInstallData(InstallData):
         self.install_template('pygobject-2.0.pc.in',
                               os.path.join(self.install_dir,
                                            'lib', 'pkgconfig'))
-        self.install_template('docs/xsl/fixxref.py.in',
-                              os.path.join(self.install_dir, XSL_DIR))
 
 class PyGObjectBuild(build):
     enable_threading = 1
@@ -173,10 +175,6 @@ ext_modules = []
 py_modules = ['dsextras']
 packages = ['codegen']
 
-if not have_pkgconfig():
-    print "Error, could not find pkg-config"
-    raise SystemExit
-
 if glib.can_build():
     #It would have been nice to create another class, such as PkgConfigCLib to
     #encapsulate this dictionary, but it is impossible. build_clib.py does
@@ -197,30 +195,21 @@ if glib.can_build():
     ext_modules.append(glib)
     py_modules += ['glib.__init__', 'glib.option']
 else:
-    print
-    print 'ERROR: Nothing to do, glib could not be found and is essential.'
-    raise SystemExit
+    raise SystemExit("ERROR: Nothing to do, glib could not be found and is essential.")
 
 if gobject.can_build():
     ext_modules.append(gobject)
     data_files.append((INCLUDE_DIR, ('gobject/pygobject.h',)))
-    data_files.append((HTML_DIR, glob.glob('docs/html/*.html')))
-    data_files.append((HTML_DIR, ['docs/style.css']))
-    data_files.append((XSL_DIR,  glob.glob('docs/xsl/*.xsl')))
     py_modules += ['gobject.__init__', 'gobject.propertyhelper', 'gobject.constants']
 else:
-    print
-    print 'ERROR: Nothing to do, gobject could not be found and is essential.'
-    raise SystemExit
+    raise SystemExit("ERROR: Nothing to do, gobject could not be found and is essential.")
 
 if gio.can_build():
     ext_modules.append(gio)
     py_modules += ['gio.__init__']
     data_files.append((DEFS_DIR,('gio/gio-types.defs',)))
 else:
-    print
-    print 'ERROR: Nothing to do, gio could not be found and is essential.'
-    raise SystemExit
+    raise SystemExit("ERROR: Nothing to do, gio could not be found and is essential.")
 
 # Threading support
 if '--disable-threading' in sys.argv:



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