Skip to content

Commit d43dc7e

Browse files
committed
mypy support
1 parent 979c3b7 commit d43dc7e

File tree

11 files changed

+56
-92
lines changed

11 files changed

+56
-92
lines changed

.github/workflows/ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
tox-action:
1818
- lint
1919
- lint_docs
20+
- mypy
2021
- unit-quick
2122
#- unit-diagnostic-servebasic
2223
#- unit-diagnostic-servebasic-gx-2005

planemo/cli.py

-34
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ def handle_blended_options(*args, **kwds):
9494
)
9595
_setup_profile_options(ctx, profile_defaults, kwds)
9696

97-
_setup_galaxy_source_options(args[0], kwds)
98-
9997
try:
10098
return f(*args, **kwds)
10199
except ExitCodeException as e:
@@ -104,38 +102,6 @@ def handle_blended_options(*args, **kwds):
104102
return pass_context(handle_blended_options)
105103

106104

107-
EXCLUSIVE_OPTIONS_LIST = [
108-
]
109-
110-
111-
def _setup_galaxy_source_options(ctx, kwds):
112-
for exclusive_options in EXCLUSIVE_OPTIONS_LIST:
113-
option_source = {}
114-
for option in exclusive_options:
115-
if option in kwds:
116-
option_source[option] = ctx.get_option_source(option)
117-
else:
118-
option_source[option] = None
119-
120-
most_authoratative_source = None
121-
most_authoratative_source_options = []
122-
for key, value in option_source.items():
123-
if value is None:
124-
continue
125-
if most_authoratative_source is None or value.value < most_authoratative_source.value:
126-
most_authoratative_source = value
127-
most_authoratative_source_options = [key]
128-
elif value == most_authoratative_source:
129-
most_authoratative_source_options.append(key)
130-
131-
if most_authoratative_source != OptionSource.default and len(most_authoratative_source_options) > 1:
132-
raise click.UsageError("Cannot specify multiple of %s" % most_authoratative_source_options)
133-
134-
for option in exclusive_options:
135-
if option in kwds and option not in most_authoratative_source_options:
136-
del kwds[option]
137-
138-
139105
def _setup_profile_options(ctx, profile_defaults, kwds):
140106
for key, value in profile_defaults.items():
141107
option_present = key in kwds

planemo/engine/interface.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os
66
import tempfile
7+
from typing import List
78

89
from six import add_metaclass
910

@@ -12,6 +13,7 @@
1213
from planemo.runnable import (
1314
cases,
1415
for_path,
16+
RunnableType,
1517
)
1618
from planemo.test.results import StructuredData
1719

@@ -37,7 +39,7 @@ def test(self, runnables):
3739
class BaseEngine(Engine):
3840
"""Base class providing context and keywords for Engine implementations."""
3941

40-
handled_runnable_types = []
42+
handled_runnable_types = [] # type: List[RunnableType]
4143

4244
def __init__(self, ctx, **kwds):
4345
"""Store context and kwds."""

planemo/galaxy/test/structures.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,14 @@ def _parse_num(num_str):
202202
return num
203203

204204

205-
TestId = namedtuple("TestId", ["name", "num", "id"])
205+
_TestId = namedtuple("TestId", ["name", "num", "id"])
206206

207207

208-
@property
209-
def _label(self):
210-
if self.num is not None:
211-
return "{0}[{1}]".format(self.name, self.num)
212-
else:
213-
return self.id
214-
208+
class TestId(_TestId):
215209

216-
TestId.label = _label
210+
@property
211+
def label(self):
212+
if self.num is not None:
213+
return "{0}[{1}]".format(self.name, self.num)
214+
else:
215+
return self.id

planemo/network_util.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import socket
2-
try:
3-
from http.client import BadStatusLine
4-
except ImportError:
5-
from httplib import BadStatusLine
2+
from http.client import BadStatusLine
63
from time import time as now
74

85
from six.moves.urllib.error import URLError

planemo/runnable.py

+20-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import collections
77
import os
88
from distutils.dir_util import copy_tree
9-
from enum import Enum
9+
from enum import auto, Enum
1010

1111
import yaml
1212
from galaxy.tool_util.cwl.parser import workflow_proxy
@@ -39,35 +39,30 @@
3939
"defintion must field [%s].")
4040

4141

42-
RunnableType = Enum(
43-
"RunnableType", 'galaxy_tool galaxy_datamanager galaxy_workflow cwl_tool cwl_workflow directory'
44-
)
45-
46-
47-
@property
48-
def _runnable_type_has_tools(runnable_type):
49-
return runnable_type.name in ["galaxy_tool", "galaxy_datamanager", "cwl_tool", "directory"]
50-
51-
52-
@property
53-
def _runnable_type_is_single_artifact(runnable_type):
54-
return runnable_type.name not in ["directory"]
42+
class RunnableType(Enum):
43+
galaxy_tool = auto()
44+
galaxy_datamanager = auto()
45+
galaxy_workflow = auto()
46+
cwl_tool = auto()
47+
cwl_workflow = auto()
48+
directory = auto()
5549

50+
@property
51+
def has_tools(runnable_type):
52+
return runnable_type.name in ["galaxy_tool", "galaxy_datamanager", "cwl_tool", "directory"]
5653

57-
@property
58-
def _runnable_type_test_data_in_parent_dir(runnable_type):
59-
return runnable_type.name in ["galaxy_datamanager"]
60-
54+
@property
55+
def is_single_artifact(runnable_type):
56+
return runnable_type.name not in ["directory"]
6157

