Skip to content

Commit c8a5d1d

Browse files
authored
Merge pull request #1361 from Jackwaterveg/setup
[Setup]refactor the version
2 parents af6cb90 + 3845804 commit c8a5d1d

File tree

5 files changed

+92
-52
lines changed

5 files changed

+92
-52
lines changed

paddleaudio/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@
1313
# limitations under the License.
1414
from .backends import *
1515
from .features import *
16-
17-
__version__ = '0.1.0'

paddlespeech/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
__version__ = '0.1.1'

setup.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import os
1818
import subprocess as sp
1919
import sys
20-
import paddlespeech
2120
from pathlib import Path
2221

2322
from setuptools import Command
@@ -28,6 +27,8 @@
2827

2928
HERE = Path(os.path.abspath(os.path.dirname(__file__)))
3029

30+
VERSION = '0.1.1'
31+
3132
requirements = {
3233
"install": [
3334
"editdistance",
@@ -83,6 +84,24 @@
8384
}
8485

8586

87+
def write_version_py(filename='paddlespeech/__init__.py'):
88+
import paddlespeech
89+
if hasattr(paddlespeech,
90+
"__version__") and paddlespeech.__version__ == VERSION:
91+
return
92+
with open(filename, "a") as f:
93+
f.write(f"\n__version__ = '{VERSION}'\n")
94+
95+
96+
def remove_version_py(filename='paddlespeech/__init__.py'):
97+
with open(filename, "r") as f:
98+
lines = f.readlines()
99+
with open(filename, "w") as f:
100+
for line in lines:
101+
if "__version__" not in line:
102+
f.write(line)
103+
104+
86105
@contextlib.contextmanager
87106
def pushd(new_dir):
88107
old_dir = os.getcwd()
@@ -170,10 +189,12 @@ def run(self):
170189
sys.exit()
171190

172191

192+
write_version_py()
193+
173194
setup_info = dict(
174195
# Metadata
175196
name='paddlespeech',
176-
version=paddlespeech.__version__,
197+
version=VERSION,
177198
author='PaddlePaddle Speech and Language Team',
178199
author_email='[email protected]',
179200
url='https://github.com/PaddlePaddle/PaddleSpeech',
@@ -236,3 +257,5 @@ def run(self):
236257
})
237258

238259
setup(**setup_info)
260+
261+
remove_version_py()

setup_audio.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@
1313
# limitations under the License.
1414
import setuptools
1515

16-
import paddleaudio
17-
1816
# set the version here
19-
version = paddleaudio.__version__
17+
VERSION = '0.1.0'
18+
19+
20+
def write_version_py(filename='paddleaudio/__init__.py'):
21+
import paddleaudio
22+
if hasattr(paddleaudio,
23+
"__version__") and paddleaudio.__version__ == VERSION:
24+
return
25+
with open(filename, "a") as f:
26+
f.write(f"\n__version__ = '{VERSION}'\n")
27+
28+
29+
def remove_version_py(filename='paddleaudio/__init__.py'):
30+
with open(filename, "r") as f:
31+
lines = f.readlines()
32+
with open(filename, "w") as f:
33+
for line in lines:
34+
if "__version__" not in line:
35+
f.write(line)
36+
37+
38+
write_version_py()
2039

2140
setuptools.setup(
2241
name="paddleaudio",
23-
version=version,
42+
version=VERSION,
2443
author="",
2544
author_email="",
2645
description="PaddleAudio, in development",
@@ -41,3 +60,5 @@
4160
'soundfile >= 0.9.0',
4261
'colorlog',
4362
], )
63+
64+
remove_version_py()

utils/generate_infer_yaml.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#!/usr/bin/env python3
22
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3-
43
'''
54
Merge training configs into a single inference config.
65
The single inference config is for CLI, which only takes a single config to do inferencing.
76
The trainig configs includes: model config, preprocess config, decode config, vocab file and cmvn file.
87
'''
9-
10-
import yaml
11-
import json
12-
import os
138
import argparse
9+
import json
1410
import math
11+
import os
12+
from contextlib import redirect_stdout
13+
1514
from yacs.config import CfgNode
1615

1716
from paddlespeech.s2t.frontend.utility import load_dict
18-
from contextlib import redirect_stdout
1917

2018

2119
def save(save_path, config):
@@ -29,18 +27,21 @@ def load(save_path):
2927
config.merge_from_file(save_path)
3028
return config
3129

30+
3231
def load_json(json_path):
3332
with open(json_path) as f:
3433
json_content = json.load(f)
3534
return json_content
3635

36+
3737
def remove_config_part(config, key_list):
3838
if len(key_list) == 0:
3939
return
40-
for i in range(len(key_list) -1):
40+
for i in range(len(key_list) - 1):
4141
config = config[key_list[i]]
4242
config.pop(key_list[-1])
4343

44+
4445
def load_cmvn_from_json(cmvn_stats):
4546
means = cmvn_stats['mean_stat']
4647
variance = cmvn_stats['var_stat']
@@ -51,17 +52,17 @@ def load_cmvn_from_json(cmvn_stats):
5152
if variance[i] < 1.0e-20:
5253
variance[i] = 1.0e-20
5354
variance[i] = 1.0 / math.sqrt(variance[i])
54-
cmvn_stats = {"mean":means, "istd":variance}
55+
cmvn_stats = {"mean": means, "istd": variance}
5556
return cmvn_stats
5657

