Coverage for python/lsst/ctrl/mpexec/taskFactory.py: 31%

25 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-04-12 02:11 -0700

1# This file is part of ctrl_mpexec. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ["TaskFactory"] 

25 

26import logging 

27from collections.abc import Iterable 

28from typing import TYPE_CHECKING, Any 

29 

30from lsst.pipe.base import TaskFactory as BaseTaskFactory 

31 

32if TYPE_CHECKING: 32 ↛ 33line 32 didn't jump to line 33, because the condition on line 32 was never true

33 from lsst.daf.butler import DatasetRef, LimitedButler 

34 from lsst.pipe.base import PipelineTask, TaskDef 

35 

36_LOG = logging.getLogger(__name__) 

37 

38 

39class TaskFactory(BaseTaskFactory): 

40 """Class instantiating PipelineTasks.""" 

41 

42 def makeTask( 

43 self, taskDef: TaskDef, butler: LimitedButler, initInputRefs: Iterable[DatasetRef] | None 

44 ) -> PipelineTask: 

45 # docstring inherited 

46 

47 config = taskDef.config 

48 

49 # Get init inputs from butler. 

50 init_inputs: dict[str, Any] = {} 

51 if initInputRefs: 

52 connections = config.connections.ConnectionsClass(config=config) 

53 for name in connections.initInputs: 

54 attribute = getattr(connections, name) 

55 dataset_type_name = attribute.name 

56 for ref in initInputRefs: 

57 if ref.datasetType.name == dataset_type_name: 

58 init_inputs[name] = butler.get(ref) 

59 break 

60 

61 # make task instance 

62 task = taskDef.taskClass(config=config, initInputs=init_inputs, name=taskDef.label) 

63 return task