Commit 625e01cd authored by Julien Cristau's avatar Julien Cristau
Browse files

[pkg] Always use setuptools (closes #487330)

parent af1d69fcf218
......@@ -26,7 +26,6 @@ version = '.'.join([str(num) for num in numversion])
license = 'LGPL'
web = "http://www.logilab.org/project/%s" % distname
ftp = "ftp://ftp.logilab.org/pub/%s" % modname
mailinglist = "mailto://python-projects@lists.logilab.org"
description = "a library to convert from a MIME type to another"
......
......@@ -11,8 +11,6 @@
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export NO_SETUPTOOLS=1
include /usr/share/python/python.mk
# don't build the python3 package if python3 is < 3.3
py3k = $(subst python3.,,$(shell py3versions -d))
......
......@@ -29,8 +29,6 @@ from __future__ import print_function
__docformat__ = "restructuredtext en"
from logilab.mtconverter.__pkginfo__ import version as __version__
import locale
import mimetypes
import re
......@@ -44,6 +42,9 @@ from io import BytesIO
from six import text_type, binary_type, int2byte, unichr
from six.moves.html_entities import name2codepoint
import pkg_resources
__version__ = pkg_resources.get_distribution('logilab-mtconverter').version
try:
import chardet
except ImportError:
......
......@@ -44,7 +44,7 @@ find . -name '*.py' -type f -print0 | xargs -0 sed -i '1,3s;^#!.*python.*$;#! /
%install
rm -rf $RPM_BUILD_ROOT
NO_SETUPTOOLS=1 %{__python} setup.py install -O1 --skip-build --root="$RPM_BUILD_ROOT"
%{__python} setup.py install -O1 --skip-build --root="$RPM_BUILD_ROOT"
rm -rf $RPM_BUILD_ROOT%{_python_sitelib}/logilab/__init__.py*
%clean
......
......@@ -25,120 +25,45 @@ __docformat__ = "restructuredtext en"
import os
import sys
import shutil
from os.path import isdir, exists, join
from os.path import isdir, exists, join, dirname, abspath
try:
if os.environ.get('NO_SETUPTOOLS'):
raise ImportError()
from setuptools import setup
from setuptools.command import install_lib
USE_SETUPTOOLS = 1
except ImportError:
from distutils.core import setup
from distutils.command import install_lib
USE_SETUPTOOLS = 0
from setuptools import setup, find_packages
here = abspath(dirname(__file__))
# import optional features
__pkginfo__ = __import__("logilab.mtconverter.__pkginfo__").mtconverter.__pkginfo__
pkginfo = {}
with open(join(here, '__pkginfo__.py')) as f:
exec(f.read(), pkginfo)
# import required features
modname = __pkginfo__.modname
version = __pkginfo__.version
license = __pkginfo__.license
description = __pkginfo__.description
web = __pkginfo__.web
author = __pkginfo__.author
author_email = __pkginfo__.author_email
modname = pkginfo['modname']
version = pkginfo['version']
license = pkginfo['license']
description = pkginfo['description']
web = pkginfo['web']
author = pkginfo['author']
author_email = pkginfo['author_email']
distname = getattr(__pkginfo__, 'distname', modname)
scripts = getattr(__pkginfo__, 'scripts', [])
data_files = getattr(__pkginfo__, 'data_files', None)
subpackage_of = getattr(__pkginfo__, 'subpackage_of', None)
include_dirs = getattr(__pkginfo__, 'include_dirs', [])
ext_modules = getattr(__pkginfo__, 'ext_modules', None)
install_requires = getattr(__pkginfo__, 'install_requires', None)
dependency_links = getattr(__pkginfo__, 'dependency_links', [])
distname = pkginfo.get('distname', modname)
data_files = pkginfo.get('data_files', None)
subpackage_of = pkginfo.get('subpackage_of', None)
include_dirs = pkginfo.get('include_dirs', [])
ext_modules = pkginfo.get('ext_modules', None)
install_requires = pkginfo.get('install_requires', None)
dependency_links = pkginfo.get('dependency_links', [])
STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build')
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
if exists('README'):
long_description = open('README').read()
if exists(join(here, 'README')):
long_description = open(join(here, 'README')).read()
else:
long_description = ''
def ensure_scripts(linux_scripts):
"""Creates the proper script names required for each platform
(taken from 4Suite)
"""
from distutils import util
if util.get_platform()[:3] == 'win':
scripts_ = [script + '.bat' for script in linux_scripts]
else:
scripts_ = linux_scripts
return scripts_
def get_packages(directory, prefix):
"""return a list of subpackages for the given directory"""
result = []
for package in os.listdir(directory):
absfile = join(directory, package)
if isdir(absfile):
if exists(join(absfile, '__init__.py')) or \
package in ('test', 'tests'):
if prefix:
result.append('%s.%s' % (prefix, package))
else:
result.append(package)
result += get_packages(absfile, result[-1])
return result
EMPTY_FILE = '''"""generated file, don't modify or your data will be lost"""
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
pass
'''
class MyInstallLib(install_lib.install_lib):
"""extend install_lib command to handle package __init__.py and
include_dirs variable if necessary
"""
def run(self):
"""overridden from install_lib class"""
install_lib.install_lib.run(self)
# create Products.__init__.py if needed
if subpackage_of:
product_init = join(self.install_dir, subpackage_of, '__init__.py')
if not exists(product_init):
self.announce('creating %s' % product_init)
stream = open(product_init, 'w')
stream.write(EMPTY_FILE)
stream.close()
# manually install included directories if any
if include_dirs:
if subpackage_of:
base = join(subpackage_of, modname)
else:
base = modname
for directory in include_dirs:
dest = join(self.install_dir, base, directory)
shutil.rmtree(dest, ignore_errors=True)
shutil.copytree(directory, dest)
def install(**kwargs):
"""setup entry point"""
if USE_SETUPTOOLS:
if '--force-manifest' in sys.argv:
sys.argv.remove('--force-manifest')
package = subpackage_of + '.' + modname
packages = get_packages(os.getcwd(), '')
if USE_SETUPTOOLS:
kwargs['namespace_packages'] = [subpackage_of]
kwargs['install_requires'] = install_requires
kwargs['dependency_links'] = dependency_links
kwargs['packages'] = packages
return setup(name = distname,
version = version,
license = license,
......@@ -147,10 +72,11 @@ def install(**kwargs):
author = author,
author_email = author_email,
url = web,
scripts = ensure_scripts(scripts),
packages = find_packages(exclude=['test*']),
data_files = data_files,
ext_modules = ext_modules,
cmdclass = {'install_lib': MyInstallLib},
namespace_packages = [subpackage_of],
install_requires = install_requires,
**kwargs
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment