Skip to content

Commit

Permalink
[Deprecations] Add Deprecation Warnings to Artifact Constructor Params (
Browse files Browse the repository at this point in the history
  • Loading branch information
quaark committed May 6, 2024
1 parent 0eefbbd commit c4f97cf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
31 changes: 28 additions & 3 deletions mlrun/artifacts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
8 changes: 8 additions & 0 deletions mlrun/artifacts/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import os
import pathlib
import warnings
from io import StringIO
from typing import Optional

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions mlrun/artifacts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import tempfile
import warnings
from os import path
from typing import Any, Optional

Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions mlrun/artifacts/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import base64
import typing
import warnings
from io import BytesIO

import mlrun
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4f97cf

Please sign in to comment.