update setup.py

This commit is contained in:
PyYoshi 2017-03-28 10:29:07 +09:00
parent 1529daac97
commit fb8a7a2719

279
setup.py
View file

@ -1,146 +1,133 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
import os import os
import sys import sys
import platform import platform
import glob import glob
import codecs import codecs
import re import re
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils.core import setup, Extension
try:
from setuptools import setup, Extension have_cython = True
except ImportError: try:
from distutils.core import setup, Extension import Cython.Compiler.Main as cython_compiler
except ImportError:
have_cython = True have_cython = False
try:
import Cython.Compiler.Main as cython_compiler cchardet_dir = 'src/cchardet/'
except ImportError: uchardet_dir = 'src/ext/uchardet/src'
have_cython = False
if have_cython:
cchardet_dir = 'src/cchardet/' pyx_sources = glob.glob(cchardet_dir + '*.pyx')
uchardet_dir = 'src/ext/uchardet/src' sys.stderr.write('cythonize: %r\n' % (pyx_sources,))
cython_compiler.compile(pyx_sources, options=cython_compiler.CompilationOptions(cplus=True))
if have_cython:
pyx_sources = glob.glob(cchardet_dir + '*.pyx') cchardet_sources = glob.glob(cchardet_dir + '*.cpp')
sys.stderr.write('cythonize: %r\n' % (pyx_sources,)) sources = cchardet_sources
cython_compiler.compile(pyx_sources, options=cython_compiler.CompilationOptions(cplus=True))
uchardet_sources = [
cchardet_sources = glob.glob(cchardet_dir + '*.cpp') os.path.join(uchardet_dir, 'CharDistribution.cpp'),
sources = cchardet_sources os.path.join(uchardet_dir, 'JpCntx.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangArabicModel.cpp'),
uchardet_sources = [ os.path.join(uchardet_dir, 'LangModels/LangBulgarianModel.cpp'),
os.path.join(uchardet_dir, 'CharDistribution.cpp'), os.path.join(uchardet_dir, 'LangModels/LangCroatianModel.cpp'),
os.path.join(uchardet_dir, 'JpCntx.cpp'), os.path.join(uchardet_dir, 'LangModels/LangCzechModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangArabicModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangEsperantoModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangBulgarianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangEstonianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangCroatianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangFinnishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangCzechModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangFrenchModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangEsperantoModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangDanishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangEstonianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangGermanModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangFinnishModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangGreekModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangFrenchModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangHungarianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangDanishModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangHebrewModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangGermanModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangIrishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangGreekModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangItalianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangHungarianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangLithuanianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangHebrewModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangLatvianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangIrishModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangMalteseModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangItalianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangPolishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangLithuanianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangPortugueseModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangLatvianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangRomanianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangMalteseModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangRussianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangPolishModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangSlovakModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangPortugueseModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangSloveneModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangRomanianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangSwedishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangRussianModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangSpanishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSlovakModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangThaiModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSloveneModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangTurkishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSwedishModel.cpp'), os.path.join(uchardet_dir, 'LangModels/LangVietnameseModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSpanishModel.cpp'), os.path.join(uchardet_dir, 'nsHebrewProber.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangThaiModel.cpp'), os.path.join(uchardet_dir, 'nsCharSetProber.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangTurkishModel.cpp'), os.path.join(uchardet_dir, 'nsBig5Prober.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangVietnameseModel.cpp'), os.path.join(uchardet_dir, 'nsEUCJPProber.cpp'),
os.path.join(uchardet_dir, 'nsHebrewProber.cpp'), os.path.join(uchardet_dir, 'nsEUCKRProber.cpp'),
os.path.join(uchardet_dir, 'nsCharSetProber.cpp'), os.path.join(uchardet_dir, 'nsEUCTWProber.cpp'),
os.path.join(uchardet_dir, 'nsBig5Prober.cpp'), os.path.join(uchardet_dir, 'nsEscCharsetProber.cpp'),
os.path.join(uchardet_dir, 'nsEUCJPProber.cpp'), os.path.join(uchardet_dir, 'nsEscSM.cpp'),
os.path.join(uchardet_dir, 'nsEUCKRProber.cpp'), os.path.join(uchardet_dir, 'nsGB2312Prober.cpp'),
os.path.join(uchardet_dir, 'nsEUCTWProber.cpp'), os.path.join(uchardet_dir, 'nsMBCSGroupProber.cpp'),
os.path.join(uchardet_dir, 'nsEscCharsetProber.cpp'), os.path.join(uchardet_dir, 'nsMBCSSM.cpp'),
os.path.join(uchardet_dir, 'nsEscSM.cpp'), os.path.join(uchardet_dir, 'nsSBCSGroupProber.cpp'),
os.path.join(uchardet_dir, 'nsGB2312Prober.cpp'), os.path.join(uchardet_dir, 'nsSBCharSetProber.cpp'),
os.path.join(uchardet_dir, 'nsMBCSGroupProber.cpp'), os.path.join(uchardet_dir, 'nsSJISProber.cpp'),
os.path.join(uchardet_dir, 'nsMBCSSM.cpp'), os.path.join(uchardet_dir, 'nsUTF8Prober.cpp'),
os.path.join(uchardet_dir, 'nsSBCSGroupProber.cpp'), os.path.join(uchardet_dir, 'nsLatin1Prober.cpp'),
os.path.join(uchardet_dir, 'nsSBCharSetProber.cpp'), os.path.join(uchardet_dir, 'nsUniversalDetector.cpp'),
os.path.join(uchardet_dir, 'nsSJISProber.cpp'), os.path.join(uchardet_dir, 'uchardet.cpp')
os.path.join(uchardet_dir, 'nsUTF8Prober.cpp'), ]
os.path.join(uchardet_dir, 'nsLatin1Prober.cpp'), sources += uchardet_sources
os.path.join(uchardet_dir, 'nsUniversalDetector.cpp'),
os.path.join(uchardet_dir, 'uchardet.cpp') cchardet_module = Extension(
] 'cchardet._cchardet',
sources += uchardet_sources sources=sources,
include_dirs=[uchardet_dir],
macros = [] language='c++',
extra_compile_args = [] )
extra_link_args = []
def read(f):
# Debug return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
# extra_compile_args.append('-g')
# extra_link_args.append('-g') with codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src', 'cchardet', 'version.py'), 'r', 'latin1') as fp:
try:
cchardet_module = Extension( version = re.findall(r"^__version__ = '([^']+)'\r?$", fp.read(), re.M)[0]
'cchardet._cchardet', except IndexError:
sources=sources, raise RuntimeError('Unable to determine version.')
include_dirs=[uchardet_dir],
language='c++', setup(
define_macros=macros, name='cchardet',
) author='PyYoshi',
author_email='myoshi321go@gmail.com',
def read(f): url=r'https://github.com/PyYoshi/cChardet',
return open(os.path.join(os.path.dirname(__file__), f)).read().strip() description='cChardet is high speed universal character encoding detector.',
long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))),
with codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src', 'cchardet', 'version.py'), 'r', 'latin1') as fp: version=version,
try: license='Mozilla Public License',
version = re.findall(r"^__version__ = '([^']+)'\r?$", fp.read(), re.M)[0] classifiers=[
except IndexError: 'License :: OSI Approved :: Mozilla Public License 1.1 (MPL 1.1)',
raise RuntimeError('Unable to determine version.') 'License :: OSI Approved :: GNU General Public License (GPL)',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
setup( 'Programming Language :: Cython',
name='cchardet', 'Programming Language :: Python',
author='PyYoshi', 'Topic :: Software Development :: Libraries',
author_email='myoshi321go@gmail.com', 'Programming Language :: Python :: 2',
url=r'https://github.com/PyYoshi/cChardet', 'Programming Language :: Python :: 2.7',
description='Universal encoding detector. This library is faster than chardet.', 'Programming Language :: Python :: 3',
long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))), 'Programming Language :: Python :: 3.4',
version=version, 'Programming Language :: Python :: 3.5',
license='Mozilla Public License', 'Programming Language :: Python :: 3.6',
classifiers=[ ],
'License :: OSI Approved :: Mozilla Public License 1.1 (MPL 1.1)', keywords=[
'License :: OSI Approved :: GNU General Public License (GPL)', 'cython',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)', 'chardet',
'Programming Language :: Cython', 'charsetdetect'
'Programming Language :: Python', ],
'Topic :: Software Development :: Libraries', cmdclass={'build_ext': build_ext},
'Programming Language :: Python :: 2', package_dir={'': 'src'},
'Programming Language :: Python :: 2.7', packages=['cchardet', ],
'Programming Language :: Python :: 3', ext_modules=[
'Programming Language :: Python :: 3.4', cchardet_module
'Programming Language :: Python :: 3.5', ],
'Programming Language :: Python :: 3.6', )
],
keywords=[
'cython',
'chardet',
'charsetdetect'
],
cmdclass={'build_ext': build_ext},
package_dir={'': 'src'},
packages=['cchardet', ],
ext_modules=[
cchardet_module
],
)