From c4f97cf755126cdfe841df027a292a85aeceb3df Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 6 May 2024 13:38:10 +0300 Subject: [PATCH] [Deprecations] Add Deprecation Warnings to Artifact Constructor Params (#5520) --- mlrun/artifacts/base.py | 31 ++++++++++++++++++++++++++++--- mlrun/artifacts/dataset.py | 8 ++++++++ mlrun/artifacts/model.py | 7 +++++++ mlrun/artifacts/plots.py | 13 +++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/mlrun/artifacts/base.py b/mlrun/artifacts/base.py index ddc859a5501..e56c6b917f7 100644 --- a/mlrun/artifacts/base.py +++ b/mlrun/artifacts/base.py @@ -191,12 +191,30 @@ def __init__( format=None, size=None, target_path=None, - # All params up until here are legacy params for compatibility with legacy artifacts. project=None, + src_path: str = None, + # All params up until here are legacy params for compatibility with legacy artifacts. + # TODO: remove them in 1.9.0. metadata: ArtifactMetadata = None, spec: ArtifactSpec = None, - src_path: str = None, ): + if ( + key + or body + or viewer + or is_inline + or format + or size + or target_path + or project + or src_path + ): + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) + self._metadata = None self.metadata = metadata self._spec = None @@ -698,11 +716,18 @@ def __init__( link_iteration=None, link_key=None, link_tree=None, - # All params up until here are legacy params for compatibility with legacy artifacts. project=None, + # All params up until here are legacy params for compatibility with legacy artifacts. + # TODO: remove them in 1.9.0. metadata: ArtifactMetadata = None, spec: LinkArtifactSpec = None, ): + if key or target_path or link_iteration or link_key or link_tree or project: + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) super().__init__( key, target_path=target_path, project=project, metadata=metadata, spec=spec ) diff --git a/mlrun/artifacts/dataset.py b/mlrun/artifacts/dataset.py index e1d62261f91..fab6cccc098 100644 --- a/mlrun/artifacts/dataset.py +++ b/mlrun/artifacts/dataset.py @@ -13,6 +13,7 @@ # limitations under the License. import os import pathlib +import warnings from io import StringIO from typing import Optional @@ -160,6 +161,13 @@ def __init__( label_column: str = None, **kwargs, ): + if key or format or target_path: + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) + format = (format or "").lower() super().__init__(key, None, format=format, target_path=target_path) if format and format not in self.SUPPORTED_FORMATS: diff --git a/mlrun/artifacts/model.py b/mlrun/artifacts/model.py index 716ed1a6ebb..48fe6fd052d 100644 --- a/mlrun/artifacts/model.py +++ b/mlrun/artifacts/model.py @@ -13,6 +13,7 @@ # limitations under the License. import tempfile +import warnings from os import path from typing import Any, Optional @@ -148,6 +149,12 @@ def __init__( model_dir=None, **kwargs, ): + if key or body or format or target_path: + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) super().__init__(key, body, format=format, target_path=target_path, **kwargs) model_file = str(model_file or "") if model_file and "/" in model_file: diff --git a/mlrun/artifacts/plots.py b/mlrun/artifacts/plots.py index e2675c29a5c..7080cd1c569 100644 --- a/mlrun/artifacts/plots.py +++ b/mlrun/artifacts/plots.py @@ -13,6 +13,7 @@ # limitations under the License. import base64 import typing +import warnings from io import BytesIO import mlrun @@ -34,6 +35,12 @@ class PlotArtifact(Artifact): def __init__( self, key=None, body=None, is_inline=False, target_path=None, title=None ): + if key or body or is_inline or target_path: + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) super().__init__(key, body, format="html", target_path=target_path) self.metadata.description = title @@ -87,6 +94,12 @@ def __init__( :param key: Key for the artifact to be stored in the database. :param target_path: Path to save the artifact. """ + if key or target_path: + warnings.warn( + "Artifact constructor parameters are deprecated and will be removed in 1.9.0. " + "Use the metadata and spec parameters instead.", + DeprecationWarning, + ) # Validate the plotly package: try: from plotly.graph_objs import Figure