|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | import os
|
3 | 3 | import sys
|
4 |
| -from shutil import copy, copytree, rmtree, ignore_patterns |
| 4 | +from shutil import copy, copytree, ignore_patterns |
5 | 5 | from glob import glob
|
| 6 | +from distutils.command.build import build as _build |
6 | 7 | try:
|
7 | 8 | from setuptools import setup, Extension
|
8 |
| -except: |
| 9 | + from setuptools.command.install import install as _install |
| 10 | + from setuptools.command.bdist_egg import bdist_egg as _bdist_egg |
| 11 | +except ImportError: |
9 | 12 | from distutils.core import setup
|
10 | 13 | from distutils.extension import Extension
|
| 14 | + from distutils.command.install import install as _install |
| 15 | + from distutils.command.bdist_egg import bdist_egg as _bdist_egg |
| 16 | + |
| 17 | +if sys.platform.startswith('win'): |
| 18 | + from distutils.command.bdist_msi import bdist_msi as _bdist_msi |
| 19 | + from distutils.command.bdist_wininst import bdist_wininst as _bdist_wininst |
11 | 20 |
|
12 | 21 | extra_compile_args = []
|
13 | 22 | extra_link_args = []
|
|
110 | 119 | ['-outdir', 'pocketsphinx']
|
111 | 120 | )
|
112 | 121 |
|
113 |
| -rmtree('pocketsphinx/data', True) |
114 |
| -rmtree('pocketsphinx/model', True) |
115 |
| -copytree('deps/pocketsphinx/model/en-us', |
116 |
| - 'pocketsphinx/model', |
117 |
| - ignore=ignore_patterns('en-us-phone.lm.bin')) |
118 |
| -os.makedirs('pocketsphinx/data') |
119 |
| -copy('deps/pocketsphinx/test/data/goforward.raw', |
120 |
| - 'pocketsphinx/data/goforward.raw') |
| 122 | +if not os.path.exists(os.path.join(os.path.dirname(__file__), 'pocketsphinx/model')): |
| 123 | + copytree(os.path.join(os.path.dirname(__file__), 'deps/pocketsphinx/model/en-us'), |
| 124 | + os.path.join(os.path.dirname(__file__), 'pocketsphinx/model'), |
| 125 | + ignore=ignore_patterns('en-us-phone.lm.bin')) |
| 126 | +if not os.path.exists(os.path.join(os.path.dirname(__file__), 'pocketsphinx/data')): |
| 127 | + os.makedirs(os.path.join(os.path.dirname(__file__), 'pocketsphinx/data')) |
| 128 | + copy(os.path.join(os.path.dirname(__file__), 'deps/pocketsphinx/test/data/goforward.raw'), |
| 129 | + os.path.join(os.path.dirname(__file__), 'pocketsphinx/data/goforward.raw')) |
| 130 | + |
| 131 | + |
| 132 | +class build(_build): |
| 133 | + def run(self): |
| 134 | + self.run_command('build_ext') |
| 135 | + return _build.run(self) |
| 136 | + |
| 137 | + |
| 138 | +class install(_install): |
| 139 | + def run(self): |
| 140 | + self.run_command('build_ext') |
| 141 | + return _install.run(self) |
| 142 | + |
| 143 | + |
| 144 | +class bdist_egg(_bdist_egg): |
| 145 | + def run(self): |
| 146 | + self.run_command('build_ext') |
| 147 | + return _bdist_egg.run(self) |
| 148 | + |
| 149 | + |
| 150 | +cmdclass = { |
| 151 | + 'build': build, |
| 152 | + 'install': install, |
| 153 | + 'bdist_egg': bdist_egg |
| 154 | +} |
| 155 | + |
| 156 | + |
| 157 | +try: |
| 158 | + from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
| 159 | +except ImportError: |
| 160 | + pass |
| 161 | +else: |
| 162 | + class bdist_wheel(_bdist_wheel): |
| 163 | + def run(self): |
| 164 | + self.run_command('build_ext') |
| 165 | + return _bdist_wheel.run(self) |
| 166 | + |
| 167 | + cmdclass['bdist_wheel'] = bdist_wheel |
| 168 | + |
| 169 | + |
| 170 | +if sys.platform.startswith('win'): |
| 171 | + class bdist_msi(_bdist_msi): |
| 172 | + def run(self): |
| 173 | + self.run_command('build_ext') |
| 174 | + return _bdist_msi.run(self) |
| 175 | + |
| 176 | + class bdist_wininst(_bdist_wininst): |
| 177 | + def run(self): |
| 178 | + self.run_command('build_ext') |
| 179 | + return _bdist_wininst.run(self) |
| 180 | + |
| 181 | + cmdclass['bdist_msi'] = bdist_msi |
| 182 | + cmdclass['bdist_wininst'] = bdist_wininst |
| 183 | + |
121 | 184 |
|
122 | 185 | setup(
|
123 | 186 | name='pocketsphinx',
|
124 |
| - version='0.1.1', |
| 187 | + version='0.1.3', |
125 | 188 | description='Python interface to CMU Sphinxbase and Pocketsphinx libraries',
|
126 | 189 | long_description=open('README.rst').read(),
|
127 | 190 | author='Dmitry Prazdnichnov',
|
|
164 | 227 | extra_link_args=extra_link_args
|
165 | 228 | )
|
166 | 229 | ],
|
| 230 | + cmdclass=cmdclass, |
167 | 231 | classifiers=[
|
168 | 232 | 'Development Status :: 2 - Pre-Alpha',
|
169 | 233 | 'Operating System :: Microsoft :: Windows',
|
|
0 commit comments