[pkg] update setup.py script to make it pip installable

authorDavid Douard <david.douard@logilab.fr>
changeseteb4912962171
branchdefault
phasepublic
hiddenno
parent revision#fd7910254c84 Added tag nazca-version-0.7.1, nazca-debian-version-0.7.1-1, nazca-centos-version-0.7.1-1 for changeset fdd8990beb40
child revision#2d44472e5d20 add dependency to lxml (closes #287976)
files modified by this revision
__pkginfo__.py
python-nazca.spec
setup.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1425563810 -3600
# Thu Mar 05 14:56:50 2015 +0100
# Node ID eb49129621715dddf42f270a0221356810c8f2cc
# Parent fd7910254c84d8548859e4f3709c834ef9b789a2
[pkg] update setup.py script to make it pip installable

diff --git a/__pkginfo__.py b/__pkginfo__.py
@@ -30,15 +30,30 @@
1  description = "Python library for data alignment"
2  web = "https://www.logilab.org/project/nazca"
3  author = "Logilab"
4  author_email = "contact@logilab.fr"
5 
6 +classifiers = [
7 +    'Programming Language :: Python',
8 +    'Topic :: Scientific/Engineering :: Information Analysis',
9 +    'Topic :: Software Development :: Libraries :: Python Modules',
10 +    'Topic :: Text Processing',
11 +]
12 +
13  __depends__ = {
14 +    'python-dateutil': None,
15 +    'lxml': None,
16 +    'numpy': None,
17      'scipy': None,
18      'scikit-learn': None,
19  }
20 
21 +__recommends__ = {
22 +    'sparqlwrapper': None,
23 +    'nltk': None,
24 +}
25 +
26  from os.path import join
27  include_dirs = [join('test', 'data'), 'data', 'examples', 'ner', 'rl', 'utils']
28 
29  if sys.version_info < (2, 7):
30 -    install_requires = ['unittest2 >= 0.5.1']
31 +    __depends__['unittest2'] = '>= 0.5.1'
diff --git a/python-nazca.spec b/python-nazca.spec
@@ -21,10 +21,11 @@
32 
33  BuildRequires:  %{python}
34  Requires:       %{python}
35  Requires:       scipy
36  Requires:       %{python}-sklearn
37 +Requires:       %{python}-dateutil
38 
39 
40  %description
41  Python library for data alignment
42 
diff --git a/setup.py b/setup.py
@@ -22,11 +22,11 @@
43  __docformat__ = "restructuredtext en"
44 
45  import os
46  import sys
47  import shutil
48 -from os.path import isdir, exists, join
49 +from os.path import isdir, exists, join, dirname
50 
51  try:
52      if os.environ.get('NO_SETUPTOOLS'):
53          raise ImportError()
54      from setuptools import setup
@@ -42,35 +42,52 @@
55      from distutils.command.build_py import build_py_2to3 as build_py
56  except ImportError:
57      # python2.x
58      from distutils.command.build_py import build_py
59 
60 -sys.modules.pop('__pkginfo__', None)
61 -# import optional features
62 -__pkginfo__ = __import__("__pkginfo__")
63 -# import required features
64 -from __pkginfo__ import modname, version, license, description, \
65 -     web, author, author_email
66 +
67 +# load metadata from the __pkginfo__.py file so there is no risk of conflict
68 +# see https://packaging.python.org/en/latest/single_source_version.html
69 +base_dir = dirname(__file__)
70 +
71 +pkginfo = {}
72 +with open(join(base_dir, "__pkginfo__.py")) as f:
73 +    exec(f.read(), pkginfo)
74 +
75 +# get required metadatas
76 +modname = pkginfo['modname']
77 +version = pkginfo['version']
78 +license = pkginfo['license']
79 +description = pkginfo['description']
80 +web = pkginfo['web']
81 +author = pkginfo['author']
82 +author_email = pkginfo['author_email']
83 +classifiers = pkginfo['classifiers']
84 
85 -distname = getattr(__pkginfo__, 'distname', modname)
86 -scripts = getattr(__pkginfo__, 'scripts', [])
87 -data_files = getattr(__pkginfo__, 'data_files', None)
88 -subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
89 -include_dirs = getattr(__pkginfo__, 'include_dirs', [])
90 -ext_modules = getattr(__pkginfo__, 'ext_modules', None)
91 -install_requires = getattr(__pkginfo__, 'install_requires', None)
92 -dependency_links = getattr(__pkginfo__, 'dependency_links', [])
93 +with open(join(base_dir, 'README')) as f:
94 +    long_description = f.read()
95 +
96 +# get optional metadatas
97 +distname = pkginfo.get('distname', modname)
98 +scripts = pkginfo.get('scripts', ())
99 +include_dirs = pkginfo.get('include_dirs', ())
100 +data_files = pkginfo.get('data_files', None)
101 +ext_modules = pkginfo.get('ext_modules', None)
102 +dependency_links = pkginfo.get('dependency_links', ())
103 +
104 +if USE_SETUPTOOLS:
105 +    requires = {}
106 +    for entry in ("__depends__", "__recommends__"):
107 +        requires.update(pkginfo.get(entry, {}))
108 +    install_requires = [("%s %s" % (d, v and v or "")).strip()
109 +                       for d, v in requires.iteritems()]
110 +else:
111 +    install_requires = []
112 
113  STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
114 -
115  IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
116 
117 -if exists('README'):
118 -    long_description = open('README').read()
119 -else:
120 -    long_description = ''
121 -
122  def ensure_scripts(linux_scripts):
123      """Creates the proper script names required for each platform
124      (taken from 4Suite)
125      """
126      from distutils import util
@@ -107,24 +124,13 @@
127      include_dirs variable if necessary
128      """
129      def run(self):
130          """overridden from install_lib class"""
131          install_lib.install_lib.run(self)
132 -        # create Products.__init__.py if needed
133 -        if subpackage_of:
134 -            product_init = join(self.install_dir, subpackage_of, '__init__.py')
135 -            if not exists(product_init):
136 -                self.announce('creating %s' % product_init)
137 -                stream = open(product_init, 'w')
138 -                stream.write(EMPTY_FILE)
139 -                stream.close()
140          # manually install included directories if any
141          if include_dirs:
142 -            if subpackage_of:
143 -                base = join(subpackage_of, modname)
144 -            else:
145 -                base = modname
146 +            base = modname
147              for directory in include_dirs:
148                  dest = join(self.install_dir, base, directory)
149                  shutil.rmtree(dest, ignore_errors=True)
150                  shutil.copytree(directory, dest)
151 
@@ -134,19 +140,12 @@
152          if '--force-manifest' in sys.argv:
153              sys.argv.remove('--force-manifest')
154      # install-layout option was introduced in 2.5.3-1~exp1
155      elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
156          sys.argv.remove('--install-layout=deb')
157 -    if subpackage_of:
158 -        package = subpackage_of + '.' + modname
159 -        kwargs['package_dir'] = {package : '.'}
160 -        packages = [package] + get_packages(os.getcwd(), package)
161 -        if USE_SETUPTOOLS:
162 -            kwargs['namespace_packages'] = [subpackage_of]
163 -    else:
164 -        kwargs['package_dir'] = {modname : '.'}
165 -        packages = [modname] + get_packages(os.getcwd(), modname)
166 +    kwargs['package_dir'] = {modname : '.'}
167 +    packages = [modname] + get_packages(os.getcwd(), modname)
168      if USE_SETUPTOOLS and install_requires:
169          kwargs['install_requires'] = install_requires
170          kwargs['dependency_links'] = dependency_links
171      kwargs['packages'] = packages
172      return setup(name = distname,