Skip to content

Commit

Permalink
Log task ID to locate its cache (#423)
Browse files Browse the repository at this point in the history
* chore: log task ID

* to make it easier for us to locate tasks' cache

* test: confirm to include task ID in repr and str
  • Loading branch information
mamo3gr authored Jan 9, 2025
1 parent ff42bf4 commit 347ff17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions test/test_task_on_kart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 347ff17

Please sign in to comment.