зеркало из https://github.com/Azure/aztk.git
Fix: Deprecation messages cause TypeError in non-verbose mode (#596)
* Stop deprecate() from throwing when not in verbose mode * Improve deprecation warning messages
This commit is contained in:
Родитель
7d7a814c50
Коммит
98c601ceb8
|
@ -41,11 +41,11 @@ class ClusterConfiguration(Model):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'vm_count' in kwargs:
|
||||
deprecate("vm_count is deprecated for ClusterConfiguration please use size instead")
|
||||
deprecate("vm_count is deprecated for ClusterConfiguration.", "Please use size instead.")
|
||||
kwargs['size'] = kwargs.pop('vm_count')
|
||||
|
||||
if 'vm_low_pri_count' in kwargs:
|
||||
deprecate("vm_low_pri_count is deprecated for ClusterConfiguration please use size_low_priority instead")
|
||||
deprecate("vm_low_pri_count is deprecated for ClusterConfiguration.", "Please use size_low_priority instead.")
|
||||
kwargs['size_low_priority'] = kwargs.pop('vm_low_pri_count')
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -101,7 +101,7 @@ class ClusterConfiguration(Model):
|
|||
)
|
||||
|
||||
if self.custom_scripts:
|
||||
deprecate("Custom scripts are DEPRECATED and will be removed in 0.8.0. Use plugins instead See https://aztk.readthedocs.io/en/v0.7.0/15-plugins.html")
|
||||
deprecate("Custom scripts are DEPRECATED.", "Use plugins instead. See https://aztk.readthedocs.io/en/v0.7.0/15-plugins.html.")
|
||||
|
||||
if self.scheduling_target == SchedulingTarget.Dedicated and self.size == 0:
|
||||
raise error.InvalidModelError("Scheduling target cannot be Dedicated if dedicated vm size is 0")
|
||||
|
|
|
@ -55,7 +55,7 @@ class Toolkit(Model):
|
|||
raise InvalidModelError("Toolkit '{0}' with version '{1}' is not available. Use one of: {2}".format(
|
||||
self.software, self.version, toolkit_def.versions))
|
||||
if self.version == "1.6":
|
||||
deprecate("Spark version 1.6 is being deprecated for Aztk. Please use 2.1 and above.")
|
||||
deprecate("Spark version 1.6 is being deprecated for Aztk.", "Please use 2.1 and above.")
|
||||
|
||||
if self.environment:
|
||||
if self.environment not in toolkit_def.environments:
|
||||
|
|
|
@ -28,17 +28,18 @@ def deprecated(reason: str = None):
|
|||
return decorator
|
||||
|
||||
|
||||
def deprecate(message: str):
|
||||
def deprecate(message: str, advice: str = ""):
|
||||
"""
|
||||
Print a deprecate warning.
|
||||
Print a deprecation warning.
|
||||
|
||||
Args:
|
||||
message (str): Message to print
|
||||
message (str): Sentence explaining what is deprecated.
|
||||
advice (str): Sentence explaining alternatives to the deprecated functionality.
|
||||
"""
|
||||
|
||||
deprecated_version = _get_deprecated_version()
|
||||
warnings.simplefilter('always', DeprecationWarning) # turn off filter
|
||||
warnings.warn("{0} It will be removed in Aztk version {1}".format(message, deprecated_version),
|
||||
warnings.warn("{0} It will be removed in Aztk version {1}. {2}".format(message, deprecated_version, advice),
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2)
|
||||
warnings.simplefilter('default', DeprecationWarning) # reset filter
|
||||
|
|
|
@ -46,7 +46,7 @@ def _load_config_file(path: str):
|
|||
|
||||
def _merge_secrets_dict(secrets: SecretsConfiguration, secrets_config):
|
||||
if 'default' in secrets_config:
|
||||
deprecate("default key in secrets.yaml is deprecated. Place all child parameters directly at the root")
|
||||
deprecate("default key in secrets.yaml is deprecated.", "Place all child parameters directly at the root")
|
||||
secrets_config = dict(**secrets_config, **secrets_config.pop('default'))
|
||||
|
||||
other = SecretsConfiguration.from_dict(secrets_config)
|
||||
|
|
|
@ -16,7 +16,7 @@ from . import plugins, toolkit
|
|||
|
||||
# Makes sure the warnings are displayed nicely in the CLI without a stacktrace
|
||||
def _show_warn(message, *_args):
|
||||
log.warning(message)
|
||||
log.warning(str(message))
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -44,7 +44,7 @@ def execute(args: typing.NamedTuple):
|
|||
file_config, wait = config.read_cluster_config()
|
||||
cluster_conf.merge(file_config)
|
||||
if args.size_low_pri is not None:
|
||||
deprecate("--size-low-pri has been deprecated. Please use --size-low-priority")
|
||||
deprecate("--size-low-pri has been deprecated.", "Please use --size-low-priority.")
|
||||
args.size_low_priority = args.size_low_pri
|
||||
|
||||
cluster_conf.merge(ClusterConfiguration(
|
||||
|
|
Загрузка…
Ссылка в новой задаче