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

authorDavid Douard <david.douard@logilab.fr>
changesetbad580932b19
branchdefault
phasedraft
hiddenyes
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#37c58cc0d694 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 bad580932b19e4061a3418cd54f295931694304f
# Parent fd7910254c84d8548859e4f3709c834ef9b789a2
[wip] [pkg] update setup.py script to make it pip installable

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