From 347ff17f7d8cab0202f155bd1af079875626f614 Mon Sep 17 00:00:00 2001 From: Mamoru Miura Date: Thu, 9 Jan 2025 10:11:35 +0900 Subject: [PATCH] Log task ID to locate its cache (#423) * chore: log task ID * to make it easier for us to locate tasks' cache * test: confirm to include task ID in repr and str --- gokart/task.py | 8 +++++--- test/test_task_on_kart.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gokart/task.py b/gokart/task.py index a7f7a06d..1ef1e569 100644 --- a/gokart/task.py +++ b/gokart/task.py @@ -540,13 +540,15 @@ def _get_module_versions(self) -> str: def __repr__(self): """ - Build a task representation like `MyTask(param1=1.5, param2='5', data_task=DataTask(id=35tyi))` + Build a task representation like + `MyTask[aca2f28555dadd0f1e3dee3d4b973651](param1=1.5, param2='5', data_task=DataTask(c1f5d06aa580c5761c55bd83b18b0b4e))` """ return self._get_task_string() def __str__(self): """ - Build a human-readable task representation like `MyTask(param1=1.5, param2='5', data_task=DataTask(id=35tyi))` + Build a human-readable task representation like + `MyTask[aca2f28555dadd0f1e3dee3d4b973651](param1=1.5, param2='5', data_task=DataTask(c1f5d06aa580c5761c55bd83b18b0b4e))` This includes only public parameters """ return self._get_task_string(only_public=True) @@ -566,7 +568,7 @@ def _get_task_string(self, only_public=False): if param_obj.significant and ((not only_public) or param_obj.visibility == ParameterVisibility.PUBLIC): repr_parts.append(f'{param_name}={self._make_representation(param_obj, param_value)}') - task_str = f'{self.get_task_family()}({", ".join(repr_parts)})' + task_str = f'{self.get_task_family()}[{self.make_unique_id()}]({", ".join(repr_parts)})' return task_str def _make_representation(self, param_obj: luigi.Parameter, param_value): diff --git a/test/test_task_on_kart.py b/test/test_task_on_kart.py index e3946b49..8e8ef9dd 100644 --- a/test/test_task_on_kart.py +++ b/test/test_task_on_kart.py @@ -550,9 +550,10 @@ def test_repr(self): task_param=_DummySubTaskWithPrivateParameter(), list_task_param=[_DummySubTaskWithPrivateParameter(), _DummySubTaskWithPrivateParameter()], ) + task_id = task.make_unique_id() sub_task_id = _DummySubTaskWithPrivateParameter().make_unique_id() expected = ( - f'{__name__}._DummyTaskWithPrivateParameter(int_param=1, private_int_param=1, task_param={__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), ' + f'{__name__}._DummyTaskWithPrivateParameter[{task_id}](int_param=1, private_int_param=1, task_param={__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), ' f'list_task_param=[{__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), {__name__}._DummySubTaskWithPrivateParameter({sub_task_id})])' ) # noqa:E501 self.assertEqual(expected, repr(task)) @@ -564,9 +565,10 @@ def test_str(self): task_param=_DummySubTaskWithPrivateParameter(), list_task_param=[_DummySubTaskWithPrivateParameter(), _DummySubTaskWithPrivateParameter()], ) + task_id = task.make_unique_id() sub_task_id = _DummySubTaskWithPrivateParameter().make_unique_id() expected = ( - f'{__name__}._DummyTaskWithPrivateParameter(int_param=1, task_param={__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), ' + f'{__name__}._DummyTaskWithPrivateParameter[{task_id}](int_param=1, task_param={__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), ' f'list_task_param=[{__name__}._DummySubTaskWithPrivateParameter({sub_task_id}), {__name__}._DummySubTaskWithPrivateParameter({sub_task_id})])' ) self.assertEqual(expected, str(task))