setuptools support
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 19 Apr 2010 15:29:58 +0200
changeset 527 70c8611957d5
parent 526 af6c6e952431
child 528 1ddc5bc2504a
setuptools support
__pkginfo__.py
debian/rules
setup.py
--- a/__pkginfo__.py	Thu Apr 08 13:34:35 2010 +0200
+++ b/__pkginfo__.py	Mon Apr 19 15:29:58 2010 +0200
@@ -64,3 +64,14 @@
                               extra_link_args=['-static-libgcc'],
                               )
                     ]
+
+install_requires = [
+    'logilab-common >= 0.47.0',
+    'logilab-database',
+    'yapps2 >= 2.1.1',
+    ]
+
+# links to download yapps2 package that is not (yet) registered in pypi
+dependency_links = [
+    "http://ftp.logilab.org/pub/yapps/yapps2-2.1.1.zip#egg=yapps2-2.1.1",
+    ]
--- a/debian/rules	Thu Apr 08 13:34:35 2010 +0200
+++ b/debian/rules	Mon Apr 19 15:29:58 2010 +0200
@@ -12,13 +12,13 @@
 #export DH_VERBOSE=1
 
 build: build-stamp
-build-stamp: 
+build-stamp:
 	dh_testdir
 	(for PYTHON in `pyversions -r`; do \
-	    $${PYTHON} setup.py build ; done )
+	    NO_SETUPTOOLS=1 $${PYTHON} setup.py build ; done )
 	${MAKE} -C doc html || true
 	touch build-stamp
-clean: 
+clean:
 	dh_testdir
 	dh_testroot
 	rm -f build-stamp configure-stamp
@@ -33,7 +33,7 @@
 	dh_clean -k
 	dh_installdirs
 	(for PYTHON in `pyversions -r`; do \
-		$${PYTHON} setup.py install --no-compile --prefix=debian/python-rql/usr/ ; \
+		NO_SETUPTOOLS=1 $${PYTHON} setup.py install --no-compile --prefix=debian/python-rql/usr/ ; \
 	done)
 	# remove test directory (installed in in the doc directory)
 	rm -rf debian/python-rql/usr/lib/python*/site-packages/rql/test
@@ -45,10 +45,10 @@
 
 # Build architecture-dependent files here.
 binary-arch: build install
-	dh_testdir 
-	dh_testroot 
+	dh_testdir
+	dh_testroot
 	dh_install -a
-	dh_pysupport -a 
+	dh_pysupport -a
 	gzip -9 -c ChangeLog > changelog.gz
 	dh_installchangelogs -a
 	dh_installexamples -a
@@ -59,7 +59,7 @@
 	dh_fixperms -a
 	dh_shlibdeps -a
 	dh_installdeb -a
-	dh_gencontrol -a 
+	dh_gencontrol -a
 	dh_md5sums -a
 	dh_builddeb -a
 
--- a/setup.py	Thu Apr 08 13:34:35 2010 +0200
+++ b/setup.py	Mon Apr 19 15:29:58 2010 +0200
@@ -1,50 +1,49 @@
 #!/usr/bin/env python
