[pkg] Drop NO_SETUPTOOLS option
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 29 Jun 2016 10:35:22 +0200
changeset 11424 1451f040555f
parent 11417 5e5e224239c3
child 11425 740cc1e09322
[pkg] Drop NO_SETUPTOOLS option setuptools is the defacto standard nowadays. The only place where NO_SETUPTOOLS option was used is during packaging (RPM, Debian) and even in this context, it seems that setuptools is the way to go (see https://wiki.debian.org/Python/LibraryStyleGuide).
cubicweb.spec
cubicweb/skeleton/DISTNAME.spec.tmpl
cubicweb/skeleton/debian/rules
cubicweb/skeleton/setup.py
debian/rules
setup.py
--- a/cubicweb.spec	Fri Jul 08 09:59:18 2016 +0200
+++ b/cubicweb.spec	Wed Jun 29 10:35:22 2016 +0200
@@ -49,7 +49,7 @@
 %endif
 
 %install
-NO_SETUPTOOLS=1 %{__python} setup.py --quiet install --no-compile --prefix=%{_prefix} --root="$RPM_BUILD_ROOT"
+%{__python} setup.py --quiet install --no-compile --prefix=%{_prefix} --root="$RPM_BUILD_ROOT"
 mkdir -p $RPM_BUILD_ROOT/var/log/cubicweb
 
 %clean
--- a/cubicweb/skeleton/DISTNAME.spec.tmpl	Fri Jul 08 09:59:18 2016 +0200
+++ b/cubicweb/skeleton/DISTNAME.spec.tmpl	Wed Jun 29 10:35:22 2016 +0200
@@ -34,7 +34,7 @@
 %%endif
 
 %%install
-NO_SETUPTOOLS=1 %%{__python} setup.py --quiet install --no-compile --prefix=%%{_prefix} --root="$RPM_BUILD_ROOT"
+%%{__python} setup.py --quiet install --no-compile --prefix=%%{_prefix} --root="$RPM_BUILD_ROOT"
 # remove generated .egg-info file
 rm -rf $RPM_BUILD_ROOT/usr/lib/python*
 
--- a/cubicweb/skeleton/debian/rules	Fri Jul 08 09:59:18 2016 +0200
+++ b/cubicweb/skeleton/debian/rules	Wed Jun 29 10:35:22 2016 +0200
@@ -1,7 +1,5 @@
 #!/usr/bin/make -f
 
-export NO_SETUPTOOLS=1
-
 %:
 	dh $@ --with python2
 
--- a/cubicweb/skeleton/setup.py	Fri Jul 08 09:59:18 2016 +0200
+++ b/cubicweb/skeleton/setup.py	Wed Jun 29 10:35:22 2016 +0200
@@ -27,16 +27,8 @@
 import shutil
 from os.path import exists, join, dirname
 
-try:
-    if os.environ.get('NO_SETUPTOOLS'):
-        raise ImportError()  # do as there is no setuptools
-    from setuptools import setup
-    from setuptools.command import install_lib
-    USE_SETUPTOOLS = True
-except ImportError:
-    from distutils.core import setup
-    from distutils.command import install_lib
-    USE_SETUPTOOLS = False
+from setuptools import setup
+from setuptools.command import install_lib
 from distutils.command import install_data
 
 
@@ -68,14 +60,11 @@
 ext_modules = pkginfo.get('ext_modules', None)
 dependency_links = pkginfo.get('dependency_links', ())
 
-if USE_SETUPTOOLS:
-    requires = {}
-    for entry in ("__depends__",):  # "__recommends__"):
-        requires.update(pkginfo.get(entry, {}))
-    install_requires = [("%s %s" % (d, v and v or "")).strip()
-                        for d, v in requires.items()]
-else:
-    install_requires = []
+requires = {}
+for entry in ("__depends__",):  # "__recommends__"):
+    requires.update(pkginfo.get(entry, {}))
+install_requires = [("%s %s" % (d, v and v or "")).strip()
+                    for d, v in requires.items()]
 
 BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build')
 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
@@ -147,50 +136,47 @@
 
 # re-enable copying data files in sys.prefix
 old_install_data = install_data.install_data
-if USE_SETUPTOOLS:
-    # overwrite InstallData to use sys.prefix instead of the egg directory
-    class MyInstallData(old_install_data):
-        """A class that manages data files installation"""
-        def run(self):
-            _old_install_dir = self.install_dir
-            if self.install_dir.endswith('egg'):
-                self.install_dir = sys.prefix
-            old_install_data.run(self)
-            self.install_dir = _old_install_dir
-    try:
-        # only if easy_install available
-        import setuptools.command.easy_install  # noqa
-        # monkey patch: Crack SandboxViolation verification
-        from setuptools.sandbox import DirectorySandbox as DS
-        old_ok = DS._ok
+# overwrite InstallData to use sys.prefix instead of the egg directory
+class MyInstallData(old_install_data):
+    """A class that manages data files installation"""
+    def run(self):
+        _old_install_dir = self.install_dir
+        if self.install_dir.endswith('egg'):
+            self.install_dir = sys.prefix
+        old_install_data.run(self)
+        self.install_dir = _old_install_dir
+try:
+    # only if easy_install available
+    import setuptools.command.easy_install  # noqa
+    # monkey patch: Crack SandboxViolation verification
+    from setuptools.sandbox import DirectorySandbox as DS
+    old_ok = DS._ok
 
-        def _ok(self, path):
-            """Return True if ``path`` can be written during installation."""
-            out = old_ok(self, path)  # here for side effect from setuptools
-            realpath = os.path.normcase(os.path.realpath(path))
-            allowed_path = os.path.normcase(sys.prefix)
-            if realpath.startswith(allowed_path):
-                out = True
-            return out
-        DS._ok = _ok
-    except ImportError:
-        pass
+    def _ok(self, path):
+        """Return True if ``path`` can be written during installation."""
+        out = old_ok(self, path)  # here for side effect from setuptools
+        realpath = os.path.normcase(os.path.realpath(path))
+        allowed_path = os.path.normcase(sys.prefix)
+        if realpath.startswith(allowed_path):
+            out = True
+        return out
+    DS._ok = _ok
+except ImportError:
+    pass
 
 
 def install(**kwargs):
     """setup entry point"""
-    if USE_SETUPTOOLS:
-        if '--force-manifest' in sys.argv:
-            sys.argv.remove('--force-manifest')
+    if '--force-manifest' in sys.argv:
+        sys.argv.remove('--force-manifest')
     # install-layout option was introduced in 2.5.3-1~exp1
     elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
         sys.argv.remove('--install-layout=deb')
     cmdclass = {'install_lib': MyInstallLib}
-    if USE_SETUPTOOLS:
-        kwargs['install_requires'] = install_requires
-        kwargs['dependency_links'] = dependency_links
-        kwargs['zip_safe'] = False
-        cmdclass['install_data'] = MyInstallData
+    kwargs['install_requires'] = install_requires
+    kwargs['dependency_links'] = dependency_links
+    kwargs['zip_safe'] = False
+    cmdclass['install_data'] = MyInstallData
 
     return setup(name=distname,
                  version=version,
--- a/debian/rules	Fri Jul 08 09:59:18 2016 +0200
+++ b/debian/rules	Wed Jun 29 10:35:22 2016 +0200
@@ -8,7 +8,7 @@
 build: build-stamp
 build-stamp:
 	dh_testdir
-	NO_SETUPTOOLS=1 python setup.py build
+	python setup.py build
 	# cubicweb.foo needs to be importable by sphinx, so create a cubicweb symlink to the source dir
 	mkdir -p debian/pythonpath
 	ln -sf $(CURDIR)/cubicweb debian/pythonpath
@@ -34,7 +34,7 @@
 	dh_clean
 	dh_installdirs
 
-	NO_SETUPTOOLS=1 python setup.py -q install --no-compile --prefix=debian/tmp/usr
+	python setup.py -q install --no-compile --prefix=debian/tmp/usr
 
 	# Put all the python library and data in cubicweb-common
 	# and scripts in cubicweb-server
--- a/setup.py	Fri Jul 08 09:59:18 2016 +0200
+++ b/setup.py	Wed Jun 29 10:35:22 2016 +0200
@@ -27,16 +27,8 @@
 import shutil
 from os.path import dirname, exists, isdir, join
 
-try:
-    if os.environ.get('NO_SETUPTOOLS'):
-        raise ImportError() # do as there is no setuptools
-    from setuptools import setup
-    from setuptools.command import install_lib
-    USE_SETUPTOOLS = True
-except ImportError:
-    from distutils.core import setup
-    from distutils.command import install_lib
-    USE_SETUPTOOLS = False
+from setuptools import setup
+from setuptools.command import install_lib
 from distutils.command import install_data
 
 here = dirname(__file__)
@@ -58,14 +50,11 @@
     long_description = f.read()
 
 # import optional features
-if USE_SETUPTOOLS:
-    requires = {}
-    for entry in ("__depends__",): # "__recommends__"):
-        requires.update(__pkginfo__.get(entry, {}))
-    install_requires = [("%s %s" % (d, v and v or "")).strip()
-                       for d, v in requires.items()]
-else:
-    install_requires = []
+requires = {}
+for entry in ("__depends__",): # "__recommends__"):
+    requires.update(__pkginfo__.get(entry, {}))
+install_requires = [("%s %s" % (d, v and v or "")).strip()
+                   for d, v in requires.items()]
 
 distname = __pkginfo__.get('distname', modname)
 scripts = __pkginfo__.get('scripts', ())
@@ -169,46 +158,43 @@
         ini.close()
 
 # re-enable copying data files in sys.prefix
-if USE_SETUPTOOLS:
-    # overwrite MyInstallData to use sys.prefix instead of the egg directory
-    MyInstallMoreData = MyInstallData
-    class MyInstallData(MyInstallMoreData): # pylint: disable=E0102
-        """A class that manages data files installation"""
-        def run(self):
-            _old_install_dir = self.install_dir
-            if self.install_dir.endswith('egg'):
-                self.install_dir = sys.prefix
-            MyInstallMoreData.run(self)
-            self.install_dir = _old_install_dir
-    try:
-        import setuptools.command.easy_install # only if easy_install available
-        # monkey patch: Crack SandboxViolation verification
-        from setuptools.sandbox import DirectorySandbox as DS
-        old_ok = DS._ok
-        def _ok(self, path):
-            """Return True if ``path`` can be written during installation."""
-            out = old_ok(self, path) # here for side effect from setuptools
-            realpath = os.path.normcase(os.path.realpath(path))
-            allowed_path = os.path.normcase(sys.prefix)
-            if realpath.startswith(allowed_path):
-                out = True
-            return out
-        DS._ok = _ok
-    except ImportError:
-        pass
+# overwrite MyInstallData to use sys.prefix instead of the egg directory
+MyInstallMoreData = MyInstallData
+class MyInstallData(MyInstallMoreData): # pylint: disable=E0102
+    """A class that manages data files installation"""
+    def run(self):
+        _old_install_dir = self.install_dir
+        if self.install_dir.endswith('egg'):
+            self.install_dir = sys.prefix
+        MyInstallMoreData.run(self)
+        self.install_dir = _old_install_dir
+try:
+    import setuptools.command.easy_install # only if easy_install available
+    # monkey patch: Crack SandboxViolation verification
+    from setuptools.sandbox import DirectorySandbox as DS
+    old_ok = DS._ok
+    def _ok(self, path):
+        """Return True if ``path`` can be written during installation."""
+        out = old_ok(self, path) # here for side effect from setuptools
+        realpath = os.path.normcase(os.path.realpath(path))
+        allowed_path = os.path.normcase(sys.prefix)
+        if realpath.startswith(allowed_path):
+            out = True
+        return out
+    DS._ok = _ok
+except ImportError:
+    pass
 
 def install(**kwargs):
     """setup entry point"""
-    if USE_SETUPTOOLS:
-        if '--force-manifest' in sys.argv:
-            sys.argv.remove('--force-manifest')
+    if '--force-manifest' in sys.argv:
+        sys.argv.remove('--force-manifest')
     # install-layout option was introduced in 2.5.3-1~exp1
     elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
         sys.argv.remove('--install-layout=deb')
     packages = [modname] + get_packages(join(here, modname), modname)
-    if USE_SETUPTOOLS:
-        kwargs['install_requires'] = install_requires
-        kwargs['zip_safe'] = False
+    kwargs['install_requires'] = install_requires
+    kwargs['zip_safe'] = False
     kwargs['packages'] = packages
     kwargs['package_data'] = package_data
     return setup(name=distname, version=version, license=license, url=web,