13
13
# limitations under the License.
14
14
import os
15
15
import sys
16
-
16
+ from typing import Optional
17
17
import click as click
18
18
from library_generation .generate_pr_description import generate_pr_descriptions
19
19
from library_generation .generate_repo import generate_from_yaml
@@ -51,6 +51,17 @@ def main(ctx):
51
51
metadata about library generation.
52
52
""" ,
53
53
)
54
+ @click .option (
55
+ "--library-names" ,
56
+ type = str ,
57
+ default = None ,
58
+ show_default = True ,
59
+ help = """
60
+ A list of library names that will be generated, separated by comma.
61
+ The library name of a library is the value of library_name or api_shortname,
62
+ if library_name is not specified, in the generation configuration.
63
+ """ ,
64
+ )
54
65
@click .option (
55
66
"--repository-path" ,
56
67
type = str ,
@@ -77,6 +88,7 @@ def main(ctx):
77
88
def generate (
78
89
baseline_generation_config_path : str ,
79
90
current_generation_config_path : str ,
91
+ library_names : Optional [str ],
80
92
repository_path : str ,
81
93
api_definitions_path : str ,
82
94
):
@@ -86,24 +98,32 @@ def generate(
86
98
history.
87
99
88
100
If baseline generation config is not specified but current generation
89
- config is specified, generate all libraries based on current generation
90
- config without commit history.
101
+ config is specified, generate all libraries if `library_names` is not
102
+ specified, based on current generation config without commit history.
91
103
92
104
If current generation config is not specified but baseline generation
93
105
config is specified, raise FileNotFoundError because current generation
94
106
config should be the source of truth of library generation.
95
107
96
108
If both baseline generation config and current generation config are not
97
109
specified, generate all libraries based on the default generation config,
98
- which is generation_config.yaml in the current working directory. Raise
99
- FileNotFoundError if the default config does not exist.
110
+ which is generation_config.yaml in the current working directory.
111
+
112
+ If `library_names` is specified, only libraries whose name can be found in
113
+ the current generation config or default generation config, if current
114
+ generation config is not specified, will be generated. Changed libraries
115
+ will be ignored even if baseline and current generation config are
116
+ specified.
117
+
118
+ Raise FileNotFoundError if the default config does not exist.
100
119
101
120
The commit history, if generated, will be available in
102
121
repository_path/pr_description.txt.
103
122
"""
104
123
__generate_repo_and_pr_description_impl (
105
124
baseline_generation_config_path = baseline_generation_config_path ,
106
125
current_generation_config_path = current_generation_config_path ,
126
+ library_names = library_names ,
107
127
repository_path = repository_path ,
108
128
api_definitions_path = api_definitions_path ,
109
129
)
@@ -112,6 +132,7 @@ def generate(
112
132
def __generate_repo_and_pr_description_impl (
113
133
baseline_generation_config_path : str ,
114
134
current_generation_config_path : str ,
135
+ library_names : Optional [str ],
115
136
repository_path : str ,
116
137
api_definitions_path : str ,
117
138
):
@@ -146,30 +167,39 @@ def __generate_repo_and_pr_description_impl(
146
167
current_generation_config_path = os .path .abspath (current_generation_config_path )
147
168
repository_path = os .path .abspath (repository_path )
148
169
api_definitions_path = os .path .abspath (api_definitions_path )
170
+ include_library_names = _parse_library_name_from (library_names )
171
+
149
172
if not baseline_generation_config_path :
150
- # Execute full generation based on current_generation_config if
173
+ # Execute selective generation based on current_generation_config if
151
174
# baseline_generation_config is not specified.
152
175
# Do not generate pull request description.
153
176
generate_from_yaml (
154
177
config = from_yaml (current_generation_config_path ),
155
178
repository_path = repository_path ,
156
179
api_definitions_path = api_definitions_path ,
180
+ target_library_names = include_library_names ,
157
181
)
158
182
return
159
183
160
- # Compare two generation configs and only generate changed libraries.
184
+ # Compare two generation configs to get changed libraries.
161
185
# Generate pull request description.
162
186
baseline_generation_config_path = os .path .abspath (baseline_generation_config_path )
163
187
config_change = compare_config (
164
188
baseline_config = from_yaml (baseline_generation_config_path ),
165
189
current_config = from_yaml (current_generation_config_path ),
166
190
)
167
- # pass None if we want to fully generate the repository.
168
- target_library_names = (
191
+ # Pass None if we want to fully generate the repository.
192
+ changed_library_names = (
169
193
config_change .get_changed_libraries ()
170
194
if not _needs_full_repo_generation (config_change = config_change )
171
195
else None
172
196
)
197
+ # Include library names takes preference if specified.
198
+ target_library_names = (
199
+ include_library_names
200
+ if include_library_names is not None
201
+ else changed_library_names
202
+ )
173
203
generate_from_yaml (
174
204
config = config_change .current_config ,
175
205
repository_path = repository_path ,
@@ -191,6 +221,12 @@ def _needs_full_repo_generation(config_change: ConfigChange) -> bool:
191
221
return not current_config .is_monorepo () or current_config .contains_common_protos ()
192
222
193
223
224
+ def _parse_library_name_from (includes : str ) -> Optional [list [str ]]:
225
+ if includes is None :
226
+ return None
227
+ return [library_name .strip () for library_name in includes .split ("," )]
228
+
229
+
194
230
@main .command ()
195
231
@click .option (
196
232
"--generation-config-path" ,
0 commit comments