Coverage for python/lsst/daf/butler/cli/opt/optionGroups.py: 92%

18 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-05 09:58 +0000

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# (https://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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

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

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

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

18# (at your option) any later version. 

19# 

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

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

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

23# GNU General Public License for more details. 

24# 

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

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

27 

28 

29__all__ = ("query_datasets_options",) 

30 

31 

32import click 

33 

34from ..utils import OptionGroup, unwrap, where_help 

35from .arguments import glob_argument, repo_argument 

36from .options import collections_option, dataset_type_option, where_option 

37 

38 

39class query_datasets_options(OptionGroup): # noqa: N801 

40 """A collection of options common to querying datasets. 

41 

42 Parameters 

43 ---------- 

44 repo : `bool` 

45 The Butler repository URI. 

46 showUri : `bool` 

47 Whether to include the dataset URI. 

48 useArguments : `bool 

49 Whether this is an argument or an option. 

50 """ 

51 

52 def __init__(self, repo: bool = True, showUri: bool = True, useArguments: bool = True) -> None: 

53 self.decorators = [] 

54 if repo: 

55 if not useArguments: 55 ↛ 56line 55 didn't jump to line 56, because the condition on line 55 was never true

56 raise RuntimeError("repo as an option is not currently supported.") 

57 self.decorators.append(repo_argument(required=True)) 

58 if useArguments: 

59 self.decorators.append( 

60 glob_argument( 

61 help=unwrap( 

62 """GLOB is one or more glob-style expressions that fully or partially identify the 

63 dataset type names to be queried.""" 

64 ) 

65 ) 

66 ) 

67 else: 

68 self.decorators.append( 

69 dataset_type_option( 

70 help=unwrap( 

71 """One or more glob-style expressions that fully or partially identify the dataset 

72 type names to be queried.""" 

73 ) 

74 ) 

75 ) 

76 self.decorators.extend( 

77 [ 

78 collections_option(), 

79 where_option(help=where_help), 

80 click.option( 

81 "--find-first", 

82 is_flag=True, 

83 help=unwrap( 

84 """For each result data ID, only yield one DatasetRef of each 

85 DatasetType, from the first collection in which a dataset of that dataset 

86 type appears (according to the order of 'collections' passed in). If 

87 used, 'collections' must specify at least one expression and must not 

88 contain wildcards.""" 

89 ), 

90 ), 

91 ] 

92 ) 

93 if showUri: 

94 self.decorators.append( 

95 click.option("--show-uri", is_flag=True, help="Show the dataset URI in results.") 

96 )