forked from rhasspy/rhasspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py.in
180 lines (137 loc) · 5.37 KB
/
setup.py.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""Setup script for Rhasspy"""
import typing
from pathlib import Path
import setuptools
this_dir = Path(__file__).parent
# -----------------------------------------------------------------------------
# Load README in as long description
long_description: str = ""
readme_path = this_dir / "README.md"
if readme_path.is_file():
long_description = readme_path.read_text()
# -----------------------------------------------------------------------------
def to_python_name(dir_name: str) -> str:
"""Convert kebab-case directory name to python module name."""
# rhasspy-asr-pocketsphinx-hermes => rhasspyasr_pocketsphinx_hermes
python_name_parts = dir_name.split("-")
return "_".join(
[python_name_parts[0] + python_name_parts[1]] + python_name_parts[2:]
)
# Build list of packages/requirements
packages: typing.Dict[str, Path] = {}
# RHASSPY_DIRS contains a list of all directories with Rhasspy libraries/services
with open(this_dir / "RHASSPY_DIRS", "r") as packages_file:
for line in packages_file:
line = line.strip()
if line:
module_dir_name = line
python_name = to_python_name(module_dir_name)
# module name -> module directory
packages[python_name] = this_dir / module_dir_name / python_name
# -----------------------------------------------------------------------------
def is_yes(s):
"""True if string is yes (from configure.ac)"""
return s.lower().strip() == "yes"
# Strip requirements for modules that were disabled during ./configure
# fuzzywuzzy
enable_fuzzywuzzy = is_yes("@ENABLE_FUZZYWUZZY@")
if not enable_fuzzywuzzy:
packages.pop("rhasspyfuzzywuzzy_hermes")
# pocketsphinx
enable_wake_pocketsphinx = is_yes("@ENABLE_WAKE_POCKETSPHINX@")
enable_stt_pocketsphinx = is_yes("@ENABLE_STT_POCKETSPHINX@")
if not enable_wake_pocketsphinx:
packages.pop("rhasspywake_pocketsphinx_hermes")
if not enable_stt_pocketsphinx:
packages.pop("rhasspyasr_pocketsphinx_hermes")
if (not enable_wake_pocketsphinx) and (not enable_stt_pocketsphinx):
packages.pop("rhasspyasr_pocketsphinx")
# kaldi
enable_kaldi = is_yes("@ENABLE_KALDI@")
if not enable_kaldi:
packages.pop("rhasspyasr_kaldi")
packages.pop("rhasspyasr_kaldi_hermes")
# deepspeech
enable_deepspeech = is_yes("@ENABLE_DEEPSPEECH@")
if not enable_deepspeech:
packages.pop("rhasspyasr_deepspeech")
packages.pop("rhasspyasr_deepspeech_hermes")
# snowboy
enable_snowboy = is_yes("@ENABLE_SNOWBOY@")
if not enable_snowboy:
packages.pop("rhasspywake_snowboy_hermes")
# porcupine
enable_porcupine = is_yes("@ENABLE_PORCUPINE@")
if not enable_porcupine:
packages.pop("rhasspywake_porcupine_hermes")
# snips
enable_snips = is_yes("@ENABLE_SNIPS@")
if not enable_snips:
packages.pop("rhasspysnips_nlu")
packages.pop("rhasspysnips_nlu_hermes")
# wavenet
enable_wavenet = is_yes("@ENABLE_WAVENET@")
if not enable_wavenet:
packages.pop("rhasspytts_wavenet_hermes")
# larynx
enable_larynx = is_yes("@ENABLE_LARYNX@")
if not enable_larynx:
packages.pop("rhasspytts_larynx_hermes")
# vosk
enable_vosk = is_yes("@ENABLE_VOSK@")
if not enable_vosk:
packages.pop("rhasspyasr_vosk_hermes")
# -----------------------------------------------------------------------------
# True if Rhasspy Python modules will be used directly from source instead of
# being installed.
in_place = is_yes("@IN_PLACE@")
# Generate requirements from remaining packages
requirements: typing.Set[str] = set()
def add_requirements(requirements_path: Path):
"""Add requirements from a file."""
if requirements_path.is_file():
with open(requirements_path, "r") as requirements_file:
for line in requirements_file:
line = line.strip()
if line:
if in_place and line.startswith("rhasspy-"):
# Exclude Rhasspy modules if "in-place"
continue
requirements.add(line)
# Look in remaining module directories for requirements
for module_python_dir in packages.values():
# rhasspy-module-directory
module_dir = module_python_dir.parent
if in_place:
# Add development requirements for in-place install
add_requirements(module_dir / "requirements_dev.txt")
else:
# Add module as requirement
version_path = module_dir / "VERSION"
if version_path.is_file():
# Use version specified in VERSION file
module_version = version_path.read_text().strip()
requirements.add(f"{module_dir.name}~={module_version}")
else:
# Use latest version
requirements.add(module_dir.name)
# Add requirements from module
add_requirements(module_dir / "requirements.txt")
# -----------------------------------------------------------------------------
setuptools.setup(
name="@PACKAGE_NAME@",
version="@PACKAGE_VERSION@",
author="Michael Hansen",
author_email="@PACKAGE_BUGREPORT@",
url="https://github.com/rhasspy/rhasspy-voltron",
install_requires=list(requirements),
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"License :: OSI Approved :: MIT License",
],
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.7",
)