-# pylint: disable-msg=W0404,W0622,W0704,W0613,E0611,C0103
+# pylint: disable-msg=W0404,W0622,W0704,W0613,W0152
 """Generic Setup script, takes package info from __pkginfo__.py file.
 
-:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: General Public License version 2 - http://www.gnu.org/licenses
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
 
 import os
 import sys
 import shutil
-from distutils.core import setup
 from os.path import isdir, exists, join, walk
 
+try:
+    if os.environ.get('NO_SETUPTOOLS'):
+        raise ImportError()
+    from setuptools import setup
+    from setuptools.command import install_lib
+    USE_SETUPTOOLS = 1
+except ImportError:
+    from distutils.core import setup
+    from distutils.command import install_lib
+    USE_SETUPTOOLS = 0
+
+
+sys.modules.pop('__pkginfo__', None)
 # import required features
 from __pkginfo__ import modname, version, license, short_desc, long_desc, \
      web, author, author_email
 # import optional features
-try:
-    from __pkginfo__ import distname
-except ImportError:
-    distname = modname
-try:
-    from __pkginfo__ import scripts
-except ImportError:
-    scripts = []
-try:
-    from __pkginfo__ import data_files
-except ImportError:
-    data_files = None
-try:
-    from __pkginfo__ import subpackage_of
-except ImportError:
-    subpackage_of = None
-try:
-    from __pkginfo__ import include_dirs
-except ImportError:
-    include_dirs = []
-try:
-    from __pkginfo__ import ext_modules
-except ImportError:
-    ext_modules = None
+import __pkginfo__
+distname = getattr(__pkginfo__, 'distname', modname)
+scripts = getattr(__pkginfo__, 'scripts', [])
+data_files = getattr(__pkginfo__, 'data_files', None)
+subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
+include_dirs = getattr(__pkginfo__, 'include_dirs', [])
+ext_modules = getattr(__pkginfo__, 'ext_modules', None)
+install_requires = getattr(__pkginfo__, 'install_requires', None)
+dependency_links = getattr(__pkginfo__, 'dependency_links', None)
 
-BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
-IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
+STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
+
+IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
+
 
 
 def ensure_scripts(linux_scripts):
@@ -77,8 +76,9 @@
     return result
 
 def export(from_dir, to_dir,
-           blacklist=BASE_BLACKLIST,
-           ignore_ext=IGNORED_EXTENSIONS):
+           blacklist=STD_BLACKLIST,
+           ignore_ext=IGNORED_EXTENSIONS,
+           verbose=True):
     """make a mirror of from_dir in to_dir, omitting directories and files
     listed in the black list
     """
@@ -95,9 +95,10 @@
                 continue
             if filename[-1] == '~':
                 continue
-            src = '%s/%s' % (directory, filename)
+            src = join(directory, filename)
             dest = to_dir + src[len(from_dir):]
-            print >> sys.stderr, src, '->', dest
+            if verbose:
+                print >> sys.stderr, src, '->', dest
             if os.path.isdir(src):
                 if not exists(dest):
                     os.mkdir(dest)
@@ -115,43 +116,28 @@
     walk(from_dir, make_mirror, None)
 
 
-EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n'
+EMPTY_FILE = '''"""generated file, don\'t modify or your data will be lost"""
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    pass
+'''
 
-def install(**kwargs):
-    """setup entry point"""
-    if subpackage_of:
-        package = subpackage_of + '.' + modname
-        kwargs['package_dir'] = {package : '.'}
-        packages = [package] + get_packages(os.getcwd(), package)
-    else:
-        kwargs['package_dir'] = {modname : '.'}
-        packages = [modname] + get_packages(os.getcwd(), modname)
-    kwargs['packages'] = packages
-    dist = setup(name = distname,
-                 version = version,
-                 license =license,
-                 description = short_desc,
-                 long_description = long_desc,
-                 author = author,
-                 author_email = author_email,
-                 url = web,
-                 scripts = ensure_scripts(scripts),
-                 data_files=data_files,
-                 ext_modules=ext_modules,
-                 **kwargs
-                 )
-
-    if dist.have_run.get('install_lib'):
-        _install = dist.get_command_obj('install_lib')
+class MyInstallLib(install_lib.install_lib):
+    """extend install_lib command to handle  package __init__.py and
+    include_dirs variable if necessary
+    """
+    def run(self):
+        """overridden from install_lib class"""
+        install_lib.install_lib.run(self)
+        # create Products.__init__.py if needed
         if subpackage_of:
-            # create Products.__init__.py if needed
-            product_init = join(_install.install_dir, subpackage_of,
-                                '__init__.py')
+            product_init = join(self.install_dir, subpackage_of, '__init__.py')
             if not exists(product_init):
+                self.announce('creating %s' % product_init)
                 stream = open(product_init, 'w')
                 stream.write(EMPTY_FILE)
                 stream.close()
-
         # manually install included directories if any
         if include_dirs:
             if subpackage_of:
@@ -159,9 +145,51 @@
             else:
                 base = modname
             for directory in include_dirs:
-                dest = join(_install.install_dir, base, directory)
-                export(directory, dest)
-    return dist
+                dest = join(self.install_dir, base, directory)
+                export(directory, dest, verbose=False)
+
+def install(**kwargs):
+    """setup entry point"""
+    try:
+        if USE_SETUPTOOLS:
+            sys.argv.remove('--force-manifest')
+    except:
+        pass
+    try:
+        if not USE_SETUPTOOLS:
+            # install-layout option was introduced in 2.5.3-1~exp1
+            if sys.versioninfo < (2, 5, 4):
+                sys.argv.remove('--install-layout=deb')
+                print "W: remove '--install-layout=deb' option"
+    except:
+        pass
+    if subpackage_of:
+        package = subpackage_of + '.' + modname
+        kwargs['package_dir'] = {package : '.'}
+        packages = [package] + get_packages(os.getcwd(), package)
+        if USE_SETUPTOOLS:
+            kwargs['namespace_packages'] = [subpackage_of]
+    else:
+        kwargs['package_dir'] = {modname : '.'}
+        packages = [modname] + get_packages(os.getcwd(), modname)
+    if USE_SETUPTOOLS and install_requires:
+        kwargs['install_requires'] = install_requires
+        kwargs['dependency_links'] = dependency_links
+    kwargs['packages'] = packages
+    return setup(name = distname,
+                 version = version,
+                 license = license,
+                 description = short_desc,
+                 long_description = long_desc,
+                 author = author,
+                 author_email = author_email,
+                 url = web,
+                 scripts = ensure_scripts(scripts),
+                 data_files = data_files,
+                 ext_modules = ext_modules,
+                 cmdclass = {'install_lib': MyInstallLib},
+                 **kwargs
+                 )
 
 if __name__ == '__main__' :
     install()