Skip to content

Commit 2fed5b0

Browse files
fix the script with subprocess
1 parent 43bb059 commit 2fed5b0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

scripts/build_twilio_library.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import glob
23
import json
34
import os
45
import re
@@ -83,7 +84,7 @@ def generate(spec_folder: str, spec_files: List[str], output_path: str, language
8384

8485

8586
def generate_domain_for_language(spec_file: str, config_path: str, spec_folder: str, output_path: str, language: str, parent_dir: str) -> None:
86-
print("generate domain for language: {}, config: {}, spec file: {}".format(language, config_path, spec_file))
87+
print("generate domain for language: {}, config: {}, spec folder: {}, file: {}".format(language, config_path, spec_folder, spec_file))
8788
full_path = os.path.join(spec_folder, spec_file)
8889
full_config_path = os.path.join(config_path, spec_file)
8990
config = {
@@ -96,21 +97,23 @@ def generate_domain_for_language(spec_file: str, config_path: str, spec_folder:
9697
}
9798
# print(config)
9899
with open(full_config_path, 'w') as f:
99-
f.write(json.dumps(config))
100+
f.write(json.dumps(config) + "\n")
100101

101102
def run_openapi_generator(parent_dir: Path, language: str) -> None:
102103
properties = "-DapiTests=false"
103104
if language in {"node", "python"}:
104105
properties += " -DskipFormModel=false"
105106

107+
paths = glob.glob(os.path.join(CONFIG_FOLDER, language, "*"))
108+
106109
command = [
107110
"java",
108111
*properties.split(), # Splits e.g. "-DapiTests=false -DskipFormModel=false" into separate arguments
109112
"-cp",
110113
"target/twilio-openapi-generator.jar",
111114
"org.openapitools.codegen.OpenAPIGenerator",
112115
"batch",
113-
f"{CONFIG_FOLDER}/{language}/*"
116+
*paths,
114117
]
115118

116119
printable_cmd = " ".join(shlex.quote(arg) for arg in command)

scripts/generate_libraries/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env python3
22

3-
# python -m scripts.generate_libraries.main --language go --input=./examples
3+
# an example way to run this script would be:
4+
#
5+
# cd /path/to/twilio-oai-generator
6+
# python -m scripts.generate_libraries.main --language go --input=../twilio-oai/spec/json --base=..
7+
#
8+
# and have twilio-oai and twilio-go as sibling directories to twilio-oai-generator
49

510
import argparse
611
import glob

0 commit comments

Comments
 (0)