From ce325366e04551b46d109b572e95320c7dc39023 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 26 Jul 2024 14:47:53 +0200 Subject: [PATCH] add types, include review comments, add pydantic mypy plugin --- .pre-commit-config.yaml | 1 + mypy.ini | 1 + nf_core/components/components_command.py | 6 +++++- nf_core/components/components_utils.py | 2 +- nf_core/components/info.py | 2 +- nf_core/components/lint/__init__.py | 5 +++-- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bcf7ff65ce..f763fa6658 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,4 @@ repos: - types-jsonschema - types-Markdown - types-setuptools + - pydantic diff --git a/mypy.ini b/mypy.ini index c48aa5884b..5a95223162 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,3 +1,4 @@ [mypy] warn_unused_configs = True ignore_missing_imports = true +plugins = pydantic.mypy diff --git a/nf_core/components/components_command.py b/nf_core/components/components_command.py index 4440dc32a4..91e14d0606 100644 --- a/nf_core/components/components_command.py +++ b/nf_core/components/components_command.py @@ -254,7 +254,11 @@ def check_patch_paths(self, patch_path: Path, module_name: str) -> None: # Update path in modules.json if the file is in the correct format modules_json = ModulesJson(self.directory) modules_json.load() - if modules_json.has_git_url_and_modules() and modules_json.modules_json is not None: + if ( + modules_json.has_git_url_and_modules() + and self.modules_repo.repo_path is not None + and modules_json.modules_json is not None + ): modules_json.modules_json["repos"][self.modules_repo.remote_url]["modules"][ self.modules_repo.repo_path ][module_name]["patch"] = str(patch_path.relative_to(Path(self.directory).resolve())) diff --git a/nf_core/components/components_utils.py b/nf_core/components/components_utils.py index 4e9c0ac601..3d64dc1bb6 100644 --- a/nf_core/components/components_utils.py +++ b/nf_core/components/components_utils.py @@ -77,7 +77,7 @@ def get_repo_info(directory: Path, use_prompt: Optional[bool] = True) -> Tuple[P ).unsafe_ask() log.info("To avoid this prompt in the future, add the 'org_path' key to a root '%s' file.", config_fn.name) if rich.prompt.Confirm.ask("[bold][blue]?[/] Would you like me to add this config now?", default=True): - with open(str(config_fn), "a+") as fh: + with open(config_fn, "a+") as fh: fh.write(f"org_path: {org}\n") log.info(f"Config added to '{config_fn.name}'") diff --git a/nf_core/components/info.py b/nf_core/components/info.py index 55a95593f9..726586b5b7 100644 --- a/nf_core/components/info.py +++ b/nf_core/components/info.py @@ -107,7 +107,7 @@ def init_mod_name(self, component): elif self.repo_type == "pipeline": assert self.modules_json is not None # mypy all_components = self.modules_json.get_all_components(self.component_type).get( - self.modules_repo.remote_url, [] + self.modules_repo.remote_url, {} ) components = [ component if directory == self.modules_repo.repo_path else f"{directory}/{component}" diff --git a/nf_core/components/lint/__init__.py b/nf_core/components/lint/__init__.py index e2475ef62c..ddf5e1e165 100644 --- a/nf_core/components/lint/__init__.py +++ b/nf_core/components/lint/__init__.py @@ -22,6 +22,7 @@ from nf_core.components.nfcore_component import NFCoreComponent from nf_core.modules.modules_json import ModulesJson from nf_core.pipelines.lint_utils import console +from nf_core.utils import LintConfigType from nf_core.utils import plural_s as _s log = logging.getLogger(__name__) @@ -77,8 +78,8 @@ def __init__( self.failed: List[LintResult] = [] self.all_local_components: List[NFCoreComponent] = [] - self.lint_config = None - self.modules_json = None + self.lint_config: Optional[LintConfigType] = None + self.modules_json: Optional[ModulesJson] = None if self.component_type == "modules": self.lint_tests = self.get_all_module_lint_tests(self.repo_type == "pipeline")