setup.py
changeset 11057 0b59724cb3f2
parent 10662 10942ed172de
child 11276 6eeb7abda47a
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
    22 """
    22 """
    23 
    23 
    24 import os
    24 import os
    25 import sys
    25 import sys
    26 import shutil
    26 import shutil
    27 from os.path import isdir, exists, join, walk
    27 from os.path import dirname, exists, isdir, join
    28 
    28 
    29 try:
    29 try:
    30     if os.environ.get('NO_SETUPTOOLS'):
    30     if os.environ.get('NO_SETUPTOOLS'):
    31         raise ImportError() # do as there is no setuptools
    31         raise ImportError() # do as there is no setuptools
    32     from setuptools import setup
    32     from setuptools import setup
    36     from distutils.core import setup
    36     from distutils.core import setup
    37     from distutils.command import install_lib
    37     from distutils.command import install_lib
    38     USE_SETUPTOOLS = False
    38     USE_SETUPTOOLS = False
    39 from distutils.command import install_data
    39 from distutils.command import install_data
    40 
    40 
       
    41 here = dirname(__file__)
       
    42 
    41 # import required features
    43 # import required features
    42 from __pkginfo__ import modname, version, license, description, web, \
    44 pkginfo = join(here, 'cubicweb', '__pkginfo__.py')
    43      author, author_email
    45 __pkginfo__ = {}
       
    46 with open(pkginfo) as f:
       
    47     exec(f.read(), __pkginfo__)
       
    48 modname = __pkginfo__['modname']
       
    49 version = __pkginfo__['version']
       
    50 license = __pkginfo__['license']
       
    51 description = __pkginfo__['description']
       
    52 web = __pkginfo__['web']
       
    53 author = __pkginfo__['author']
       
    54 author_email = __pkginfo__['author_email']
    44 
    55 
    45 long_description = open('README').read()
    56 long_description = open('README').read()
    46 
    57 
    47 # import optional features
    58 # import optional features
    48 import __pkginfo__
       
    49 if USE_SETUPTOOLS:
    59 if USE_SETUPTOOLS:
    50     requires = {}
    60     requires = {}
    51     for entry in ("__depends__",): # "__recommends__"):
    61     for entry in ("__depends__",): # "__recommends__"):
    52         requires.update(getattr(__pkginfo__, entry, {}))
    62         requires.update(__pkginfo__.get(entry, {}))
    53     install_requires = [("%s %s" % (d, v and v or "")).strip()
    63     install_requires = [("%s %s" % (d, v and v or "")).strip()
    54                        for d, v in requires.items()]
    64                        for d, v in requires.items()]
    55 else:
    65 else:
    56     install_requires = []
    66     install_requires = []
    57 
    67 
    58 distname = getattr(__pkginfo__, 'distname', modname)
    68 distname = __pkginfo__.get('distname', modname)
    59 scripts = getattr(__pkginfo__, 'scripts', ())
    69 scripts = __pkginfo__.get('scripts', ())
    60 include_dirs = getattr(__pkginfo__, 'include_dirs', ())
    70 include_dirs = __pkginfo__.get('include_dirs', ())
    61 data_files = getattr(__pkginfo__, 'data_files', None)
    71 data_files = __pkginfo__.get('data_files', None)
    62 subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
    72 subpackage_of = __pkginfo__.get('subpackage_of', None)
    63 ext_modules = getattr(__pkginfo__, 'ext_modules', None)
    73 ext_modules = __pkginfo__.get('ext_modules', None)
    64 package_data = getattr(__pkginfo__, 'package_data', {})
    74 package_data = __pkginfo__.get('package_data', {})
    65 
    75 
    66 BASE_BLACKLIST = ('CVS', 'dist', 'build', '__buildlog')
    76 BASE_BLACKLIST = ('CVS', 'dist', 'build', '__buildlog')
    67 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
    77 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
    68 
    78 
    69 
    79 
    98 
   108 
    99 def export(from_dir, to_dir,
   109 def export(from_dir, to_dir,
   100            blacklist=BASE_BLACKLIST,
   110            blacklist=BASE_BLACKLIST,
   101            ignore_ext=IGNORED_EXTENSIONS,
   111            ignore_ext=IGNORED_EXTENSIONS,
   102            verbose=True):
   112            verbose=True):
   103     """make a mirror of from_dir in to_dir, omitting directories and files
       
   104     listed in the black list
       
   105     """
       
   106     def make_mirror(arg, directory, fnames):
       
   107         """walk handler"""
       
   108         for norecurs in blacklist:
       
   109             try:
       
   110                 fnames.remove(norecurs)
       
   111             except ValueError:
       
   112                 pass
       
   113         for filename in fnames:
       
   114             # don't include binary files
       
   115             if filename[-4:] in ignore_ext:
       
   116                 continue
       
   117             if filename[-1] == '~':
       
   118                 continue
       
   119             src = '%s/%s' % (directory, filename)
       
   120             dest = to_dir + src[len(from_dir):]
       
   121             if verbose:
       
   122                sys.stderr.write('%s -> %s\n' % (src, dest))
       
   123             if os.path.isdir(src):
       
   124                 if not exists(dest):
       
   125                     os.mkdir(dest)
       
   126             else:
       
   127                 if exists(dest):
       
   128                     os.remove(dest)
       
   129                 shutil.copy2(src, dest)
       
   130     try:
   113     try:
   131         os.mkdir(to_dir)
   114         os.mkdir(to_dir)
   132     except OSError as ex:
   115     except OSError as ex:
   133         # file exists ?
   116         # file exists ?
   134         import errno
   117         import errno
   135         if ex.errno != errno.EEXIST:
   118         if ex.errno != errno.EEXIST:
   136             raise
   119             raise
   137     walk(from_dir, make_mirror, None)
   120     for dirpath, dirnames, filenames in os.walk(from_dir):
       
   121         for norecurs in blacklist:
       
   122             try:
       
   123                 dirnames.remove(norecurs)
       
   124             except ValueError:
       
   125                 pass
       
   126         for dirname in dirnames:
       
   127             dest = join(to_dir, dirname)
       
   128             if not exists(dest):
       
   129                 os.mkdir(dest)
       
   130         for filename in filenames:
       
   131             # don't include binary files
       
   132             src = join(dirpath, filename)
       
   133             dest = to_dir + src[len(from_dir):]
       
   134             if filename[-4:] in ignore_ext:
       
   135                 continue
       
   136             if filename[-1] == '~':
       
   137                 continue
       
   138             if exists(dest):
       
   139                 os.remove(dest)
       
   140             shutil.copy2(src, dest)
   138 
   141 
   139 
   142 
   140 EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n'
   143 EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n'
   141 
   144 
   142 class MyInstallLib(install_lib.install_lib):
   145 class MyInstallLib(install_lib.install_lib):
   217         kwargs['package_dir'] = {package : '.'}
   220         kwargs['package_dir'] = {package : '.'}
   218         packages = [package] + get_packages(os.getcwd(), package)
   221         packages = [package] + get_packages(os.getcwd(), package)
   219         if USE_SETUPTOOLS:
   222         if USE_SETUPTOOLS:
   220             kwargs['namespace_packages'] = [subpackage_of]
   223             kwargs['namespace_packages'] = [subpackage_of]
   221     else:
   224     else:
   222         kwargs['package_dir'] = {modname : '.'}
   225         packages = [modname] + get_packages(join(here, modname), modname)
   223         packages = [modname] + get_packages(os.getcwd(), modname)
       
   224     if USE_SETUPTOOLS:
   226     if USE_SETUPTOOLS:
   225         kwargs['install_requires'] = install_requires
   227         kwargs['install_requires'] = install_requires
   226         kwargs['zip_safe'] = False
   228         kwargs['zip_safe'] = False
   227     kwargs['packages'] = packages
   229     kwargs['packages'] = packages
   228     kwargs['package_data'] = package_data
   230     kwargs['package_data'] = package_data