Skip to content

Commit

Permalink
Add type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jul 2, 2024
1 parent 64f9076 commit bafecff
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
7 changes: 5 additions & 2 deletions planemo/commands/cmd_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import click

from planemo import options
from planemo.cli import command_function
from planemo.cli import (
command_function,
PlanemoCliContext,
)
from planemo.tool_lint import (
build_tool_lint_args,
lint_tools_on_path,
Expand Down Expand Up @@ -43,7 +46,7 @@
# default=False,
# )
@command_function
def cli(ctx, uris, **kwds):
def cli(ctx: PlanemoCliContext, uris, **kwds):
"""Check for common errors and best practices."""
lint_args = build_tool_lint_args(ctx, **kwds)
exit_code = lint_tools_on_path(ctx, uris, lint_args, recursive=kwds["recursive"])
Expand Down
7 changes: 5 additions & 2 deletions planemo/commands/cmd_shed_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
shed,
shed_lint,
)
from planemo.cli import command_function
from planemo.cli import (
command_function,
PlanemoCliContext,
)


@click.command("shed_lint")
Expand Down Expand Up @@ -41,7 +44,7 @@
# default=False,
# )
@command_function
def cli(ctx, paths, **kwds):
def cli(ctx: PlanemoCliContext, paths, **kwds):
"""Check Tool Shed repository for common issues.
With the ``--tools`` flag, this command lints actual Galaxy tools
Expand Down
7 changes: 5 additions & 2 deletions planemo/commands/cmd_workflow_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import click

from planemo import options
from planemo.cli import command_function
from planemo.cli import (
command_function,
PlanemoCliContext,
)
from planemo.workflow_lint import (
build_wf_lint_args,
lint_workflow_artifacts_on_paths,
Expand All @@ -23,7 +26,7 @@
help="Check workflows directory with the standards of iwc",
)
@command_function
def cli(ctx, paths, **kwds):
def cli(ctx: PlanemoCliContext, paths, **kwds):
"""Check workflows for syntax errors and best practices."""
# Unlike tools, lets just make this recursive by default.
lint_args = build_wf_lint_args(ctx, **kwds)
Expand Down
12 changes: 10 additions & 2 deletions planemo/lint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Utilities to help linting various targets."""

import os
from typing import (
Any,
Dict,
TYPE_CHECKING,
)
from urllib.request import urlopen

import requests
Expand All @@ -13,8 +18,11 @@
from planemo.shed import find_urls_for_xml
from planemo.xml import validation

if TYPE_CHECKING:
from planemo.cli import PlanemoCliContext


def build_lint_args(ctx, **kwds):
def build_lint_args(ctx: "PlanemoCliContext", **kwds) -> Dict[str, Any]:
"""Handle common report, error, and skip linting arguments."""
report_level = kwds.get("report_level", "all")
fail_level = kwds.get("fail_level", "warn")
Expand All @@ -39,7 +47,7 @@ def build_lint_args(ctx, **kwds):
if len(invalid_skip_types):
error(f"Unknown linter type(s) {invalid_skip_types} in list of linters to be skipped. Known linters {linters}")

lint_args = dict(
lint_args: Dict[str, Any] = dict(
level=report_level,
fail_level=fail_level,
skip_types=skip_types,
Expand Down
6 changes: 5 additions & 1 deletion planemo/shed_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import xml.etree.ElementTree as ET
from typing import TYPE_CHECKING

import yaml
from galaxy.tool_util.lint import lint_tool_source_with
Expand Down Expand Up @@ -31,6 +32,9 @@
from planemo.tools import yield_tool_sources
from planemo.xml import XSDS_PATH

if TYPE_CHECKING:
from planemo.cli import PlanemoCliContext

TOOL_DEPENDENCIES_XSD = os.path.join(XSDS_PATH, "tool_dependencies.xsd")
REPO_DEPENDENCIES_XSD = os.path.join(XSDS_PATH, "repository_dependencies.xsd")

Expand All @@ -50,7 +54,7 @@
]


def lint_repository(ctx, realized_repository, **kwds):
def lint_repository(ctx: "PlanemoCliContext", realized_repository, **kwds):
"""Lint a realized shed repository.
See :mod:`planemo.shed` for details on constructing a realized
Expand Down
6 changes: 5 additions & 1 deletion planemo/tool_lint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os.path import basename
from typing import TYPE_CHECKING

from galaxy.tool_util.lint import lint_tool_source

Expand All @@ -22,10 +23,13 @@
yield_tool_sources_on_paths,
)

if TYPE_CHECKING:
from planemo.cli import PlanemoCliContext

LINTING_TOOL_MESSAGE = "Linting tool %s"


def build_tool_lint_args(ctx, **kwds):
def build_tool_lint_args(ctx: "PlanemoCliContext", **kwds):
lint_args = build_lint_args(ctx, **kwds)
extra_modules = _lint_extra_modules(**kwds)
lint_args["extra_modules"] = extra_modules
Expand Down
4 changes: 2 additions & 2 deletions planemo/workflow_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class WorkflowLintContext(LintContext):
training_topic = None


def build_wf_lint_args(ctx, **kwds):
def build_wf_lint_args(ctx: "PlanemoCliContext", **kwds) -> Dict[str, Any]:
lint_args = build_lint_args(ctx, **kwds)
lint_args["iwc_grade"] = str(kwds.get("iwc", False))
lint_args["iwc_grade"] = kwds.get("iwc", False)
return lint_args


Expand Down

0 comments on commit bafecff

Please sign in to comment.