Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mypy to pre-commit config, fix mypy errors #2545

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ repos:
rev: "v2.7.1"
hooks:
- id: prettier
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.1" # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies:
- types-PyYAML
- types-requests
- types-jsonschema
- types-Markdown
- types-setuptools
5 changes: 3 additions & 2 deletions docs/api/_src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
import os
import sys
from typing import Dict

sys.path.insert(0, os.path.abspath("../../../nf_core"))
import nf_core
Expand Down Expand Up @@ -58,7 +59,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language: str = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -113,7 +114,7 @@

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
latex_elements: Dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we have this in pyproject.toml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it felt like it didn't pick it up correctly. let me check again

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[mypy]
warn_unused_configs = True
ignore_missing_imports = true
56 changes: 26 additions & 30 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def nf_core_cli(ctx, verbose, hide_progress, log_file):


# nf-core list
@nf_core_cli.command()
@nf_core_cli.command("list")
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option(
"-s",
Expand All @@ -162,7 +162,7 @@ def nf_core_cli(ctx, verbose, hide_progress, log_file):
)
@click.option("--json", is_flag=True, default=False, help="Print full output as JSON")
@click.option("--show-archived", is_flag=True, default=False, help="Print archived workflows")
def list(keywords, sort, json, show_archived):
def list_pipelines(keywords, sort, json, show_archived):
"""
List available nf-core pipelines with local info.

Expand Down Expand Up @@ -553,21 +553,21 @@ def subworkflows(ctx, git_remote, branch, no_pull):


# nf-core modules list subcommands
@modules.group()
@modules.group("list")
@click.pass_context
def list(ctx):
def modules_list(ctx):
"""
List modules in a local pipeline or remote repository.
"""
pass


# nf-core modules list remote
@list.command()
@modules_list.command("remote")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
def remote(ctx, keywords, json):
def modules_list_remote(ctx, keywords, json):
"""
List modules in a remote GitHub repo [dim i](e.g [link=https://github.com/nf-core/modules]nf-core/modules[/])[/].
"""
Expand All @@ -588,7 +588,7 @@ def remote(ctx, keywords, json):


# nf-core modules list local
@list.command()
@modules_list.command("local")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
Expand All @@ -599,7 +599,7 @@ def remote(ctx, keywords, json):
default=".",
help=r"Pipeline directory. [dim]\[default: Current working directory][/]",
)
def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
def modules_list_local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do these changes for subworkflows too?

"""
List modules installed locally in a pipeline
"""
Expand All @@ -620,7 +620,7 @@ def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin


# nf-core modules install
@modules.command()
@modules.command("install")
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
Expand All @@ -633,7 +633,7 @@ def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
@click.option("-p", "--prompt", is_flag=True, default=False, help="Prompt for the version of the module")
@click.option("-f", "--force", is_flag=True, default=False, help="Force reinstallation of module if it already exists")
@click.option("-s", "--sha", type=str, metavar="<commit sha>", help="Install module at commit SHA")
def install(ctx, tool, dir, prompt, force, sha):
def modules_install(ctx, tool, dir, prompt, force, sha):
"""
Install DSL2 modules within a pipeline.

Expand All @@ -660,7 +660,7 @@ def install(ctx, tool, dir, prompt, force, sha):


# nf-core modules update
@modules.command()
@modules.command("update")
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
Expand Down Expand Up @@ -699,7 +699,7 @@ def install(ctx, tool, dir, prompt, force, sha):
default=False,
help="Automatically update all linked modules and subworkflows without asking for confirmation",
)
def update(ctx, tool, directory, force, prompt, sha, install_all, preview, save_diff, update_deps):
def modules_update(ctx, tool, directory, force, prompt, sha, install_all, preview, save_diff, update_deps):
"""
Update DSL2 modules within a pipeline.

Expand Down Expand Up @@ -767,7 +767,7 @@ def patch(ctx, tool, dir, remove):


# nf-core modules remove
@modules.command()
@modules.command("remove")
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
Expand All @@ -777,7 +777,7 @@ def patch(ctx, tool, dir, remove):
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
def remove(ctx, dir, tool):
def modules_remove(ctx, dir, tool):
"""
Remove a module from a pipeline.
"""
Expand Down Expand Up @@ -887,7 +887,7 @@ def test_module(ctx, tool, dir, no_prompts, update, once):


# nf-core modules lint
@modules.command()
@modules.command("lint")
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", metavar="<pipeline/modules directory>")
Expand All @@ -912,9 +912,7 @@ def test_module(ctx, tool, dir, no_prompts, update, once):
show_default=True,
)
@click.option("--fix-version", is_flag=True, help="Fix the module version if a newer version is available")
def lint(
ctx, tool, dir, registry, key, all, fail_warned, local, passed, sort_by, fix_version
): # pylint: disable=redefined-outer-name
def modules_lint(ctx, tool, dir, registry, key, all, fail_warned, local, passed, sort_by, fix_version):
"""
Lint one or more modules in a directory.

Expand Down Expand Up @@ -959,7 +957,7 @@ def lint(


# nf-core modules info
@modules.command()
@modules.command("info")
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
Expand All @@ -969,7 +967,7 @@ def lint(
default=".",
help=r"Pipeline directory. [dim]\[default: Current working directory][/]",
)
def info(ctx, tool, dir):
def modules_info(ctx, tool, dir):
"""
Show developer usage information about a given module.

Expand Down Expand Up @@ -1095,17 +1093,17 @@ def test_subworkflow(ctx, subworkflow, dir, no_prompts, update, once):


# nf-core subworkflows list subcommands
@subworkflows.group()
@subworkflows.group("list")
@click.pass_context
def list(ctx):
def subworkflows_list(ctx):
"""
List subworkflows in a local pipeline or remote repository.
"""
pass


# nf-core subworkflows list remote
@list.command()
@subworkflows_list.command("remote")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
Expand All @@ -1131,7 +1129,7 @@ def remote(ctx, keywords, json):


# nf-core subworkflows list local
@list.command()
@subworkflows_list.command("local")
@click.pass_context
@click.argument("keywords", required=False, nargs=-1, metavar="<filter keywords>")
@click.option("-j", "--json", is_flag=True, help="Print as JSON to stdout")
Expand Down Expand Up @@ -1163,7 +1161,7 @@ def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin


# nf-core subworkflows lint
@subworkflows.command()
@subworkflows.command("lint")
@click.pass_context
@click.argument("subworkflow", type=str, required=False, metavar="subworkflow name")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", metavar="<pipeline/modules directory>")
Expand All @@ -1187,9 +1185,7 @@ def local(ctx, keywords, json, dir): # pylint: disable=redefined-builtin
help="Sort lint output by subworkflow or test name.",
show_default=True,
)
def lint(
ctx, subworkflow, dir, registry, key, all, fail_warned, local, passed, sort_by
): # pylint: disable=redefined-outer-name
def subworkflows_lint(ctx, subworkflow, dir, registry, key, all, fail_warned, local, passed, sort_by):
"""
Lint one or more subworkflows in a directory.

Expand Down Expand Up @@ -1496,11 +1492,11 @@ def build(dir, no_prompts, web_only, url):


# nf-core schema lint
@schema.command()
@schema.command("lint")
@click.argument(
"schema_path", type=click.Path(exists=True), default="nextflow_schema.json", metavar="<pipeline schema>"
)
def lint(schema_path):
def schema_lint(schema_path):
"""
Check that a given pipeline schema is valid.

Expand Down
2 changes: 1 addition & 1 deletion nf_core/params_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
self,
pipeline=None,
revision=None,
):
) -> None:
"""Initialise the ParamFileBuilder class

Args:
Expand Down
12 changes: 6 additions & 6 deletions nf_core/subworkflows/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class SubworkflowLint(ComponentLint):
"""

# Import lint functions
from .main_nf import main_nf
from .meta_yml import meta_yml
from .subworkflow_changes import subworkflow_changes
from .subworkflow_tests import subworkflow_tests
from .subworkflow_todos import subworkflow_todos
from .subworkflow_version import subworkflow_version
from .main_nf import main_nf # type: ignore[misc]
from .meta_yml import meta_yml # type: ignore[misc]
from .subworkflow_changes import subworkflow_changes # type: ignore[misc]
from .subworkflow_tests import subworkflow_tests # type: ignore[misc]
from .subworkflow_todos import subworkflow_todos # type: ignore[misc]
from .subworkflow_version import subworkflow_version # type: ignore[misc]

def __init__(
self,
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ norecursedirs = [ ".*", "build", "dist", "*.egg", "data", "__pycache__", ".githu
profile = "black"
known_first_party = ["nf_core"]
multi_line_output = 3

[tool.mypy]
ignore_missing_imports = true
follow_imports = "skip"
disable_error_code = "no-redef"
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ types-PyYAML
types-requests
types-jsonschema
types-Markdown
types-setuptools
20 changes: 10 additions & 10 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,44 +178,44 @@ def test_sphinx_md_files(self):
#######################
# SPECIFIC LINT TESTS #
#######################
from .lint.actions_awsfulltest import (
from .lint.actions_awsfulltest import ( # type: ignore[misc]
test_actions_awsfulltest_fail,
test_actions_awsfulltest_pass,
test_actions_awsfulltest_warn,
)
from .lint.actions_awstest import (
from .lint.actions_awstest import ( # type: ignore[misc]
test_actions_awstest_fail,
test_actions_awstest_pass,
)
from .lint.actions_ci import (
from .lint.actions_ci import ( # type: ignore[misc]
test_actions_ci_fail_wrong_nf,
test_actions_ci_fail_wrong_trigger,
test_actions_ci_pass,
)
from .lint.actions_schema_validation import (
from .lint.actions_schema_validation import ( # type: ignore[misc]
test_actions_schema_validation_fails_for_additional_property,
test_actions_schema_validation_missing_jobs,
test_actions_schema_validation_missing_on,
)
from .lint.files_exist import (
from .lint.files_exist import ( # type: ignore[misc]
test_files_exist_depreciated_file,
test_files_exist_missing_config,
test_files_exist_missing_main,
test_files_exist_pass,
)
from .lint.files_unchanged import (
from .lint.files_unchanged import ( # type: ignore[misc]
test_files_unchanged_fail,
test_files_unchanged_pass,
)
from .lint.merge_markers import test_merge_markers_found
from .lint.modules_json import test_modules_json_pass
from .lint.nextflow_config import (
from .lint.merge_markers import test_merge_markers_found # type: ignore[misc]
from .lint.modules_json import test_modules_json_pass # type: ignore[misc]
from .lint.nextflow_config import ( # type: ignore[misc]
test_nextflow_config_bad_name_fail,
test_nextflow_config_dev_in_release_mode_failed,
test_nextflow_config_example_pass,
test_nextflow_config_missing_test_profile_failed,
)
from .lint.version_consistency import test_version_consistency
from .lint.version_consistency import test_version_consistency # type: ignore[misc]


# TODO nf-core: Assess and strip out if no longer required for DSL2
Expand Down
Loading