mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Better control when dumping import state
This commit is contained in:
		
							parent
							
								
									5fbd37e57a
								
							
						
					
					
						commit
						ec5cf095a9
					
				
					 1 changed files with 10 additions and 12 deletions
				
			
		|  | @ -7,27 +7,25 @@ | |||
| 
 | ||||
| def _dump_state(args): | ||||
|     print(sys.version) | ||||
|     print("sys.path:") | ||||
|     pprint(sys.path) | ||||
|     print("sys.meta_path") | ||||
|     pprint(sys.meta_path) | ||||
|     print("sys.path_hooks") | ||||
|     pprint(sys.path_hooks) | ||||
|     print("sys.path_importer_cache") | ||||
|     pprint(sys.path_importer_cache) | ||||
|     print("sys.modules:") | ||||
|     pprint(sys.modules) | ||||
|     for name in args.attributes: | ||||
|         print("sys.{}:".format(name)) | ||||
|         pprint(getattr(sys, name)) | ||||
| 
 | ||||
| def _add_dump_args(cmd): | ||||
|     cmd.add_argument("attributes", metavar="ATTR", nargs="+", | ||||
|                      help="sys module attribute to display") | ||||
| 
 | ||||
| COMMANDS = ( | ||||
|   ("dump", "Dump import state", _dump_state), | ||||
|   ("dump", "Dump import state", _dump_state, _add_dump_args), | ||||
| ) | ||||
| 
 | ||||
| def _make_parser(): | ||||
|     parser = argparse.ArgumentParser() | ||||
|     sub = parser.add_subparsers(title="Commands") | ||||
|     for name, description, implementation in COMMANDS: | ||||
|     for name, description, implementation, add_args in COMMANDS: | ||||
|         cmd = sub.add_parser(name, help=description) | ||||
|         cmd.set_defaults(command=implementation) | ||||
|         add_args(cmd) | ||||
|     return parser | ||||
| 
 | ||||
| def main(args): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nick Coghlan
						Nick Coghlan