62-
@property
63-
def _runnable_type_is_galaxy_artifact(runnable_type):
64-
return "galaxy" in runnable_type.name
58+
@property
59+
def test_data_in_parent_dir(runnable_type):
60+
return runnable_type.name in ["galaxy_datamanager"]
6561

62+
@property
63+
def is_galaxy_artifact(runnable_type):
64+
return "galaxy" in runnable_type.name
6665

67-
RunnableType.has_tools = _runnable_type_has_tools
68-
RunnableType.is_single_artifact = _runnable_type_is_single_artifact
69-
RunnableType.test_data_in_parent_dir = _runnable_type_test_data_in_parent_dir
70-
RunnableType.is_galaxy_artifact = _runnable_type_is_galaxy_artifact
7166

7267
_Runnable = collections.namedtuple("Runnable", ["path", "type"])
7368

planemo/shed/__init__.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,24 @@ def construct_yaml_str(self, node):
175175
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
176176

177177

178-
ShedContext = namedtuple("ShedContext", ["tsi", "shed_config", "config_owner"])
178+
_ShedContext = namedtuple("ShedContext", ["tsi", "shed_config", "config_owner"])
179179

180180

181-
def _shed_context_owner(self):
182-
owner = self.config_owner
183-
if owner is None:
184-
owner = username(self.tsi)
185-
return owner
186-
187-
188-
@property
189-
def _shed_context_label(self):
190-
return self.shed_config.get("label") or "tool shed"
181+
class ShedContext(_ShedContext):
191182

183+
def owner(self):
184+
owner = self.config_owner
185+
if owner is None:
186+
owner = username(self.tsi)
187+
return owner
192188

193-
ShedContext.owner = _shed_context_owner
194-
ShedContext.label = _shed_context_label
189+
@property
190+
def label(self):
191+
return self.shed_config.get("label") or "tool shed"
195192

196193

197194
def shed_init(ctx, path, **kwds):
198-
"""Intialize a new shed repository."""
195+
"""Initialize a new shed repository."""
199196
if not os.path.exists(path):
200197
os.makedirs(path)
201198
shed_config_path = os.path.join(path, SHED_CONFIG_NAME)

planemo/shed2tap/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tarfile
77
import zipfile
88
from ftplib import all_errors as FTPErrors # tuple of exceptions
9+
from typing import List
910
from xml.etree import ElementTree
1011

1112
from galaxy.util import unicodify
@@ -329,6 +330,8 @@ def __init__(self, name, version, repo):
329330

330331

331332
class BaseAction(object):
333+
_keys = [] # type: List[str]
334+
action_type = None # type: str
332335

333336
def __repr__(self):
334337
return "Action[type=%s]" % self.action_type
@@ -686,7 +689,7 @@ def to_bash(self):
686689

687690
class MakeInstallAction(BaseAction):
688691
action_type = "make_install"
689-
_keys = []
692+
_keys = [] # type: List[str]
690693

691694
def __init__(self, elem):
692695
pass

planemo/templates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
try:
33
from jinja2 import Template
44
except ImportError:
5-
Template = None
5+
Template = None # type: ignore
66

77
NO_JINJA2_MESSAGE = ("This functionality requires Jinja2 but this library is "
88
"unavailable. Install with `pip install jinja2`.")
99

1010

11-
def render(template_str, **kwds):
11+
def render(template_str: str, **kwds):
1212
"""Use jinja2 to render specified template."""
1313
if Template is None:
1414
raise Exception(NO_JINJA2_MESSAGE)

setup.cfg

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ with-coverage=1
99
logging-filter=planemo,galaxy
1010
logging-level=INFO
1111

12-
1312
[flake8]
1413
max-line-length = 150
1514
max-complexity = 14
1615
exclude=.eggs,.git,.tox,.venv,.venv3,build,docs/conf.py,docs/standards,project_templates/cwl_draft3_spec/
1716
import-order-style = smarkets
1817
application-import-names = planemo,test
18+
19+
[mypy]
20+
ignore_missing_imports = True

tox.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ commands =
99
lint_docs: make lint-docs
1010
lint_docstrings: flake8 --ignore='D107,D401,D105' {[tox]source_dir}
1111
unit: pytest {env:PYTEST_FAIL_FAIL:} {env:PYTEST_CAPTURE:} -m {env:PYTEST_MARK:""} {env:PYTEST_TARGET:{[tox]test_dir}} {posargs}
12+
mypy: mypy {[tox]source_dir} {posargs}
1213

1314
passenv =
1415
PLANEMO_*
@@ -25,6 +26,7 @@ deps =
2526
# unit: pytest-timeout
2627
unit: coverage
2728
unit: flask
29+
mypy: mypy
2830
setenv =
2931
gx: PYTEST_MARK="tests_galaxy_branch"
3032
diagnostic: PLANEMO_TEST_VERBOSE=1
@@ -52,7 +54,7 @@ setenv =
5254
2005: PLANEMO_TEST_GALAXY_BRANCH=release_20.05
5355
2001: PLANEMO_TEST_GALAXY_BRANCH=release_20.01
5456
skip_install =
55-
doc_test,lint,lint_docs,lint_docstrings: True
57+
doc_test,lint,lint_docs,lint_docstrings,mypy: True
5658
whitelist_externals =
5759
lint_docs: make
5860

0 commit comments

Comments
 (0)