58+
5759
def merge_configs(
58-
conf_path = "conf/conformer.yaml",
59-
preprocess_path = "conf/preprocess.yaml",
60-
decode_path = "conf/tuning/decode.yaml",
61-
vocab_path = "data/vocab.txt",
62-
cmvn_path = "data/mean_std.json",
63-
save_path = "conf/conformer_infer.yaml",
64-
):
60+
conf_path="conf/conformer.yaml",
61+
preprocess_path="conf/preprocess.yaml",
62+
decode_path="conf/tuning/decode.yaml",
63+
vocab_path="data/vocab.txt",
64+
cmvn_path="data/mean_std.json",
65+
save_path="conf/conformer_infer.yaml", ):
6566

6667
# Load the configs
6768
config = load(conf_path)
@@ -72,17 +73,16 @@ def merge_configs(
7273
if cmvn_path.split(".")[-1] == 'json':
7374
cmvn_stats = load_json(cmvn_path)
7475
if os.path.exists(preprocess_path):
75-
preprocess_config = load(preprocess_path)
76+
preprocess_config = load(preprocess_path)
7677
for idx, process in enumerate(preprocess_config["process"]):
7778
if process['type'] == "cmvn_json":
78-
preprocess_config["process"][idx][
79-
"cmvn_path"] = cmvn_stats
79+
preprocess_config["process"][idx]["cmvn_path"] = cmvn_stats
8080
break
8181

8282
config.preprocess_config = preprocess_config
8383
else:
8484
cmvn_stats = load_cmvn_from_json(cmvn_stats)
85-
config.mean_std_filepath = [{"cmvn_stats":cmvn_stats}]
85+
config.mean_std_filepath = [{"cmvn_stats": cmvn_stats}]
8686
config.augmentation_config = ''
8787
# the cmvn file is end with .ark
8888
else:
@@ -95,7 +95,8 @@ def merge_configs(
9595
# Remove some parts of the config
9696

9797
if os.path.exists(preprocess_path):
98-
remove_train_list = ["train_manifest",
98+
remove_train_list = [
99+
"train_manifest",
99100
"dev_manifest",
100101
"test_manifest",
101102
"n_epoch",
@@ -124,9 +125,10 @@ def merge_configs(
124125
"batch_size",
125126
"maxlen_in",
126127
"maxlen_out",
127-
]
128+
]
128129
else:
129-
remove_train_list = ["train_manifest",
130+
remove_train_list = [
131+
"train_manifest",
130132
"dev_manifest",
131133
"test_manifest",
132134
"n_epoch",
@@ -141,43 +143,41 @@ def merge_configs(
141143
"weight_decay",
142144
"sortagrad",
143145
"num_workers",
144-
]
146+
]
145147

146148
for item in remove_train_list:
147149
try:
148150
remove_config_part(config, [item])
149151
except:
150-
print ( item + " " +"can not be removed")
152+
print(item + " " + "can not be removed")
151153

152154
# Save the config
153155
save(save_path, config)
154156

155157

156-
157158
if __name__ == "__main__":
158-
parser = argparse.ArgumentParser(
159-
prog='Config merge', add_help=True)
159+
parser = argparse.ArgumentParser(prog='Config merge', add_help=True)
160160
parser.add_argument(
161-
'--cfg_pth', type=str, default = 'conf/transformer.yaml', help='origin config file')
161+
'--cfg_pth',
162+
type=str,
163+
default='conf/transformer.yaml',
164+
help='origin config file')
162165
parser.add_argument(
163-
'--pre_pth', type=str, default= "conf/preprocess.yaml", help='')
166+
'--pre_pth', type=str, default="conf/preprocess.yaml", help='')
164167
parser.add_argument(
165-
'--dcd_pth', type=str, default= "conf/tuninig/decode.yaml", help='')
168+
'--dcd_pth', type=str, default="conf/tuninig/decode.yaml", help='')
166169
parser.add_argument(
167-
'--vb_pth', type=str, default= "data/lang_char/vocab.txt", help='')
170+
'--vb_pth', type=str, default="data/lang_char/vocab.txt", help='')
168171
parser.add_argument(
169-
'--cmvn_pth', type=str, default= "data/mean_std.json", help='')
172+
'--cmvn_pth', type=str, default="data/mean_std.json", help='')
170173
parser.add_argument(
171-
'--save_pth', type=str, default= "conf/transformer_infer.yaml", help='')
174+
'--save_pth', type=str, default="conf/transformer_infer.yaml", help='')
172175
parser_args = parser.parse_args()
173176

174177
merge_configs(
175-
conf_path = parser_args.cfg_pth,
176-
decode_path = parser_args.dcd_pth,
177-
preprocess_path = parser_args.pre_pth,
178-
vocab_path = parser_args.vb_pth,
179-
cmvn_path = parser_args.cmvn_pth,
180-
save_path = parser_args.save_pth,
181-
)
182-
183-
178+
conf_path=parser_args.cfg_pth,
179+
decode_path=parser_args.dcd_pth,
180+
preprocess_path=parser_args.pre_pth,
181+
vocab_path=parser_args.vb_pth,
182+
cmvn_path=parser_args.cmvn_pth,
183+
save_path=parser_args.save_pth, )

0 commit comments

Comments
 (0)