mirror of
				https://github.com/clearml/clearml
				synced 2025-06-26 18:16:07 +00:00 
			
		
		
		
	flake8 + change ModuleNotFoundError to ImportError (support py 2.7/3.5)
This commit is contained in:
		
							parent
							
								
									a8d6380696
								
							
						
					
					
						commit
						23394a265d
					
				| @ -383,7 +383,8 @@ class SearchStrategy(object): | |||||||
| 
 | 
 | ||||||
|         If returns ``False``, the job was aborted / completed, and should be taken off the current job list |         If returns ``False``, the job was aborted / completed, and should be taken off the current job list | ||||||
| 
 | 
 | ||||||
|         If there is a budget limitation, this call should update ``self.budget.compute_time.update`` / ``self.budget.iterations.update`` |         If there is a budget limitation, this call should update | ||||||
|  |         ``self.budget.compute_time.update`` / ``self.budget.iterations.update`` | ||||||
| 
 | 
 | ||||||
|         :param TrainsJob job: A ``TrainsJob`` object to monitor. |         :param TrainsJob job: A ``TrainsJob`` object to monitor. | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,8 @@ | |||||||
| from time import sleep, time | from time import sleep | ||||||
| from typing import Any, Optional, Sequence | from typing import Any, Optional, Sequence | ||||||
| 
 | 
 | ||||||
| from ..optimization import Objective, SearchStrategy | from ..optimization import Objective, SearchStrategy | ||||||
| from ..parameters import ( | from ..parameters import (DiscreteParameterRange, Parameter, UniformIntegerParameterRange, UniformParameterRange) | ||||||
|     DiscreteParameterRange, UniformParameterRange, RandomSeed, UniformIntegerParameterRange, Parameter, ) |  | ||||||
| from ...task import Task | from ...task import Task | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|  | |||||||
| @ -57,10 +57,10 @@ class ExtApiServiceProxy(ApiServiceProxy): | |||||||
|         for module_path in self._get_services_modules(): |         for module_path in self._get_services_modules(): | ||||||
|             try: |             try: | ||||||
|                 return importlib.import_module(name, package=module_path) |                 return importlib.import_module(name, package=module_path) | ||||||
|             except ModuleNotFoundError: |             except ImportError: | ||||||
|                 pass |                 pass | ||||||
| 
 | 
 | ||||||
