mirror of
				https://github.com/clearml/clearml-agent
				synced 2025-06-26 18:16:15 +00:00 
			
		
		
		
	Fix pip freeze dump to comply with yaml fancy print
This commit is contained in:
		
							parent
							
								
									546ffff95d
								
							
						
					
					
						commit
						8f28d2882a
					
				| @ -91,7 +91,6 @@ from clearml_agent.errors import ( | ||||
| from clearml_agent.helper.base import ( | ||||
|     return_list, | ||||
|     print_parameters, | ||||
|     dump_yaml, | ||||
|     warning, | ||||
|     normalize_path, | ||||
|     check_directory_path, | ||||
| @ -110,7 +109,7 @@ from clearml_agent.helper.base import ( | ||||
|     is_linux_platform, | ||||
|     rm_file, | ||||
|     add_python_path, | ||||
|     safe_remove_tree, get_python_version, | ||||
|     safe_remove_tree, get_python_version, dump_flat_dict, | ||||
| ) | ||||
| from clearml_agent.helper.check_update import start_check_update_daemon | ||||
| from clearml_agent.helper.console import ensure_text, print_text, decode_binary_lines | ||||
| @ -2471,7 +2470,7 @@ class Worker(ServiceCommandSection): | ||||
|         print("Restoring running environment of task id [%s]:" % task_id) | ||||
|         if freeze: | ||||
|             print("Summary - installed python packages:") | ||||
|             print(dump_yaml(freeze)) | ||||
|             print(dump_flat_dict(freeze)) | ||||
|         else: | ||||
|             print("No freeze information available") | ||||
| 
 | ||||
| @ -2989,7 +2988,7 @@ class Worker(ServiceCommandSection): | ||||
| 
 | ||||
|         if freeze: | ||||
|             print("Summary - installed python packages:") | ||||
|             print(dump_yaml(freeze)) | ||||
|             print(dump_flat_dict(freeze)) | ||||
|         else: | ||||
|             print("No freeze information available") | ||||
| 
 | ||||
|  | ||||
| @ -22,7 +22,7 @@ from .._vendor import furl | ||||
| from .._vendor import six | ||||
| from .._vendor.attr import fields_dict | ||||
| from .._vendor.pathlib2 import Path | ||||
| from .._vendor.six.moves import reduce | ||||
| from .._vendor.six.moves import reduce  # noqa | ||||
| from .._vendor import pyyaml as yaml | ||||
| 
 | ||||
| from clearml_agent.errors import CommandFailedError | ||||
| @ -310,6 +310,30 @@ def dump_yaml(obj, path=None, dump_all=False, **kwargs): | ||||
|         dump_func(obj, output, **base_kwargs) | ||||
| 
 | ||||
| 
 | ||||
| def _dump_flat_dict(flat_dict): | ||||
|     if not isinstance(flat_dict, (dict, )): | ||||
|         flat_dict = {"": flat_dict} | ||||
| 
 | ||||
|     out = "" | ||||
|     for k in flat_dict.keys(): | ||||
|         out += "{}:\n".format(k) | ||||
|         values = flat_dict[k] | ||||
|         if not isinstance(values, (list, tuple)): | ||||
|             values = [values] | ||||
|         for v in values: | ||||
|             out += "- {}\n".format(v) | ||||
| 
 | ||||
|     return out | ||||
| 
 | ||||
| 
 | ||||
| def dump_flat_dict(flat_dict): | ||||
|     # noinspection PyBroadException | ||||
|     try: | ||||
|         return _dump_flat_dict(flat_dict) | ||||
|     except Exception: | ||||
|         return dump_yaml(flat_dict) | ||||
| 
 | ||||
| 
 | ||||
| def one_value(dct): | ||||
|     return next(iter(six.itervalues(dct))) | ||||
| 
 | ||||
|  | ||||
| @ -32,7 +32,13 @@ class SystemPip(PackageManager): | ||||
|         pass | ||||
| 
 | ||||
|     def install_from_file(self, path): | ||||
|         self.run_with_env(('install', '-r', path) + self.install_flags(), cwd=self.cwd) | ||||
|         try: | ||||
|             self.run_with_env(('install', '-r', path) + self.install_flags(), cwd=self.cwd) | ||||
|         except Exception: | ||||
|             print("ERROR: installing pip requirements failed, requirements.txt:\n{}\n".format( | ||||
|                 "\n".join([line for line in Path(path).read_text().splitlines() if line.strip()]) | ||||
|             )) | ||||
|             raise | ||||
| 
 | ||||
|     def install_packages(self, *packages): | ||||
|         self._install(*(packages + self.install_flags())) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 clearml
						clearml