Skip to content

Commit d0f35c0

Browse files
committed
Fix type annotations
1 parent aebe5cb commit d0f35c0

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

planemo/config.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from planemo.cli import PlanemoCliContext
2222

2323
PLANEMO_CONFIG_ENV_PROP = "PLANEMO_GLOBAL_CONFIG_PATH"
24-
DEFAULT_CONFIG = {} # type: Dict[str, Any]
24+
DEFAULT_CONFIG: Dict[str, Any] = {}
2525

2626
VALUE_UNSET = object()
2727

@@ -30,10 +30,10 @@
3030

3131

3232
def _default_callback(
33-
default: Optional[Union[bool, int, str]],
33+
default: Any,
3434
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] = [],
3737
) -> Callable:
3838
def callback(ctx, param, value):
3939
planemo_ctx = ctx.obj
@@ -66,11 +66,11 @@ def callback(ctx, param, value):
6666

6767

6868
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]]:
7171
if use_global_config:
7272
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
7474
for global_config_key in global_config_keys:
7575
if global_config_key in global_config:
7676
default_value = global_config[global_config_key]
@@ -87,7 +87,7 @@ def planemo_option(*args, **kwargs) -> Callable:
8787
defaults from ~/.planemo.yml, and tracks how parameters are specified
8888
using the Planemo Context object.
8989
"""
90-
option_type = kwargs.get("type", None)
90+
option_type = kwargs.get("type")
9191
use_global_config = kwargs.pop("use_global_config", False)
9292
use_env_var = kwargs.pop("use_env_var", False)
9393
extra_global_config_vars = kwargs.pop("extra_global_config_vars", [])
@@ -101,7 +101,7 @@ def planemo_option(*args, **kwargs) -> Callable:
101101
outer_callback = kwargs.pop("callback", None)
102102

103103
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))
105105
result = _default_callback(
106106
default,
107107
use_global_config=use_global_config,
@@ -125,7 +125,7 @@ def callback(ctx, param, value):
125125
if arg.startswith("--"):
126126
name = arg[len("--") :]
127127
assert name
128-
kwargs["envvar"] = "PLANEMO_%s" % name.upper()
128+
kwargs["envvar"] = f"PLANEMO_{name.upper()}"
129129

130130
option = click.option(*args, **kwargs)
131131
return option
@@ -138,7 +138,7 @@ def global_config_path(config_path: Optional[str] = None) -> str:
138138
return config_path
139139

140140

141-
def read_global_config(config_path: str) -> Dict[Any, Any]:
141+
def read_global_config(config_path: Optional[str]) -> Dict[str, Any]:
142142
config_path = global_config_path(config_path)
143143
if not os.path.exists(config_path):
144144
return DEFAULT_CONFIG

planemo/context.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import sys
1111
import traceback
1212
from typing import (
13+
Any,
1314
Dict,
15+
Optional,
1416
TYPE_CHECKING,
1517
)
1618
from urllib.request import urlopen
19+
1720
from planemo.config import read_global_config
1821

1922
if TYPE_CHECKING:
@@ -62,26 +65,26 @@ class PlanemoContext(PlanemoContextInterface):
6265
def __init__(self) -> None:
6366
"""Construct a Context object using execution environment."""
6467
self.home = os.getcwd()
65-
self._global_config = None
68+
self._global_config: Optional[Dict] = None
6669
# Will be set by planemo CLI driver
6770
self.verbose = False
68-
self.planemo_config = None
71+
self.planemo_config: Optional[str] = None
6972
self.planemo_directory = None
70-
self.option_source = {}
73+
self.option_source: Dict[str, "OptionSource"] = {}
7174

7275
def set_option_source(self, param_name: str, option_source: "OptionSource", force: bool = False) -> None:
7376
"""Specify how an option was set."""
7477
if not force:
75-
assert param_name not in self.option_source, "No option source for [%s]" % param_name
78+
assert param_name not in self.option_source, f"Option source for [{param_name}] already set"
7679
self.option_source[param_name] = option_source
7780

7881
def get_option_source(self, param_name: str) -> "OptionSource":
7982
"""Return OptionSource value indicating how the option was set."""
80-
assert param_name in self.option_source, "No option source for [%s]" % param_name
83+
assert param_name in self.option_source, f"No option source for [{param_name}]"
8184
return self.option_source[param_name]
8285

8386
@property
84-
def global_config(self) -> Dict[str, Dict[str, str]]:
87+
def global_config(self) -> Dict[str, Any]:
8588
"""Read Planemo's global configuration.
8689
8790
As defined most simply by ~/.planemo.yml.
@@ -131,7 +134,7 @@ def cache_download(self, url, destination):
131134
with urlopen(url) as fh:
132135
content = fh.read()
133136
if len(content) == 0:
134-
raise Exception("Failed to download [%s]." % url)
137+
raise Exception(f"Failed to download [{url}].")
135138
with open(cache_destination, "wb") as f:
136139
f.write(content)
137140

@@ -141,9 +144,7 @@ def _ensure_directory(self, path: str, name: str) -> str:
141144
if not os.path.exists(path):
142145
os.makedirs(path)
143146
if not os.path.isdir(path):
144-
template = "Planemo %s directory [%s] unavailable."
145-
message = template % (name, path)
146-
raise Exception(message)
147+
raise Exception(f"Planemo {name} directory [{path}] unavailable.")
147148
return path
148149

149150
def _log_message(self, message):

planemo/database/factory.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Create a DatabaseSource from supplied planemo configuration."""
22
from galaxy.util.commands import which
33

4+
from .interface import DatabaseSource
45
from .postgres import LocalPostgresDatabaseSource
56
from .postgres_docker import DockerPostgresDatabaseSource
67

0 commit comments

Comments
 (0)