Skip to content

Commit

Permalink
add types, include review comments, add pydantic mypy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Jul 26, 2024
1 parent 0fe3910 commit ce32536
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ repos:
- types-jsonschema
- types-Markdown
- types-setuptools
- pydantic
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[mypy]
warn_unused_configs = True
ignore_missing_imports = true
plugins = pydantic.mypy
6 changes: 5 additions & 1 deletion nf_core/components/components_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion nf_core/components/components_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")

Expand Down
2 changes: 1 addition & 1 deletion nf_core/components/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
5 changes: 3 additions & 2 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ce32536

Please sign in to comment.