21
21
from planemo .cli import PlanemoCliContext
22
22
23
23
PLANEMO_CONFIG_ENV_PROP = "PLANEMO_GLOBAL_CONFIG_PATH"
24
- DEFAULT_CONFIG = {} # type : Dict[str, Any]
24
+ DEFAULT_CONFIG : Dict [str , Any ] = {}
25
25
26
26
VALUE_UNSET = object ()
27
27
30
30
31
31
32
32
def _default_callback (
33
- default : Optional [ Union [ bool , int , str ]] ,
33
+ default : Any ,
34
34
use_global_config : bool = False ,
35
- resolve_path : Optional [ bool ] = False ,
36
- extra_global_config_vars : List [Union [ Any , str ] ] = [],
35
+ resolve_path : bool = False ,
36
+ extra_global_config_vars : List [str ] = [],
37
37
) -> Callable :
38
38
def callback (ctx , param , value ):
39
39
planemo_ctx = ctx .obj
@@ -66,11 +66,11 @@ def callback(ctx, param, value):
66
66
67
67
68
68
def _find_default (
69
- ctx : "PlanemoCliContext" , param : Option , use_global_config : bool , extra_global_config_vars : List [Union [ Any , str ] ]
70
- ) -> Tuple [object , None ]:
69
+ ctx : "PlanemoCliContext" , param : Option , use_global_config : bool , extra_global_config_vars : List [str ]
70
+ ) -> Union [ Tuple [Any , OptionSource ], Tuple [ object , None ] ]:
71
71
if use_global_config :
72
72
global_config = ctx .global_config
73
- global_config_keys = ["default_%s" % param .name ] + extra_global_config_vars
73
+ global_config_keys = [f "default_{ param .name } " ] + extra_global_config_vars
74
74
for global_config_key in global_config_keys :
75
75
if global_config_key in global_config :
76
76
default_value = global_config [global_config_key ]
@@ -87,7 +87,7 @@ def planemo_option(*args, **kwargs) -> Callable:
87
87
defaults from ~/.planemo.yml, and tracks how parameters are specified
88
88
using the Planemo Context object.
89
89
"""
90
- option_type = kwargs .get ("type" , None )
90
+ option_type = kwargs .get ("type" )
91
91
use_global_config = kwargs .pop ("use_global_config" , False )
92
92
use_env_var = kwargs .pop ("use_env_var" , False )
93
93
extra_global_config_vars = kwargs .pop ("extra_global_config_vars" , [])
@@ -101,7 +101,7 @@ def planemo_option(*args, **kwargs) -> Callable:
101
101
outer_callback = kwargs .pop ("callback" , None )
102
102
103
103
def callback (ctx , param , value ):
104
- resolve_path = option_type and getattr (option_type , "resolve_path" , False )
104
+ resolve_path = bool ( option_type and getattr (option_type , "resolve_path" , False ) )
105
105
result = _default_callback (
106
106
default ,
107
107
use_global_config = use_global_config ,
@@ -125,7 +125,7 @@ def callback(ctx, param, value):
125
125
if arg .startswith ("--" ):
126
126
name = arg [len ("--" ) :]
127
127
assert name
128
- kwargs ["envvar" ] = "PLANEMO_%s" % name .upper ()
128
+ kwargs ["envvar" ] = f "PLANEMO_{ name .upper ()} "
129
129
130
130
option = click .option (* args , ** kwargs )
131
131
return option
@@ -138,7 +138,7 @@ def global_config_path(config_path: Optional[str] = None) -> str:
138
138
return config_path
139
139
140
140
141
- def read_global_config (config_path : str ) -> Dict [Any , Any ]:
141
+ def read_global_config (config_path : Optional [ str ] ) -> Dict [str , Any ]:
142
142
config_path = global_config_path (config_path )
143
143
if not os .path .exists (config_path ):
144
144
return DEFAULT_CONFIG
0 commit comments