From 028a8356767fa81669074e5e0106774b49345123 Mon Sep 17 00:00:00 2001 From: Alex Burlacu Date: Wed, 19 Jul 2023 02:11:40 +0300 Subject: [PATCH] Deprecate Task.get_by_name --- clearml/backend_interface/task/task.py | 15 --------------- clearml/task.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/clearml/backend_interface/task/task.py b/clearml/backend_interface/task/task.py index 53465a37..531c8a4c 100644 --- a/clearml/backend_interface/task/task.py +++ b/clearml/backend_interface/task/task.py @@ -2807,21 +2807,6 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin): res = cls._send(session=session, req=req, log=log) return res - @classmethod - def get_by_name(cls, task_name): - # type: (str) -> Task - """ - Returns the most recent task with the given name from anywhere in the system as a Task object. - - :param str task_name: The name of the task to search for. - - :return: Task object of the most recent task with that name. - """ - res = cls._send(cls._get_default_session(), tasks.GetAllRequest(name=exact_match_regex(task_name))) - - task = get_single_result(entity='task', query=task_name, results=res.response.tasks) - return cls(task_id=task.id) - @classmethod def get_task_output_log_web_page(cls, task_id, project_id=None, app_server_host=None): # type: (str, Optional[str], Optional[str]) -> str diff --git a/clearml/task.py b/clearml/task.py index 1becc33e..e0110af7 100644 --- a/clearml/task.py +++ b/clearml/task.py @@ -7,6 +7,7 @@ import signal import sys import threading import time +import warnings from argparse import ArgumentParser from logging import getLogger from tempfile import mkstemp, mkdtemp @@ -860,6 +861,23 @@ class Task(_Task): return task + @classmethod + def get_by_name(cls, task_name): + # type: (str) -> TaskInstance + """ + + .. note:: + This method is deprecated, use :meth:`Task.get_task` instead. + + Returns the most recent task with the given name from anywhere in the system as a Task object. + + :param str task_name: The name of the task to search for. + + :return: Task object of the most recent task with that name. + """ + warnings.warn("Warning: 'Task.get_by_name' is deprecated. Use 'Task.get_task' instead", DeprecationWarning) + return cls.get_task(task_name=task_name) + @classmethod def get_task( cls,