1414 get_management_command ,
1515 get_repos ,
1616 get_status ,
17+ get_repo_name_map ,
1718 install_package ,
1819)
1920
@@ -33,15 +34,6 @@ def __repr__(self):
3334pass_repo = click .make_pass_decorator (Repo )
3435
3536
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-
4537@click .group (invoke_without_command = True )
4638@click .option (
4739 "-l" ,
@@ -52,7 +44,7 @@ def get_repo_name_map(repos, url_pattern):
5244@click .pass_context
5345def repo (context , list_repos ):
5446 """
55- Run Django fork and third-party library tests .
47+ Run tests configured to test django-mongodb-backend .
5648 """
5749 context .obj = Repo ()
5850 repos , url_pattern , branch_pattern = get_repos ("pyproject.toml" )
@@ -207,15 +199,75 @@ def makemigrations(context, repo_name, args):
207199 click .echo (context .get_help ())
208200
209201
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+
210259@repo .command ()
211260@click .argument ("repo_name" , required = False )
212261@click .argument ("modules" , nargs = - 1 )
213262@click .option ("-k" , "--keyword" , help = "Filter tests by keyword" )
214263@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" )
216266@click .option ("--keepdb" , is_flag = True , help = "Keep db" )
217267@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+ ):
219271 """Run tests for Django fork and third-party libraries."""
220272 repos , url_pattern , _ = get_repos ("pyproject.toml" )
221273 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):
229281 )
230282 return
231283
232- if show :
284+ if show_settings :
233285 click .echo (f"⚙️ Test settings for 📦 { repo_name } :" )
234286 settings_dict = dict (sorted (test_settings_map [repo_name ].items ()))
235287 formatted = format_str (str (settings_dict ), mode = Mode ())
@@ -327,64 +379,23 @@ def test(context, repo_name, modules, keyword, list_tests, show, keepdb):
327379 subprocess .run (command , cwd = settings ["test_dir" ])
328380 return
329381
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 )
365391 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." )
369393 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" )
385396 return
386397
387- # Show help if nothing selected
398+ # No repo_name, show help
388399 click .echo (context .get_help ())
389400
390401
0 commit comments