1
- # coding: utf-8
2
-
3
- from __future__ import with_statement , print_function , absolute_import
4
-
5
- from setuptools import setup , find_packages , Extension
6
- import setuptools .command .develop
7
- import setuptools .command .build_py
8
- from distutils .version import LooseVersion
9
- import subprocess
10
- import numpy as np
11
1
import os
2
+ import subprocess
3
+ from distutils .version import LooseVersion
12
4
from glob import glob
13
- from os .path import join , exists
5
+ from os .path import exists , join
14
6
from subprocess import run
15
7
16
- version = '0.0.3'
8
+ import numpy as np
9
+ import setuptools .command .build_py
10
+ import setuptools .command .develop
11
+ from setuptools import Extension , find_packages , setup
12
+
13
+ version = "0.0.3"
17
14
18
- min_cython_ver = ' 0.21.0'
15
+ min_cython_ver = " 0.21.0"
19
16
try :
20
17
import Cython
18
+
21
19
ver = Cython .__version__
22
20
_CYTHON_INSTALLED = ver >= LooseVersion (min_cython_ver )
23
21
except ImportError :
24
22
_CYTHON_INSTALLED = False
25
23
26
24
try :
27
25
if not _CYTHON_INSTALLED :
28
- raise ImportError ('No supported version of Cython installed.' )
29
- from Cython .Distutils import build_ext
26
+ raise ImportError ("No supported version of Cython installed." )
30
27
from Cython .Build import cythonize
28
+ from Cython .Distutils import build_ext
29
+
31
30
cython = True
32
31
except ImportError :
33
32
cython = False
34
33
35
34
if cython :
36
- ext = ' .pyx'
37
- cmdclass = {' build_ext' : build_ext }
35
+ ext = " .pyx"
36
+ cmdclass = {" build_ext" : build_ext }
38
37
else :
39
- ext = ' .cpp'
38
+ ext = " .cpp"
40
39
cmdclass = {}
41
40
if not os .path .exists (join ("pyopenjtalk" , "openjtalk" + ext )):
42
41
raise RuntimeError ("Cython is required to generate C++ code" )
59
58
all_src = []
60
59
include_dirs = []
61
60
for s in [
62
- "jpcommon" , "mecab/src" , "mecab2njd" , "njd" , "njd2jpcommon" ,
63
- "njd_set_accent_phrase" , "njd_set_accent_type" ,
64
- "njd_set_digit" , "njd_set_long_vowel" , "njd_set_pronunciation" ,
65
- "njd_set_unvoiced_vowel" , "text2mecab" ,
61
+ "jpcommon" ,
62
+ "mecab/src" ,
63
+ "mecab2njd" ,
64
+ "njd" ,
65
+ "njd2jpcommon" ,
66
+ "njd_set_accent_phrase" ,
67
+ "njd_set_accent_type" ,
68
+ "njd_set_digit" ,
69
+ "njd_set_long_vowel" ,
70
+ "njd_set_pronunciation" ,
71
+ "njd_set_unvoiced_vowel" ,
72
+ "text2mecab" ,
66
73
]:
67
74
all_src += glob (join (src_top , s , "*.c" ))
68
75
all_src += glob (join (src_top , s , "*.cpp" ))
69
76
include_dirs .append (join (os .getcwd (), src_top , s ))
70
77
71
- # define core cython module
72
- ext_modules = [Extension (
73
- name = "pyopenjtalk.openjtalk" ,
74
- sources = [join ("pyopenjtalk" , "openjtalk" + ext )] + all_src ,
75
- include_dirs = [np .get_include ()] + include_dirs ,
76
- extra_compile_args = [],
77
- extra_link_args = [],
78
- language = "c++" ,
79
- define_macros = [
80
- ("HAVE_CONFIG_H" , None ),
81
- ("DIC_VERSION" , 102 ), ("MECAB_DEFAULT_RC" , "\" dummy\" " ),
82
- ("PACKAGE" , "\" open_jtalk\" " ),
83
- ("VERSION" , "\" 1.10\" " ),
84
- ("CHARSET_UTF_8" , None ),
85
- ]
86
- )]
78
+ # Extension for OpenJTalk frontend
79
+ ext_modules = [
80
+ Extension (
81
+ name = "pyopenjtalk.openjtalk" ,
82
+ sources = [join ("pyopenjtalk" , "openjtalk" + ext )] + all_src ,
83
+ include_dirs = [np .get_include ()] + include_dirs ,
84
+ extra_compile_args = [],
85
+ extra_link_args = [],
86
+ language = "c++" ,
87
+ define_macros = [
88
+ ("HAVE_CONFIG_H" , None ),
89
+ ("DIC_VERSION" , 102 ),
90
+ ("MECAB_DEFAULT_RC" , '"dummy"' ),
91
+ ("PACKAGE" , '"open_jtalk"' ),
92
+ ("VERSION" , '"1.10"' ),
93
+ ("CHARSET_UTF_8" , None ),
94
+ ],
95
+ )
96
+ ]
97
+
98
+ # Extension for HTSEngine backend
99
+ htsengine_src_top = join ("lib" , "hts_engine_API" , "src" )
100
+ all_htsengine_src = glob (join (htsengine_src_top , "lib" , "*.c" ))
101
+ ext_modules += [
102
+ Extension (
103
+ name = "pyopenjtalk.htsengine" ,
104
+ sources = [join ("pyopenjtalk" , "htsengine" + ext )] + all_htsengine_src ,
105
+ include_dirs = [np .get_include (), join (htsengine_src_top , "include" )],
106
+ extra_compile_args = [],
107
+ extra_link_args = [],
108
+ language = "c++" ,
109
+ )
110
+ ]
87
111
88
112
# Adapted from https://github.com/pytorch/pytorch
89
113
cwd = os .path .dirname (os .path .abspath (__file__ ))
90
- if os .getenv (' PYOPENJTALK_BUILD_VERSION' ):
91
- version = os .getenv (' PYOPENJTALK_BUILD_VERSION' )
114
+ if os .getenv (" PYOPENJTALK_BUILD_VERSION" ):
115
+ version = os .getenv (" PYOPENJTALK_BUILD_VERSION" )
92
116
else :
93
117
try :
94
- sha = subprocess .check_output (
95
- ['git' , 'rev-parse' , 'HEAD' ], cwd = cwd ).decode ('ascii' ).strip ()
96
- version += '+' + sha [:7 ]
118
+ sha = (
119
+ subprocess .check_output (["git" , "rev-parse" , "HEAD" ], cwd = cwd )
120
+ .decode ("ascii" )
121
+ .strip ()
122
+ )
123
+ version += "+" + sha [:7 ]
97
124
except subprocess .CalledProcessError :
98
125
pass
99
126
except IOError : # FileNotFoundError for python 3
100
127
pass
101
128
102
129
103
130
class build_py (setuptools .command .build_py .build_py ):
104
-
105
131
def run (self ):
106
132
self .create_version_file ()
107
133
setuptools .command .build_py .build_py .run (self )
108
134
109
135
@staticmethod
110
136
def create_version_file ():
111
137
global version , cwd
112
- print (' -- Building version ' + version )
113
- version_path = os .path .join (cwd , ' pyopenjtalk' , ' version.py' )
114
- with open (version_path , 'w' ) as f :
138
+ print (" -- Building version " + version )
139
+ version_path = os .path .join (cwd , " pyopenjtalk" , " version.py" )
140
+ with open (version_path , "w" ) as f :
115
141
f .write ("__version__ = '{}'\n " .format (version ))
116
142
117
143
118
144
class develop (setuptools .command .develop .develop ):
119
-
120
145
def run (self ):
121
146
build_py .create_version_file ()
122
147
setuptools .command .develop .develop .run (self )
123
148
124
149
125
- cmdclass [' build_py' ] = build_py
126
- cmdclass [' develop' ] = develop
150
+ cmdclass [" build_py" ] = build_py
151
+ cmdclass [" develop" ] = develop
127
152
128
153
129
- with open (' README.md' , 'r' ) as fd :
154
+ with open (" README.md" , "r" ) as fd :
130
155
long_description = fd .read ()
131
156
132
157
setup (
133
- name = ' pyopenjtalk' ,
158
+ name = " pyopenjtalk" ,
134
159
version = version ,
135
- description = ' A python wrapper for OpenJTalk' ,
160
+ description = " A python wrapper for OpenJTalk" ,
136
161
long_description = long_description ,
137
- long_description_content_type = ' text/markdown' ,
138
- author = ' Ryuichi Yamamoto' ,
139
- author_email = ' zryuichi@gmail.com' ,
140
- url = ' https://github.com/r9y9/pyopenjtalk' ,
141
- license = ' MIT' ,
162
+ long_description_content_type = " text/markdown" ,
163
+ author = " Ryuichi Yamamoto" ,
164
+ author_email = " zryuichi@gmail.com" ,
165
+ url = " https://github.com/r9y9/pyopenjtalk" ,
166
+ license = " MIT" ,
142
167
packages = find_packages (),
143
- package_data = {'' : [' htsvoice/*' ]},
168
+ package_data = {"" : [" htsvoice/*" ]},
144
169
ext_modules = ext_modules ,
145
170
cmdclass = cmdclass ,
146
171
install_requires = [
147
- ' numpy >= 1.8.0' ,
148
- ' cython >= ' + min_cython_ver ,
149
- ' six' ,
172
+ " numpy >= 1.8.0" ,
173
+ " cython >= " + min_cython_ver ,
174
+ " six" ,
150
175
],
151
- tests_require = [' nose' , ' coverage' ],
176
+ tests_require = [" nose" , " coverage" ],
152
177
extras_require = {
153
- ' docs' : [' sphinx_rtd_theme' ],
154
- ' test' : [' nose' , ' scipy' ],
178
+ " docs" : [" sphinx_rtd_theme" ],
179
+ " test" : [" nose" , " scipy" ],
155
180
},
156
181
classifiers = [
157
182
"Operating System :: POSIX" ,
@@ -168,5 +193,5 @@ def run(self):
168
193
"Intended Audience :: Science/Research" ,
169
194
"Intended Audience :: Developers" ,
170
195
],
171
- keywords = ["OpenJTalk" , "Research" ]
196
+ keywords = ["OpenJTalk" , "Research" ],
172
197
)
0 commit comments