[pkg] pure setuptools setup.py (closes #294479)

  • stop installing __pkginfo__ (move it back to root dir)
  • adapt all packaging to use setuptools
authorRémi Cardona <remi.cardona@logilab.fr>
changeset6db240fd8b0c
branchdefault
phasepublic
hiddenno
parent revision#205b979c05a6 Stop importing __pkginfo__
child revision#dc2276e74f82 [debian] don't call setup.py with -q
files modified by this revision
__pkginfo__.py
debian/control
debian/rules
logilab/common/__pkginfo__.py
python-logilab-common.spec
setup.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@logilab.fr>
# Date 1432816765 -7200
# Thu May 28 14:39:25 2015 +0200
# Node ID 6db240fd8b0cafbb6b4898639ca61b9b4966e1ea
# Parent 205b979c05a69c14a78d49c43c31192d243375d8
[pkg] pure setuptools setup.py (closes #294479)

- stop installing __pkginfo__ (move it back to root dir)
- adapt all packaging to use setuptools

diff --git a/logilab/common/__pkginfo__.py b/__pkginfo__.py
@@ -41,11 +41,11 @@
1  include_dirs = [join('test', 'data')]
2 
3  install_requires = [
4          'six >= 1.4.0',
5          ]
6 -test_require = ['pytz']
7 +tests_require = ['pytz']
8 
9  if sys.version_info < (2, 7):
10      install_requires.append('unittest2 >= 0.5.1')
11  if os.name == 'nt':
12      install_requires.append('colorama')
diff --git a/debian/control b/debian/control
@@ -8,11 +8,13 @@
13  	   Adrien Di Mascio <Adrien.DiMascio@logilab.fr>,
14  	   Nicolas Chauvat <nicolas.chauvat@logilab.fr>,
15  Build-Depends:
16   debhelper (>= 8),
17   python-all,
18 + python-setuptools,
19   python3-all,
20 + python3-setuptools,
21  Build-Depends-Indep:
22   python-epydoc,
23   graphviz,
24   python-unittest2,
25   python-egenix-mxdatetime,
diff --git a/debian/rules b/debian/rules
@@ -30,23 +30,23 @@
26  	dh $@ --with python2,python3
27 
28  override_dh_auto_build:
29  	dh_auto_build
30  ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
31 -	NO_SETUPTOOLS=1 python setup.py -q build --build-purelib build/lib
32 +	python setup.py -q build --build-purelib build/lib
33  	$(MAKE) -C doc
34  endif
35 
36  override_dh_auto_install:
37 -	NO_SETUPTOOLS=1 python setup.py -q install --no-compile \
38 +	python setup.py -q install --no-compile \
39  	                --root=$(CURDIR)/debian/$(PACKAGE)/ \
40  	                ${py_setup_install_args}
41  	# remove test directory
42  	rm -rf debian/$(PACKAGE)/$(PYLIB)/logilab/common/test
43 
44  ifneq (,$(build_py3k))
45 -	NO_SETUPTOOLS=1 python3 setup.py -q install --no-compile \
46 +	python3 setup.py -q install --no-compile \
47  	                --root=$(CURDIR)/debian/$(PACKAGE3)/ \
48  	                ${py_setup_install_args}
49  	# remove test directory
50  	rm -rf debian/$(PACKAGE3)/$(PYLIB3)/logilab/common/test
51 
@@ -64,30 +64,19 @@
52  	dh_installdocs doc/apidoc/
53  endif
54 
55  override_dh_auto_test:
56  ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
57 -	# PYTHON 2.X
58 -	# IMPORTANT: Install command was overriden by Logilab to install data test files.
59 -	NO_SETUPTOOLS=1 python setup.py -q install --no-compile \
60 -	                --root=$(CURDIR)/testing/ ${py_setup_install_args}
61 -	# since "logilab.common" is a namespace package, we need to "simulate" it
62 -	touch $(CURDIR)/testing/$(PYLIB)/logilab/__init__.py
63 -	# use the default python version to select the script dir to run the tests
64 -	PYTHONPATH=$(CURDIR)/testing/$(PYLIB) python $(CURDIR)/testing/usr/bin/pytest -t $(CURDIR)/testing/$(PYLIB)/logilab/common/test
65 -	rm -rf $(CURDIR)/testing
66 -	
67 +	python setup.py -q install \
68 +                --root=$(CURDIR)/testing/ ${py_setup_install_args}
69 +	echo 'import site, os.path; site.addsitedir(os.path.dirname(__file__))' > testing/$(PYLIB)/sitecustomize.py
70 +	PYTHONPATH=$(CURDIR)/testing/$(PYLIB) python bin/pytest -t $(CURDIR)/test
71  ifneq (,$(build_py3k))
72 -	# PYTHON 3.x
73 -	# IMPORTANT: Install command was overriden by Logilab to install data test files.
74 -	NO_SETUPTOOLS=1 python3 setup.py -q install --no-compile \
75 -	                --root=$(CURDIR)/testing/ ${py_setup_install_args}
76 -	# since "logilab.common" is a namespace package, we need to "simulate" it
77 -	touch $(CURDIR)/testing/$(PYLIB3)/logilab/__init__.py
78 -	# use python3 version to run pytest
79 -	-PYTHONPATH=$(CURDIR)/testing/$(PYLIB3) python3 $(CURDIR)/testing/usr/bin/pytest -t $(CURDIR)/testing/$(PYLIB3)/logilab/common/test
80 -	rm -rf $(CURDIR)/testing
81 +	python3 setup.py -q install \
82 +		--root=$(CURDIR)/testing/ ${py_setup_install_args}
83 +	echo 'import site, os.path; site.addsitedir(os.path.dirname(__file__))' > testing/$(PYLIB3)/sitecustomize.py
84 +	PYTHONPATH=$(CURDIR)/testing/$(PYLIB3) python3 bin/pytest -t $(CURDIR)/test
85  endif
86  endif
87 
88  override_dh_compress:
89  	dh_compress -X.py -X.ini -X.xml -Xtest/ -Xapidoc/
diff --git a/python-logilab-common.spec b/python-logilab-common.spec
@@ -21,10 +21,11 @@
90  BuildArch:      noarch
91  BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
92 
93  BuildRequires:  python-devel python-setuptools python-unittest2 pytz
94  Requires:       mx
95 +Requires:       python-setuptools
96  Requires:       %{python}-six >= 1.4.0
97 
98 
99  %description
100  This package contains several modules providing low level functionality 
@@ -43,11 +44,11 @@
101  %endif
102 
103 
104  %install
105  rm -rf $RPM_BUILD_ROOT
106 -NO_SETUPTOOLS=1 %{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT %{?python_scriptarch: --install-scripts=%{python_scriptarch}}
107 +%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT %{?python_scriptarch: --install-scripts=%{python_scriptarch}}
108  rm -rf $RPM_BUILD_ROOT%{_python_sitelib}/logilab/common/test
109 
110  %check
111  %{__python} setup.py test
112 
diff --git a/setup.py b/setup.py
@@ -1,9 +1,8 @@
113  #!/usr/bin/env python
114 -# -*- coding: utf-8 -*-
115 -# pylint: disable=W0404,W0622,W0704,W0613
116 -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
117 +# pylint: disable=W0404,W0622,W0704,W0613,W0152
118 +# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
119  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
120  #
121  # This file is part of logilab-common.
122  #
123  # logilab-common is free software: you can redistribute it and/or modify it under
@@ -20,159 +19,36 @@
124  # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
125  """Generic Setup script, takes package info from __pkginfo__.py file.
126  """
127  __docformat__ = "restructuredtext en"
128 
129 -import os
130 -import sys
131 -import shutil
132 -from os.path import isdir, exists, join
133 -
134 -try:
135 -    if os.environ.get('NO_SETUPTOOLS'):
136 -        raise ImportError()
137 -    from setuptools import setup
138 -    from setuptools.command import install_lib
139 -    USE_SETUPTOOLS = 1
140 -except ImportError:
141 -    from distutils.core import setup
142 -    from distutils.command import install_lib
143 -    USE_SETUPTOOLS = 0
144 -
145 -from distutils.command.build_py import build_py
146 -
147 -# import optional features
148 -__pkginfo__ = __import__("logilab.common.__pkginfo__").common.__pkginfo__
149 -
150 -
151 -# import required features
152 -modname = __pkginfo__.modname
153 -version = __pkginfo__.version
154 -license = __pkginfo__.license
155 -description = __pkginfo__.description
156 -web = __pkginfo__.web
157 -author = __pkginfo__.author
158 -author_email = __pkginfo__.author_email
159 -
160 -distname = getattr(__pkginfo__, 'distname', modname)
161 -scripts = getattr(__pkginfo__, 'scripts', [])
162 -data_files = getattr(__pkginfo__, 'data_files', None)
163 -subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
164 -include_dirs = getattr(__pkginfo__, 'include_dirs', [])
165 -ext_modules = getattr(__pkginfo__, 'ext_modules', None)
166 -install_requires = getattr(__pkginfo__, 'install_requires', None)
167 -test_require = getattr(__pkginfo__, 'test_require', None)
168 -dependency_links = getattr(__pkginfo__, 'dependency_links', [])
169 -classifiers = getattr(__pkginfo__, 'classifiers', [])
170 -
171 -STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
172 -
173 -IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
174 -
175 -if exists('README'):
176 -    long_description = open('README').read()
177 -else:
178 -    long_description = ''
179 -
180 -def ensure_scripts(linux_scripts):
181 -    """Creates the proper script names required for each platform
182 -    (taken from 4Suite)
183 -    """
184 -    from distutils import util
185 -    if util.get_platform()[:3] == 'win':
186 -        scripts_ = [script + '.bat' for script in linux_scripts]
187 -    else:
188 -        scripts_ = linux_scripts
189 -    return scripts_
190 -
191 -def get_packages(directory, prefix):
192 -    """return a list of subpackages for the given directory"""
193 -    result = []
194 -    for package in os.listdir(directory):
195 -        absfile = join(directory, package)
196 -        if isdir(absfile):
197 -            if exists(join(absfile, '__init__.py')) or \
198 -                   package in ('test', 'tests'):
199 -                if prefix:
200 -                    result.append('%s.%s' % (prefix, package))
201 -                else:
202 -                    result.append(package)
203 -                result += get_packages(absfile, result[-1])
204 -    return result
205 +from setuptools import setup, find_packages
206 +from io import open
207 +from os import path
208 
209 -EMPTY_FILE = '''"""generated file, don't modify or your data will be lost"""
210 -try:
211 -    __import__('pkg_resources').declare_namespace(__name__)
212 -except ImportError:
213 -    pass
214 -'''
215 -
216 -class MyInstallLib(install_lib.install_lib):
217 -    """extend install_lib command to handle package __init__.py if necessary
218 -    """
219 -    def run(self):
220 -        """overridden from install_lib class"""
221 -        install_lib.install_lib.run(self)
222 -        # create Products.__init__.py if needed
223 -        if subpackage_of:
224 -            product_init = join(self.install_dir, subpackage_of, '__init__.py')
225 -            if not exists(product_init):
226 -                self.announce('creating %s' % product_init)
227 -                stream = open(product_init, 'w')
228 -                stream.write(EMPTY_FILE)
229 -                stream.close()
230 -
231 +here = path.abspath(path.dirname(__file__))
232 
233 -class MyBuildPy(build_py):
234 -    """extend build_by command to handle include_dirs variable if necessary
235 -    """
236 -    def run(self):
237 -        """overridden from install_lib class"""
238 -        build_py.run(self)
239 -        # manually install included directories if any
240 -        if include_dirs:
241 -            if subpackage_of:
242 -                base = join(subpackage_of, modname)
243 -            else:
244 -                base = modname
245 -            basedir = os.path.join(self.build_lib, base)
246 -            for directory in include_dirs:
247 -                dest = join(basedir, directory)
248 -                shutil.rmtree(dest, ignore_errors=True)
249 -                shutil.copytree(directory, dest)
250 -
251 +pkginfo = {}
252 +with open(path.join(here, '__pkginfo__.py')) as f:
253 +    exec(f.read(), pkginfo)
254 
255 -def install(**kwargs):
256 -    """setup entry point"""
257 -    if USE_SETUPTOOLS:
258 -        if '--force-manifest' in sys.argv:
259 -            sys.argv.remove('--force-manifest')
260 -    # install-layout option was introduced in 2.5.3-1~exp1
261 -    elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
262 -        sys.argv.remove('--install-layout=deb')
263 -    package = subpackage_of + '.' + modname
264 -    packages = get_packages(os.getcwd(), '')
265 -    if USE_SETUPTOOLS:
266 -        kwargs['namespace_packages'] = [subpackage_of]
267 -        kwargs['install_requires'] = install_requires
268 -        kwargs['test_require'] = test_require
269 -        kwargs['dependency_links'] = dependency_links
270 -    kwargs['packages'] = packages
271 -    return setup(name = distname,
272 -                 version = version,
273 -                 license = license,
274 -                 description = description,
275 -                 long_description = long_description,
276 -                 classifiers = classifiers,
277 -                 author = author,
278 -                 author_email = author_email,
279 -                 url = web,
280 -                 scripts = ensure_scripts(scripts),
281 -                 data_files = data_files,
282 -                 ext_modules = ext_modules,
283 -                 cmdclass = {'install_lib': MyInstallLib,
284 -                             'build_py': MyBuildPy},
285 -                 **kwargs
286 -                 )
287 +# Get the long description from the relevant file
288 +with open(path.join(here, 'README'), encoding='utf-8') as f:
289 +    long_description = f.read()
290 
291 -if __name__ == '__main__' :
292 -    install()
293 +setup(
294 +    name=pkginfo['distname'],
295 +    version=pkginfo['version'],
296 +    description=pkginfo['description'],
297 +    long_description=long_description,
298 +    url=pkginfo['web'],
299 +    author=pkginfo['author'],
300 +    author_email=pkginfo['author_email'],
301 +    license=pkginfo['license'],
302 +    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
303 +    classifiers=pkginfo['classifiers'],
304 +    packages=find_packages(exclude=['contrib', 'docs', 'test*']),
305 +    namespace_packages=[pkginfo['subpackage_of']],
306 +    install_requires=pkginfo['install_requires'],
307 +    tests_require=pkginfo['tests_require'],
308 +    scripts=pkginfo['scripts'],
309 +)