cChardet/setup.py

145 lines
5.6 KiB
Python
Raw Normal View History

2012-06-20 15:59:23 +00:00
#!/usr/bin/env python
# coding: utf-8
import os
import sys
import platform
2016-10-17 11:18:24 +00:00
import glob
import codecs
import re
2017-03-27 15:35:55 +00:00
from distutils.command.build_ext import build_ext
2013-06-09 10:37:34 +00:00
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
2017-03-27 15:35:55 +00:00
have_cython = True
try:
import Cython.Compiler.Main as cython_compiler
except ImportError:
have_cython = False
2012-06-26 07:00:39 +00:00
2017-03-27 15:35:55 +00:00
cchardet_dir = 'src/cchardet/'
uchardet_dir = 'src/ext/uchardet/src'
if have_cython:
2016-10-17 05:36:43 +00:00
pyx_sources = glob.glob(cchardet_dir + '*.pyx')
sys.stderr.write('cythonize: %r\n' % (pyx_sources,))
cython_compiler.compile(pyx_sources, options=cython_compiler.CompilationOptions(cplus=True))
2017-03-27 15:35:55 +00:00
2016-10-17 05:36:43 +00:00
cchardet_sources = glob.glob(cchardet_dir + '*.cpp')
2017-03-27 15:35:55 +00:00
sources = cchardet_sources
uchardet_sources = [
os.path.join(uchardet_dir, 'CharDistribution.cpp'),
os.path.join(uchardet_dir, 'JpCntx.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangArabicModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangBulgarianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangCroatianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangCzechModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangEsperantoModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangEstonianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangFinnishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangFrenchModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangDanishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangGermanModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangGreekModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangHungarianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangHebrewModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangIrishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangItalianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangLithuanianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangLatvianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangMalteseModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangPolishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangPortugueseModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangRomanianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangRussianModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSlovakModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSloveneModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSwedishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangSpanishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangThaiModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangTurkishModel.cpp'),
os.path.join(uchardet_dir, 'LangModels/LangVietnameseModel.cpp'),
os.path.join(uchardet_dir, 'nsHebrewProber.cpp'),
os.path.join(uchardet_dir, 'nsCharSetProber.cpp'),
os.path.join(uchardet_dir, 'nsBig5Prober.cpp'),
os.path.join(uchardet_dir, 'nsEUCJPProber.cpp'),
os.path.join(uchardet_dir, 'nsEUCKRProber.cpp'),
os.path.join(uchardet_dir, 'nsEUCTWProber.cpp'),
os.path.join(uchardet_dir, 'nsEscCharsetProber.cpp'),
os.path.join(uchardet_dir, 'nsEscSM.cpp'),
os.path.join(uchardet_dir, 'nsGB2312Prober.cpp'),
os.path.join(uchardet_dir, 'nsMBCSGroupProber.cpp'),
os.path.join(uchardet_dir, 'nsMBCSSM.cpp'),
os.path.join(uchardet_dir, 'nsSBCSGroupProber.cpp'),
os.path.join(uchardet_dir, 'nsSBCharSetProber.cpp'),
os.path.join(uchardet_dir, 'nsSJISProber.cpp'),
os.path.join(uchardet_dir, 'nsUTF8Prober.cpp'),
os.path.join(uchardet_dir, 'nsLatin1Prober.cpp'),
os.path.join(uchardet_dir, 'nsUniversalDetector.cpp'),
os.path.join(uchardet_dir, 'uchardet.cpp')
]
sources += uchardet_sources
2012-06-26 00:44:17 +00:00
macros = []
2012-07-07 03:44:19 +00:00
extra_compile_args = []
extra_link_args = []
2017-03-27 15:35:55 +00:00
# Debug
# extra_compile_args.append('-g')
# extra_link_args.append('-g')
2012-06-26 07:00:39 +00:00
2016-10-17 05:36:43 +00:00
cchardet_module = Extension(
'cchardet._cchardet',
sources=sources,
2017-03-27 15:35:55 +00:00
include_dirs=[uchardet_dir],
2016-10-17 05:36:43 +00:00
language='c++',
2012-06-26 07:00:39 +00:00
define_macros=macros,
)
2012-06-20 01:41:36 +00:00
2016-10-17 10:39:55 +00:00
def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
2017-03-27 15:35:55 +00:00
with codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'src', 'cchardet', 'version.py'), 'r', 'latin1') as fp:
2016-10-17 11:18:24 +00:00
try:
2017-03-27 15:35:55 +00:00
version = re.findall(r"^__version__ = '([^']+)'\r?$", fp.read(), re.M)[0]
2016-10-17 11:18:24 +00:00
except IndexError:
raise RuntimeError('Unable to determine version.')
2012-06-20 01:41:36 +00:00
setup(
2016-10-17 05:36:43 +00:00
name='cchardet',
author='PyYoshi',
2016-10-17 06:18:10 +00:00
author_email='myoshi321go@gmail.com',
2016-10-17 05:36:43 +00:00
url=r'https://github.com/PyYoshi/cChardet',
description='Universal encoding detector. This library is faster than chardet.',
2016-10-17 10:39:55 +00:00
long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))),
2016-11-04 03:17:18 +00:00
version=version,
2016-10-17 05:36:43 +00:00
license='MIT License',
classifiers=[
2013-05-08 05:16:01 +00:00
'License :: OSI Approved :: MIT License',
'Programming Language :: Cython',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries',
'Programming Language :: Python :: 2',
2016-10-17 10:39:55 +00:00
'Programming Language :: Python :: 2.7',
2013-05-08 05:16:01 +00:00
'Programming Language :: Python :: 3',
2016-10-17 10:39:55 +00:00
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
2017-01-08 03:48:59 +00:00
'Programming Language :: Python :: 3.6',
2013-05-08 05:16:01 +00:00
],
2016-10-17 05:36:43 +00:00
keywords=[
2012-06-20 15:59:23 +00:00
'cython',
'chardet',
'charsetdetect'
],
2016-10-17 05:36:43 +00:00
cmdclass={'build_ext': build_ext},
2017-03-27 15:35:55 +00:00
package_dir={'': 'src'},
2016-10-17 05:36:43 +00:00
packages=['cchardet', ],
ext_modules=[
cchardet_module
],
2013-08-03 12:40:25 +00:00
)