14
14
get_management_command ,
15
15
get_repos ,
16
16
get_status ,
17
+ get_repo_name_map ,
17
18
install_package ,
18
19
)
19
20
@@ -33,15 +34,6 @@ def __repr__(self):
33
34
pass_repo = click .make_pass_decorator (Repo )
34
35
35
36
36
- def get_repo_name_map (repos , url_pattern ):
37
- """Return a dict mapping repo_name to repo_url from a list of repo URLs."""
38
- return {
39
- os .path .basename (url_pattern .search (url ).group (0 )): url
40
- for url in repos
41
- if url_pattern .search (url )
42
- }
43
-
44
-
45
37
@click .group (invoke_without_command = True )
46
38
@click .option (
47
39
"-l" ,
@@ -52,7 +44,7 @@ def get_repo_name_map(repos, url_pattern):
52
44
@click .pass_context
53
45
def repo (context , list_repos ):
54
46
"""
55
- Run Django fork and third-party library tests .
47
+ Run tests configured to test django-mongodb-backend .
56
48
"""
57
49
context .obj = Repo ()
58
50
repos , url_pattern , branch_pattern = get_repos ("pyproject.toml" )
@@ -207,15 +199,75 @@ def makemigrations(context, repo_name, args):
207
199
click .echo (context .get_help ())
208
200
209
201
202
+ @repo .command ()
203
+ @click .argument ("repo_names" , nargs = - 1 )
204
+ @click .option ("-a" , "--all-repos" , is_flag = True , help = "Status for all repositories" )
205
+ @click .option ("-r" , "--reset" , is_flag = True , help = "Reset" )
206
+ @click .option ("-d" , "--diff" , is_flag = True , help = "Show diff" )
207
+ @click .option ("-b" , "--branch" , is_flag = True , help = "Show branch" )
208
+ @click .option ("-u" , "--update" , is_flag = True , help = "Update repos" )
209
+ @click .option ("-l" , "--log" , is_flag = True , help = "Show log" )
210
+ @click .pass_context
211
+ @pass_repo
212
+ def status (repo , context , repo_names , all_repos , reset , diff , branch , update , log ):
213
+ """Repository status."""
214
+ repos , url_pattern , _ = get_repos ("pyproject.toml" )
215
+ repo_name_map = get_repo_name_map (repos , url_pattern )
216
+
217
+ # Status for specified repo names
218
+ if repo_names :
219
+ not_found = []
220
+ for repo_name in repo_names :
221
+ repo_url = repo_name_map .get (repo_name )
222
+ if repo_url :
223
+ get_status (
224
+ repo_url ,
225
+ url_pattern ,
226
+ repo ,
227
+ reset = reset ,
228
+ diff = diff ,
229
+ branch = branch ,
230
+ update = update ,
231
+ log = log ,
232
+ )
233
+ else :
234
+ not_found .append (repo_name )
235
+ for name in not_found :
236
+ click .echo (f"Repository '{ name } ' not found." )
237
+ return
238
+
239
+ # Status for all repos
240
+ if all_repos :
241
+ click .echo (f"Status of { len (repos )} repositories..." )
242
+ for repo_name , repo_url in repo_name_map .items ():
243
+ get_status (
244
+ repo_url ,
245
+ url_pattern ,
246
+ repo ,
247
+ reset = reset ,
248
+ diff = diff ,
249
+ branch = branch ,
250
+ update = update ,
251
+ log = log ,
252
+ )
253
+ return
254
+
255
+ # Show help if nothing selected
256
+ click .echo (context .get_help ())
257
+
258
+
210
259
@repo .command ()
211
260
@click .argument ("repo_name" , required = False )
212
261
@click .argument ("modules" , nargs = - 1 )
213
262
@click .option ("-k" , "--keyword" , help = "Filter tests by keyword" )
214
263
@click .option ("-l" , "--list-tests" , is_flag = True , help = "List tests" )
215
- @click .option ("-s" , "--show" , is_flag = True , help = "Show settings" )
264
+ @click .option ("-s" , "--show-settings" , is_flag = True , help = "Show settings" )
265
+ @click .option ("-a" , "--all-repos" , is_flag = True , help = "All repos" )
216
266
@click .option ("--keepdb" , is_flag = True , help = "Keep db" )
217
267
@click .pass_context
218
- def test (context , repo_name , modules , keyword , list_tests , show , keepdb ):
268
+ def test (
269
+ context , repo_name , modules , keyword , list_tests , show_settings , keepdb , all_repos
270
+ ):
219
271
"""Run tests for Django fork and third-party libraries."""
220
272
repos , url_pattern , _ = get_repos ("pyproject.toml" )
221
273
repo_name_map = get_repo_name_map (repos , url_pattern )
@@ -229,7 +281,7 @@ def test(context, repo_name, modules, keyword, list_tests, show, keepdb):
229
281
)
230
282
return
231
283
232
- if show :
284
+ if show_settings :
233
285
click .echo (f"⚙️ Test settings for 📦 { repo_name } :" )
234
286
settings_dict = dict (sorted (test_settings_map [repo_name ].items ()))
235
287
formatted = format_str (str (settings_dict ), mode = Mode ())
@@ -327,64 +379,23 @@ def test(context, repo_name, modules, keyword, list_tests, show, keepdb):
327
379
subprocess .run (command , cwd = settings ["test_dir" ])
328
380
return
329
381
330
- # No repo_name, show help
331
- click .echo (context .get_help ())
332
-
333
-
334
- @repo .command ()
335
- @click .argument ("repo_names" , nargs = - 1 )
336
- @click .option ("-a" , "--all-repos" , is_flag = True , help = "Status for all repositories" )
337
- @click .option ("-r" , "--reset" , is_flag = True , help = "Reset" )
338
- @click .option ("-d" , "--diff" , is_flag = True , help = "Show diff" )
339
- @click .option ("-b" , "--branch" , is_flag = True , help = "Show branch" )
340
- @click .option ("-u" , "--update" , is_flag = True , help = "Update repos" )
341
- @click .option ("-l" , "--log" , is_flag = True , help = "Show log" )
342
- @click .pass_context
343
- @pass_repo
344
- def status (repo , context , repo_names , all_repos , reset , diff , branch , update , log ):
345
- """Repository status."""
346
- repos , url_pattern , _ = get_repos ("pyproject.toml" )
347
- repo_name_map = get_repo_name_map (repos , url_pattern )
348
-
349
- # Status for specified repo names
350
- if repo_names :
351
- not_found = []
352
- for repo_name in repo_names :
353
- repo_url = repo_name_map .get (repo_name )
354
- if repo_url :
355
- get_status (
356
- repo_url ,
357
- url_pattern ,
358
- repo ,
359
- reset = reset ,
360
- diff = diff ,
361
- branch = branch ,
362
- update = update ,
363
- log = log ,
364
- )
382
+ if all_repos and show_settings :
383
+ repos , url_pattern , _ = get_repos ("pyproject.toml" )
384
+ repo_name_map = get_repo_name_map (repos , url_pattern )
385
+ for repo_name in repo_name_map :
386
+ if repo_name in test_settings_map :
387
+ click .echo (f"⚙️ Test settings for 📦 { repo_name } :" )
388
+ settings_dict = dict (sorted (test_settings_map [repo_name ].items ()))
389
+ formatted = format_str (str (settings_dict ), mode = Mode ())
390
+ rprint (formatted )
365
391
else :
366
- not_found .append (repo_name )
367
- for name in not_found :
368
- click .echo (f"Repository '{ name } ' not found." )
392
+ click .echo (f"Settings for '{ repo_name } ' not found." )
369
393
return
370
-
371
- # Status for all repos
372
- if all_repos :
373
- click .echo (f"Status of { len (repos )} repositories..." )
374
- for repo_name , repo_url in repo_name_map .items ():
375
- get_status (
376
- repo_url ,
377
- url_pattern ,
378
- repo ,
379
- reset = reset ,
380
- diff = diff ,
381
- branch = branch ,
382
- update = update ,
383
- log = log ,
384
- )
394
+ else :
395
+ click .echo ("Can only use --all-repos with --show-settings" )
385
396
return
386
397
387
- # Show help if nothing selected
398
+ # No repo_name, show help
388
399
click .echo (context .get_help ())
389
400
390
401
0 commit comments