cubicweb/skeleton/setup.py
changeset 11152 fccc6ddd975c
parent 11085 2c0541b6803f
child 11424 1451f040555f
equal deleted inserted replaced
11151:4259c55df3e7 11152:fccc6ddd975c
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
     2 # pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
     3 #
     3 #
     4 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 # copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 #
     6 #
     7 # This file is part of CubicWeb.
     7 # This file is part of a CubicWeb cube.
     8 #
     8 #
     9 # CubicWeb is free software: you can redistribute it and/or modify it under the
     9 # CubicWeb is free software: you can redistribute it and/or modify it under the
    10 # terms of the GNU Lesser General Public License as published by the Free
    10 # terms of the GNU Lesser General Public License as published by the Free
    11 # Software Foundation, either version 2.1 of the License, or (at your option)
    11 # Software Foundation, either version 2.1 of the License, or (at your option)
    12 # any later version.
    12 # any later version.
    23 __docformat__ = "restructuredtext en"
    23 __docformat__ = "restructuredtext en"
    24 
    24 
    25 import os
    25 import os
    26 import sys
    26 import sys
    27 import shutil
    27 import shutil
    28 from os.path import exists, join
    28 from os.path import exists, join, dirname
    29 
    29 
    30 try:
    30 try:
    31     if os.environ.get('NO_SETUPTOOLS'):
    31     if os.environ.get('NO_SETUPTOOLS'):
    32         raise ImportError()  # do as there is no setuptools
    32         raise ImportError()  # do as there is no setuptools
    33     from setuptools import setup
    33     from setuptools import setup
    37     from distutils.core import setup
    37     from distutils.core import setup
    38     from distutils.command import install_lib
    38     from distutils.command import install_lib
    39     USE_SETUPTOOLS = False
    39     USE_SETUPTOOLS = False
    40 from distutils.command import install_data
    40 from distutils.command import install_data
    41 
    41 
    42 # import required features
    42 
    43 from __pkginfo__ import modname, version, license, description, web, \
    43 # load metadata from the __pkginfo__.py file so there is no risk of conflict
    44     author, author_email, classifiers
    44 # see https://packaging.python.org/en/latest/single_source_version.html
    45 
    45 base_dir = dirname(__file__)
    46 if exists('README'):
    46 pkginfo = {}
    47     long_description = open('README').read()
    47 with open(join(base_dir, "__pkginfo__.py")) as f:
    48 else:
    48     exec(f.read(), pkginfo)
    49     long_description = ''
    49 
    50 
    50 # get required metadatas
    51 # import optional features
    51 modname = pkginfo['modname']
    52 import __pkginfo__
    52 version = pkginfo['version']
       
    53 license = pkginfo['license']
       
    54 description = pkginfo['description']
       
    55 web = pkginfo['web']
       
    56 author = pkginfo['author']
       
    57 author_email = pkginfo['author_email']
       
    58 classifiers = pkginfo['classifiers']
       
    59 
       
    60 with open(join(base_dir, 'README')) as f:
       
    61     long_description = f.read()
       
    62 
       
    63 # get optional metadatas
       
    64 distname = pkginfo.get('distname', modname)
       
    65 scripts = pkginfo.get('scripts', ())
       
    66 include_dirs = pkginfo.get('include_dirs', ())
       
    67 data_files = pkginfo.get('data_files', None)
       
    68 ext_modules = pkginfo.get('ext_modules', None)
       
    69 dependency_links = pkginfo.get('dependency_links', ())
       
    70 
    53 if USE_SETUPTOOLS:
    71 if USE_SETUPTOOLS:
    54     requires = {}
    72     requires = {}
    55     for entry in ("__depends__",):  # "__recommends__"):
    73     for entry in ("__depends__",):  # "__recommends__"):
    56         requires.update(getattr(__pkginfo__, entry, {}))
    74         requires.update(pkginfo.get(entry, {}))
    57     install_requires = [("%s %s" % (d, v and v or "")).strip()
    75     install_requires = [("%s %s" % (d, v and v or "")).strip()
    58                         for d, v in requires.items()]
    76                         for d, v in requires.items()]
    59 else:
    77 else:
    60     install_requires = []
    78     install_requires = []
    61 
    79 
    62 distname = getattr(__pkginfo__, 'distname', modname)
    80 BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build')
    63 scripts = getattr(__pkginfo__, 'scripts', ())
       
    64 include_dirs = getattr(__pkginfo__, 'include_dirs', ())
       
    65 data_files = getattr(__pkginfo__, 'data_files', None)
       
    66 ext_modules = getattr(__pkginfo__, 'ext_modules', None)
       
    67 dependency_links = getattr(__pkginfo__, 'dependency_links', ())
       
    68 
       
    69 BASE_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
       
    70 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
    81 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
    71 
    82 
    72 
    83 
    73 def ensure_scripts(linux_scripts):
    84 def ensure_scripts(linux_scripts):
    74     """
    85     """
    98         for norecurs in blacklist:
   109         for norecurs in blacklist:
    99             try:
   110             try:
   100                 dirnames.remove(norecurs)
   111                 dirnames.remove(norecurs)
   101             except ValueError:
   112             except ValueError:
   102                 pass
   113                 pass
   103         for dirname in dirnames:
   114         for dir_name in dirnames:
   104             dest = join(to_dir, dirname)
   115             dest = join(to_dir, dir_name)
   105             if not exists(dest):
   116             if not exists(dest):
   106                 os.mkdir(dest)
   117                 os.mkdir(dest)
   107         for filename in filenames:
   118         for filename in filenames:
   108             # don't include binary files
   119             # don't include binary files
   109             src = join(dirpath, filename)
   120             src = join(dirpath, filename)
   130         if include_dirs:
   141         if include_dirs:
   131             base = modname
   142             base = modname
   132             for directory in include_dirs:
   143             for directory in include_dirs:
   133                 dest = join(self.install_dir, base, directory)
   144                 dest = join(self.install_dir, base, directory)
   134                 export(directory, dest, verbose=False)
   145                 export(directory, dest, verbose=False)
       
   146 
   135 
   147 
   136 # re-enable copying data files in sys.prefix
   148 # re-enable copying data files in sys.prefix
   137 old_install_data = install_data.install_data
   149 old_install_data = install_data.install_data
   138 if USE_SETUPTOOLS:
   150 if USE_SETUPTOOLS:
   139     # overwrite InstallData to use sys.prefix instead of the egg directory
   151     # overwrite InstallData to use sys.prefix instead of the egg directory