Description: Fixed & completed setup.py
 The upstream setup.py had to be amended under three aspects:
 1) it tests the presence of required libraries (and fails if they are missing);
 2) it fails at compiling sphinx documentation (unless it is ran from the
    documentation root dir, which isn't the case) - this point is solved by
    subclassing BuildDoc, and changing the "run" method to first chdir there;
 3) it doesn't install documentation and .desktop files.

Author: Pietro Battiston <me@pietrobattiston.it>

---

Forwarded: yes
Last-Update: <2010-12-20>

--- sqlkit-0.9.2.orig/setup.py
+++ sqlkit-0.9.2/setup.py
@@ -26,10 +26,11 @@ import sys
 try:
    from setuptools import setup, find_packages
 except ImportError, e:
-   from distribute_setup import use_setuptools
-   use_setuptools()
-   from setuptools import setup, find_packages
-   
+   print "You need to install setuptools to use this setup.py script"
+   sys.exit(1)
+
+from sphinx.setup_command import BuildDoc
+
 REQUIRES = []
 
 f = open('sqlkit/__init__.py')
@@ -37,32 +38,40 @@ for line in f:
    if line.startswith('__version__'):
        version = line.split()[2].strip("'")
 
-if sys.argv[1] == 'install':
-   try:
-      import pygtk
-      pygtk.require('2.0')
-   except ImportError:
-      print "You need to install also pygtk and I was not able to work out"
-      print "  a correct dependency in setup.py"
-      sys.exit(1)
-
-# setuptools really fails in understanding which packages are already installed
-# pip is much better!
-try:
-   import sqlalchemy
-except ImportError:
-   REQUIRES = ['sqlalchemy >= 0.5', ]
-
-try:
-   import babel
-except ImportError:
-   REQUIRES += ['Babel']
-
-try:
-   import dateutil
-except ImportError:
-   REQUIRES += ['python-dateutil']
 
+class BuildDocFromDir(BuildDoc):
+    def run(self):
+        """
+        Run the normal build but first chdir to the documentation root.
+        """
+        orig_params = [os.path.realpath( '.' ), self.builder_target_dir, self.doctree_dir]
+        os.chdir( self.source_dir )
+
+        self.builder_target_dir = os.path.relpath( self.builder_target_dir, self.source_dir )
+        self.doctree_dir = os.path.relpath( self.doctree_dir, self.source_dir )
+
+        BuildDoc.run( self )
+        curdir, self.builder_target_dir, self.docree_dir = orig_params
+        os.chdir( curdir )
+
+
+def doc_files():
+    """
+    Create a list of documentation files.
+    """
+    files = []
+    walker = os.walk( 'doc/html' )
+    while True:
+        try:
+            n = walker.next()
+            new_list = []
+            files.append( (os.path.join( "share/doc/python-sqlkit-doc", n[0][9:] ), new_list) )
+            for a_file in n[2]:
+                new_list.append( "%s/%s" % (n[0], a_file) )
+        except StopIteration:
+            break
+    
+    return files
    
 setup(name='sqlkit',
       version=version,
@@ -73,10 +82,12 @@ setup(name='sqlkit',
       install_requires=REQUIRES,
       packages = find_packages('.'),
       scripts=['bin/sqledit'],
+      data_files =[('share/applications', ['sqlkit.desktop'])] + doc_files(),
 #      package_dir = {'' : 'sqlkit'},
 #      package_data = {'sqlkit' : ['locale']},
       classifiers= classifiers.split('\n'),
       include_package_data=True,      
       zip_safe=False,
+      cmdclass={'build_sphinx': BuildDocFromDir}
      )
 
