1
1
import argparse
2
2
import logging
3
3
from pathlib import Path
4
- from subprocess import run
4
+ from subprocess import run , PIPE
5
5
import tomli
6
6
7
7
_LOGGER = logging .getLogger (__name__ )
@@ -40,19 +40,25 @@ def generate_autorest(folder: Path) -> None:
40
40
41
41
42
42
def generate_typespec (folder : Path ) -> None :
43
+ tsp_location_path = folder / "tsp-location.yaml"
43
44
44
- # Turns out, "pwsh" is the name for PowerShell 7 on Windows, that is required for those scripts
45
- ps_cmd = "pwsh"
45
+ if not tsp_location_path .exists ():
46
+ raise ValueError (
47
+ "Didn't find a tsp_location.yaml in local directory. Please make sure a valid "
48
+ "tsp-location.yaml file exists before running this command, for more information "
49
+ "on how to create one, see: "
50
+ "https://github.com/Azure/azure-sdk-tools/tree/main/tools/tsp-client/README.md"
51
+ )
46
52
47
- completed_process = run ([ps_cmd , "../../../eng/common/scripts/TypeSpec-Project-Sync.ps1 " , folder ], cwd = folder )
53
+ completed_process = run (["tsp-client " , "update" ], cwd = folder , shell = True , stderr = PIPE )
48
54
if completed_process .returncode != 0 :
49
- raise ValueError ("Something happened with TypeSpec Synx step: " + str (completed_process ))
55
+ if "'tsp-client' is not recognized" in completed_process .stderr .decode ("utf-8" ):
56
+ raise ValueError (
57
+ "tsp-client is not installed. Please run: npm install -g @azure-tools/typespec-client-generator-cli"
58
+ )
59
+ raise ValueError ("Something happened with tsp-client update step: " + str (completed_process ))
50
60
51
- completed_process = run ([ps_cmd , "../../../eng/common/scripts/TypeSpec-Project-Generate.ps1" , folder ], cwd = folder )
52
- if completed_process .returncode != 0 :
53
- raise ValueError ("Something happened with TypeSpec Generate step: " + str (completed_process ))
54
-
55
- _LOGGER .info ("TypeSpec done" )
61
+ _LOGGER .info ("TypeSpec generate done" )
56
62
57
63
def generate (folder : Path = Path ("." )) -> None :
58
64
if (folder / "swagger" / "README.md" ).exists ():
@@ -72,48 +78,6 @@ def generate_main() -> None:
72
78
description = "Build SDK using Codegen." ,
73
79
formatter_class = argparse .RawTextHelpFormatter ,
74
80
)
75
- # FIXME, we probably don't need any of that
76
- # parser.add_argument(
77
- # "--rest-folder",
78
- # "-r",
79
- # dest="restapi_git_folder",
80
- # default=None,
81
- # help="Rest API git folder. [default: %(default)s]",
82
- # )
83
- # parser.add_argument(
84
- # "--project",
85
- # "-p",
86
- # dest="project",
87
- # action="append",
88
- # help="Select a specific project. Do all by default. You can use a substring for several projects.",
89
- # )
90
- # parser.add_argument("--readme", "-m", dest="readme", help="Select a specific readme. Must be a path")
91
- # parser.add_argument(
92
- # "--config",
93
- # "-c",
94
- # dest="config_path",
95
- # default=CONFIG_FILE,
96
- # help="The JSON configuration format path [default: %(default)s]",
97
- # )
98
- # parser.add_argument(
99
- # "--autorest",
100
- # dest="autorest_bin",
101
- # help="Force the Autorest to be executed. Must be a executable command.",
102
- # )
103
- # parser.add_argument(
104
- # "-f",
105
- # "--force",
106
- # dest="force",
107
- # action="store_true",
108
- # help="Should I force generation if SwaggerToSdk tag is not found",
109
- # )
110
- # parser.add_argument(
111
- # "--sdk-folder",
112
- # "-s",
113
- # dest="sdk_folder",
114
- # default=".",
115
- # help="A Python SDK folder. [default: %(default)s]",
116
- # )
117
81
parser .add_argument (
118
82
"-v" ,
119
83
"--verbose" ,
@@ -129,15 +93,7 @@ def generate_main() -> None:
129
93
logging .basicConfig ()
130
94
main_logger .setLevel (logging .DEBUG if args .debug else logging .INFO )
131
95
132
- generate (
133
- # args.config_path,
134
- # args.sdk_folder,
135
- # args.project,
136
- # args.readme,
137
- # args.restapi_git_folder,
138
- # args.autorest_bin,
139
- # args.force,
140
- )
96
+ generate ()
141
97
142
98
143
99
if __name__ == "__main__" :
0 commit comments