|         raise ModuleNotFoundError( |         raise ImportError( | ||||||
|             "No module '{}' in all predefined services module paths".format(name) |             "No module '{}' in all predefined services module paths".format(name) | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -311,8 +311,8 @@ class Config(object): | |||||||
|         try: |         try: | ||||||
|             return ConfigFactory.parse_file(file_path) |             return ConfigFactory.parse_file(file_path) | ||||||
|         except ParseSyntaxException as ex: |         except ParseSyntaxException as ex: | ||||||
|             msg = "Failed parsing {0} ({1.__class__.__name__}): (at char {1.loc}, line:{1.lineno}, col:{1.column})".format( |             msg = "Failed parsing {0} ({1.__class__.__name__}): " \ | ||||||
|                 file_path, ex) |                   "(at char {1.loc}, line:{1.lineno}, col:{1.column})".format(file_path, ex) | ||||||
|             six.reraise( |             six.reraise( | ||||||
|                 ConfigurationError, |                 ConfigurationError, | ||||||
|                 ConfigurationError(msg, file_path=file_path), |                 ConfigurationError(msg, file_path=file_path), | ||||||
|  | |||||||
| @ -65,8 +65,8 @@ class Metrics(InterfaceBase): | |||||||
|         """ |         """ | ||||||
|         Write events to the backend, uploading any required files. |         Write events to the backend, uploading any required files. | ||||||
|         :param events: A list of event objects |         :param events: A list of event objects | ||||||
|         :param async_enable: If True, upload is performed asynchronously and an AsyncResult object is returned, otherwise a |         :param async_enable: If True, upload is performed asynchronously and an AsyncResult object is returned, | ||||||
|             blocking call is made and the upload result is returned. |             otherwise a blocking call is made and the upload result is returned. | ||||||
|         :param callback: A optional callback called when upload was completed in case async is True |         :param callback: A optional callback called when upload was completed in case async is True | ||||||
|         :return: .backend_api.session.CallResult if async is False otherwise AsyncResult. Note that if no events were |         :return: .backend_api.session.CallResult if async is False otherwise AsyncResult. Note that if no events were | ||||||
|             sent, None will be returned. |             sent, None will be returned. | ||||||
|  | |||||||
| @ -226,7 +226,8 @@ class _Arguments(object): | |||||||
|                     # if we have an int, we should cast to float, because it is more generic |                     # if we have an int, we should cast to float, because it is more generic | ||||||
|                     if var_type == int: |                     if var_type == int: | ||||||
|                         var_type = float |                         var_type = float | ||||||
|                     elif var_type == type(None):  # noqa: E721 - do not change! because isinstance(var_type, type(None)) === False |                     elif var_type == type(None):  # noqa: E721 - do not change! | ||||||
|  |                         # because isinstance(var_type, type(None)) === False | ||||||
|                         var_type = str |                         var_type = str | ||||||
|                     # now we should try and cast the value if we can |                     # now we should try and cast the value if we can | ||||||
|                     try: |                     try: | ||||||
|  | |||||||
| @ -473,7 +473,7 @@ class Artifacts(object): | |||||||
|             try: |             try: | ||||||
|                 with open(local_filename, 'wt') as f: |                 with open(local_filename, 'wt') as f: | ||||||
|                     f.write(artifact_object) |                     f.write(artifact_object) | ||||||
|             except Exception as ex: |             except Exception: | ||||||
|                 # cleanup and raise exception |                 # cleanup and raise exception | ||||||
|                 os.unlink(local_filename) |                 os.unlink(local_filename) | ||||||
|                 raise |                 raise | ||||||
| @ -495,7 +495,7 @@ class Artifacts(object): | |||||||
|             try: |             try: | ||||||
|                 with open(local_filename, 'wb') as f: |                 with open(local_filename, 'wb') as f: | ||||||
|                     pickle.dump(artifact_object, f) |                     pickle.dump(artifact_object, f) | ||||||
|             except Exception as ex: |             except Exception: | ||||||
|                 # cleanup and raise exception |                 # cleanup and raise exception | ||||||
|                 os.unlink(local_filename) |                 os.unlink(local_filename) | ||||||
|                 raise |                 raise | ||||||
|  | |||||||
| @ -109,7 +109,7 @@ class WeightsFileHandler(object): | |||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     def add_pre_callback(cls, callback_function): |     def add_pre_callback(cls, callback_function): | ||||||
|         # type: (Callable[[Union[str, WeightsFileHandler.CallbackType], WeightsFileHandler.ModelInfo], Optional[WeightsFileHandler.ModelInfo]]) -> int |         # type: (Callable[[Union[str, WeightsFileHandler.CallbackType], WeightsFileHandler.ModelInfo], Optional[WeightsFileHandler.ModelInfo]]) -> int  # noqa | ||||||
|         """ |         """ | ||||||
|         Add a pre-save/load callback for weights files and return its handle. If the callback was already added, |         Add a pre-save/load callback for weights files and return its handle. If the callback was already added, | ||||||
|          return the existing handle. |          return the existing handle. | ||||||
| @ -127,7 +127,7 @@ class WeightsFileHandler(object): | |||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     def add_post_callback(cls, callback_function): |     def add_post_callback(cls, callback_function): | ||||||
|         # type: (Callable[[Union[str, WeightsFileHandler.CallbackType], WeightsFileHandler.ModelInfo], WeightsFileHandler.ModelInfo]) -> int |         # type: (Callable[[Union[str, WeightsFileHandler.CallbackType], WeightsFileHandler.ModelInfo], WeightsFileHandler.ModelInfo]) -> int  # noqa | ||||||
|         """ |         """ | ||||||
|         Add a post-save/load callback for weights files and return its handle. |         Add a post-save/load callback for weights files and return its handle. | ||||||
|         If the callback was already added, return the existing handle. |         If the callback was already added, return the existing handle. | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ class PatchFastai(object): | |||||||
|         try: |         try: | ||||||
|             PatchFastai.__metrics_names = ["train_loss"] if recorder.no_val else ["train_loss", "valid_loss"] |             PatchFastai.__metrics_names = ["train_loss"] if recorder.no_val else ["train_loss", "valid_loss"] | ||||||
|             PatchFastai.__metrics_names += recorder.metrics_names |             PatchFastai.__metrics_names += recorder.metrics_names | ||||||
|         except Exception as ex: |         except Exception: | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
| @ -84,7 +84,7 @@ class PatchFastai(object): | |||||||
|             iteration = kwargs.get("iteration", 0) |             iteration = kwargs.get("iteration", 0) | ||||||
|             for name, val in stats_report.items(): |             for name, val in stats_report.items(): | ||||||
|                 logger.report_scalar(title="model_stats_gradients", series=name, value=val, iteration=iteration) |                 logger.report_scalar(title="model_stats_gradients", series=name, value=val, iteration=iteration) | ||||||
|         except Exception as ex: |         except Exception: | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|  | |||||||
| @ -74,5 +74,6 @@ class PostImportHookPatching(object): | |||||||
| 
 | 
 | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def remove_on_import(name, func): |     def remove_on_import(name, func): | ||||||
|         if name in PostImportHookPatching._post_import_hooks and func in PostImportHookPatching._post_import_hooks[name]: |         if name in PostImportHookPatching._post_import_hooks and \ | ||||||
|  |                 func in PostImportHookPatching._post_import_hooks[name]: | ||||||
|             PostImportHookPatching._post_import_hooks[name].remove(func) |             PostImportHookPatching._post_import_hooks[name].remove(func) | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ def get_cache_dir(): | |||||||
|     cache_base_dir = Path(  # noqa: F405 |     cache_base_dir = Path(  # noqa: F405 | ||||||
|         expandvars( |         expandvars( | ||||||
|             expanduser( |             expanduser( | ||||||
|                 TRAINS_CACHE_DIR.get() or |                 TRAINS_CACHE_DIR.get() or  # noqa: F405 | ||||||
|                 config.get("storage.cache.default_base_dir") or |                 config.get("storage.cache.default_base_dir") or | ||||||
|                 DEFAULT_CACHE_DIR  # noqa: F405 |                 DEFAULT_CACHE_DIR  # noqa: F405 | ||||||
|             ) |             ) | ||||||
|  | |||||||
| @ -2375,7 +2375,7 @@ class Task(_Task): | |||||||
|                             relative_file_name = filename.relative_to(offline_folder).as_posix() |                             relative_file_name = filename.relative_to(offline_folder).as_posix() | ||||||
|                             zf.write(filename.as_posix(), arcname=relative_file_name) |                             zf.write(filename.as_posix(), arcname=relative_file_name) | ||||||
|                 print('TRAINS Task: Offline session stored in {}'.format(zip_file)) |                 print('TRAINS Task: Offline session stored in {}'.format(zip_file)) | ||||||
|             except Exception as ex: |             except Exception: | ||||||
|                 pass |                 pass | ||||||
| 
 | 
 | ||||||
|         # delete locking object (lock file) |         # delete locking object (lock file) | ||||||
|  | |||||||
| @ -61,9 +61,9 @@ class DeferredExecution(object): | |||||||
|     def defer_execution(self, condition_or_attr_name=True): |     def defer_execution(self, condition_or_attr_name=True): | ||||||
|         """ |         """ | ||||||
|         Deferred execution decorator, designed to wrap class functions for classes containing a deferred execution pool. |         Deferred execution decorator, designed to wrap class functions for classes containing a deferred execution pool. | ||||||
|         :param condition_or_attr_name: Condition controlling whether wrapped function should be deferred. True by default. |         :param condition_or_attr_name: Condition controlling whether wrapped function should be deferred. | ||||||
|             If a callable is provided, it will be called with the class instance (self) as first argument. |             True by default. If a callable is provided, it will be called with the class instance (self) | ||||||
|             If a string is provided, a class instance (self) attribute by that name is evaluated. |             as first argument. If a string is provided, a class instance (self) attribute by that name is evaluated. | ||||||
|         :return: |         :return: | ||||||
|         """ |         """ | ||||||
|         def decorator(func): |         def decorator(func): | ||||||
|  | |||||||
| @ -147,7 +147,8 @@ def create_2d_scatter_series(np_row_wise, title="Scatter", series_name="Series", | |||||||
|     :param layout_config: optional dictionary for layout configuration, passed directly to plotly |     :param layout_config: optional dictionary for layout configuration, passed directly to plotly | ||||||
|     :return: Plotly chart dict. |     :return: Plotly chart dict. | ||||||
|     """ |     """ | ||||||
|     plotly_obj = _plotly_scatter_layout_dict(title=title, xaxis_title=xtitle, yaxis_title=ytitle, comment=comment)  # noqa: F841 |     plotly_obj = _plotly_scatter_layout_dict(  # noqa: F841 | ||||||
|  |         title=title, xaxis_title=xtitle, yaxis_title=ytitle, comment=comment) | ||||||
|     assert np_row_wise.ndim == 2, "Expected a 2D numpy array" |     assert np_row_wise.ndim == 2, "Expected a 2D numpy array" | ||||||
|     assert np_row_wise.shape[1] == 2, "Expected two columns X/Y e.g. [(x0,y0), (x1,y1) ...]" |     assert np_row_wise.shape[1] == 2, "Expected two columns X/Y e.g. [(x0,y0), (x1,y1) ...]" | ||||||
| 
 | 
 | ||||||
| @ -481,7 +482,8 @@ def create_plotly_table(table_plot, title, series, layout_config=None): | |||||||
|     """ |     """ | ||||||
|     if not pd: |     if not pd: | ||||||
|         raise UsageError( |         raise UsageError( | ||||||
|             "pandas is required in order to support reporting tables using CSV or a URL, please install the pandas python package" |             "pandas is required in order to support reporting tables using CSV or a URL, " | ||||||
|  |             "please install the pandas python package" | ||||||
|         ) |         ) | ||||||
|     index_added = not isinstance(table_plot.index, pd.RangeIndex) |     index_added = not isinstance(table_plot.index, pd.RangeIndex) | ||||||
|     headers_values = list([col] for col in table_plot.columns) |     headers_values = list([col] for col in table_plot.columns) | ||||||
|  | |||||||
| @ -88,7 +88,8 @@ class ConfigFactory(object): | |||||||
|         :type resolve: boolean |         :type resolve: boolean | ||||||
|         :param unresolved_value: assigned value value to unresolved substitution. |         :param unresolved_value: assigned value value to unresolved substitution. | ||||||
|             If overriden with a default value, it will replace all unresolved value to the default value. |             If overriden with a default value, it will replace all unresolved value to the default value. | ||||||
|         If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its substitution expression (e.g., ${x}) |             If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its | ||||||
|  |             substitution expression (e.g., ${x}) | ||||||
|         :type unresolved_value: class |         :type unresolved_value: class | ||||||
|         :return: Config object |         :return: Config object | ||||||
|         :type return: Config |         :type return: Config | ||||||
| @ -113,7 +114,8 @@ class ConfigFactory(object): | |||||||
|         :type resolve: boolean |         :type resolve: boolean | ||||||
|         :param unresolved_value: assigned value value to unresolved substitution. |         :param unresolved_value: assigned value value to unresolved substitution. | ||||||
|             If overriden with a default value, it will replace all unresolved value to the default value. |             If overriden with a default value, it will replace all unresolved value to the default value. | ||||||
|         If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its substitution expression (e.g., ${x}) |             If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by | ||||||
|  |             its substitution expression (e.g., ${x}) | ||||||
|         :type unresolved_value: boolean |         :type unresolved_value: boolean | ||||||
|         :return: Config object or [] |         :return: Config object or [] | ||||||
|         :type return: Config or list |         :type return: Config or list | ||||||
| @ -142,7 +144,8 @@ class ConfigFactory(object): | |||||||
|         :type resolve: boolean |         :type resolve: boolean | ||||||
|         :param unresolved_value: assigned value value to unresolved substitution. |         :param unresolved_value: assigned value value to unresolved substitution. | ||||||
|             If overriden with a default value, it will replace all unresolved value to the default value. |             If overriden with a default value, it will replace all unresolved value to the default value. | ||||||
|         If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its substitution expression (e.g., ${x}) |             If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by | ||||||
|  |             its substitution expression (e.g., ${x}) | ||||||
|         :type unresolved_value: boolean |         :type unresolved_value: boolean | ||||||
|         :return: Config object |         :return: Config object | ||||||
|         :type return: Config |         :type return: Config | ||||||
| @ -235,7 +238,8 @@ class ConfigParser(object): | |||||||
|         :type resolve: boolean |         :type resolve: boolean | ||||||
|         :param unresolved_value: assigned value value to unresolved substitution. |         :param unresolved_value: assigned value value to unresolved substitution. | ||||||
|             If overriden with a default value, it will replace all unresolved value to the default value. |             If overriden with a default value, it will replace all unresolved value to the default value. | ||||||
|         If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by its substitution expression (e.g., ${x}) |             If it is set to to pyhocon.STR_SUBSTITUTION then it will replace the value by | ||||||
|  |             its substitution expression (e.g., ${x}) | ||||||
|         :type unresolved_value: boolean |         :type unresolved_value: boolean | ||||||
|         :return: a ConfigTree or a list |         :return: a ConfigTree or a list | ||||||
|         """ |         """ | ||||||
| @ -434,7 +438,8 @@ class ConfigParser(object): | |||||||
|             config = config_expr.parseString(content, parseAll=True)[0] |             config = config_expr.parseString(content, parseAll=True)[0] | ||||||
| 
 | 
 | ||||||
|             if resolve: |             if resolve: | ||||||
|                 allow_unresolved = resolve and unresolved_value is not DEFAULT_SUBSTITUTION and unresolved_value is not MANDATORY_SUBSTITUTION |                 allow_unresolved = resolve and unresolved_value is not DEFAULT_SUBSTITUTION and \ | ||||||
|  |                                    unresolved_value is not MANDATORY_SUBSTITUTION | ||||||
|                 has_unresolved = cls.resolve_substitutions(config, allow_unresolved) |                 has_unresolved = cls.resolve_substitutions(config, allow_unresolved) | ||||||
|                 if has_unresolved and unresolved_value is MANDATORY_SUBSTITUTION: |                 if has_unresolved and unresolved_value is MANDATORY_SUBSTITUTION: | ||||||
|                     raise ConfigSubstitutionException( |                     raise ConfigSubstitutionException( | ||||||
| @ -489,8 +494,8 @@ class ConfigParser(object): | |||||||
|                         if len(prop_path) > 1 and config.get(substitution.variable, None) is not None: |                         if len(prop_path) > 1 and config.get(substitution.variable, None) is not None: | ||||||
|                             continue  # If value is present in latest version, don't do anything |                             continue  # If value is present in latest version, don't do anything | ||||||
|                         if prop_path[0] == key: |                         if prop_path[0] == key: | ||||||
|                             if isinstance( |                             if isinstance(previous_item, ConfigValues) and not accept_unresolved: | ||||||
|                                     previous_item, ConfigValues) and not accept_unresolved:  # We hit a dead end, we cannot evaluate |                                 # We hit a dead end, we cannot evaluate | ||||||
|                                 raise ConfigSubstitutionException( |                                 raise ConfigSubstitutionException( | ||||||
|                                     "Property {variable} cannot be substituted. Check for cycles.".format( |                                     "Property {variable} cannot be substituted. Check for cycles.".format( | ||||||
|                                         variable=substitution.variable |                                         variable=substitution.variable | ||||||
|  | |||||||
| @ -515,7 +515,8 @@ class ConfigValues(object): | |||||||
|             tok_type = determine_type(token) |             tok_type = determine_type(token) | ||||||
|             if first_tok_type is not tok_type: |             if first_tok_type is not tok_type: | ||||||
|                 raise ConfigWrongTypeException( |                 raise ConfigWrongTypeException( | ||||||
|                     "Token '{token}' of type {tok_type} (index {index}) must be of type {req_tok_type} (line: {line}, col: {col})".format( |                     "Token '{token}' of type {tok_type} (index {index}) must be of type {req_tok_type} " | ||||||
|  |                     "(line: {line}, col: {col})".format( | ||||||
|                         token=token, |                         token=token, | ||||||
|                         index=index + 1, |                         index=index + 1, | ||||||
|                         tok_type=tok_type.__name__, |                         tok_type=tok_type.__name__, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 allegroai
						allegroai