Skip to content

fix: address mypy issues - #83

Open
jjjermiah wants to merge 11 commits into
snakemake:mainfrom
jjjermiah:jjjermiah/fix-mypy-issues
Open

jjjermiah wants to merge 11 commits into
snakemake:mainfrom
jjjermiah:jjjermiah/fix-mypy-issues

Conversation

@jjjermiah

@jjjermiah jjjermiah commented Mar 16, 2025 •

Copy link
Copy Markdown
Contributor

Errors to address:

➜ pixi run type-check
✨ Pixi task (type-check in dev): mypy snakemake_interface_executor_plugins/
snakemake_interface_executor_plugins/executors/base.py:30: error: "WorkflowExecutorInterface" has no attribute "dag"  [attr-defined]
snakemake_interface_executor_plugins/executors/base.py:90: error: "JobSchedulerExecutorInterface" has no attribute "finish_callback"  [attr-defined]
snakemake_interface_executor_plugins/executors/base.py:94: error: "JobSchedulerExecutorInterface" has no attribute "error_callback"; maybe "executor_error_callback"?  [attr-defined]
snakemake_interface_executor_plugins/executors/base.py:97: error: "JobSchedulerExecutorInterface" has no attribute "submit_callback"  [attr-defined]
snakemake_interface_executor_plugins/executors/real.py:34: error: "WorkflowExecutorInterface" has no attribute "executor_settings"; maybe "execution_settings" or "remote_execution_settings"?  [attr-defined]
snakemake_interface_executor_plugins/executors/real.py:81: error: "WorkflowExecutorInterface" has no attribute "dag"  [attr-defined]
snakemake_interface_executor_plugins/executors/real.py:85: error: Argument 1 to "encode_target_jobs_cli_args" has incompatible type "str"; expected "list[TargetSpec]"  [arg-type]
snakemake_interface_executor_plugins/executors/real.py:180: error: Incompatible return value type (got "Mapping[str, str]", expected "dict[str, str]")  [return-value]
snakemake_interface_executor_plugins/executors/remote.py:80: error: Need type annotation for "active_jobs" (hint: "active_jobs: list[<type>] = ...")  [var-annotated]
snakemake_interface_executor_plugins/executors/remote.py:121: error: Incompatible return value type (got "int", expected "ExecMode")  [return-value]
snakemake_interface_executor_plugins/executors/remote.py:131: error: Signature of "get_job_args" incompatible with supertype "RealExecutor"  [override]
snakemake_interface_executor_plugins/executors/remote.py:131: note:      Superclass:
snakemake_interface_executor_plugins/executors/remote.py:131: note:          def get_job_args(self, job: JobExecutorInterface, **kwargs: Any) -> Any
snakemake_interface_executor_plugins/executors/remote.py:131: note:      Subclass:
snakemake_interface_executor_plugins/executors/remote.py:131: note:          def get_job_args(self, job: JobExecutorInterface) -> Any
Found 11 errors in 3 files (checked 17 source files)

Summary by CodeRabbit

  • New Features
    • Executor integrations can provide callbacks for job submission, completion, and errors, and expose workflow settings and DAG information.
    • Job target specifications can now contain multiple structured targets.
  • Improvements
    • Remote executor job arguments now forward additional options.
    • Shared-filesystem choices receive consistent parsing and validation, including rejection of "none" when combined with other choices.
  • Chores
    • Type checking now runs in the quality-control workflow.

@coderabbitai

coderabbitai Bot commented Mar 16, 2025 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3fa9947-3a27-4ad1-8a41-4073a365e042
Commits

Reviewing files that changed from the base of the PR and between ab73f7d and 7003069.

Files selected for processing: 6
  • .github/workflows/test.yml
  • snakemake_interface_executor_plugins/executors/real.py
  • snakemake_interface_executor_plugins/executors/remote.py
  • snakemake_interface_executor_plugins/jobs.py
  • snakemake_interface_executor_plugins/settings.py
  • tests/tests.py
Files with no reviewable changes: 1
  • .github/workflows/test.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Executor interface types and method contracts changed. Remote job arguments now pass through to the base implementation. Shared-filesystem choice parsing and its tests changed. The workflow also enables the Mypy type-check step in CI.

Changes: Executor plugin contracts and settings

Layer / File(s) Summary
Executor types and method contracts
snakemake_interface_executor_plugins/jobs.py, snakemake_interface_executor_plugins/executors/*, snakemake_interface_executor_plugins/base.py, snakemake_interface_executor_plugins/scheduler.py, snakemake_interface_executor_plugins/workflow.py, .github/workflows/test.yml
Executor classes gain type annotations. get_target_spec now returns a list of TargetSpec values. RemoteExecutor.get_job_args accepts and forwards keyword arguments. Workflow and scheduler interfaces add properties and callbacks. The Mypy step runs pixi run --environment dev type-check with if: always().
Shared-filesystem choice parsing
snakemake_interface_executor_plugins/settings.py, tests/tests.py
_parse_choices_into accepts a list of choices and returns the specified container type. Tests cover list and set results, valid choices, invalid combinations with none, and forwarding remote job arguments.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Suggested reviewers: johanneskoester

Merge Risk: Minimal · up to 70030

The changes are ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: resolving mypy issues across executor interfaces and implementations.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@jjjermiah jjjermiah changed the title WIP: fix mypy issues fix: address mypy issues Mar 16, 2025
@jjjermiah
jjjermiah marked this pull request as ready for review March 16, 2025 16:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.gitignore (1)

162-165: Clarify and Confirm Ignore Entries for Package Management Transition

The new entries for poetry.lock, .pixi, and *.egg-info clearly reflect the shift toward Pixi-based management. Please confirm that:

  • Keeping poetry.lock (now un-commented) in the ignore list is intentional, especially if the project is fully transitioning away from Poetry.
  • Ignoring .pixi and *.egg-info meets the desired artifact cleanup goals.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb22a21 and ab73f7d.

⛔ Files ignored due to path filters (2)
  • pixi.lock is excluded by !**/*.lock
  • pyproject.toml is excluded by !pyproject.toml
📒 Files selected for processing (10)
  • .gitattributes (1 hunks)
  • .github/workflows/release-please.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • .gitignore (1 hunks)
  • snakemake_interface_executor_plugins/executors/base.py (2 hunks)
  • snakemake_interface_executor_plugins/executors/real.py (3 hunks)
  • snakemake_interface_executor_plugins/executors/remote.py (4 hunks)
  • snakemake_interface_executor_plugins/jobs.py (2 hunks)
  • snakemake_interface_executor_plugins/scheduler.py (1 hunks)
  • snakemake_interface_executor_plugins/workflow.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • snakemake_interface_executor_plugins/workflow.py
  • snakemake_interface_executor_plugins/scheduler.py
  • snakemake_interface_executor_plugins/jobs.py
  • snakemake_interface_executor_plugins/executors/real.py
  • snakemake_interface_executor_plugins/executors/remote.py
  • snakemake_interface_executor_plugins/executors/base.py
🔇 Additional comments (33)
snakemake_interface_executor_plugins/jobs.py (2)

8-8: Added appropriate imports for type annotations.

The imports for List from typing and TargetSpec from snakemake_interface_executor_plugins.utils have been correctly added to support the type signature changes.

Also applies to: 11-11


62-62: Return type correction aligns with actual implementation.

The return type of get_target_spec() has been updated from str to List[TargetSpec] to properly reflect the actual implementation, fixing the mypy type error mentioned in the PR description.

snakemake_interface_executor_plugins/workflow.py (3)

24-24: Added import for ExecutorSettingsBase.

The import for ExecutorSettingsBase has been correctly added to support the new abstract property.


57-59: Added required abstract property for executor settings.

The executor_settings property has been added to the interface, properly typed as returning ExecutorSettingsBase. This fixes one of the mypy errors mentioned in the PR objectives.


81-83: Added required abstract property for dag.

The dag property has been added to the interface, addressing the missing "dag" attribute in WorkflowExecutorInterface mentioned in the PR description.

snakemake_interface_executor_plugins/executors/base.py (3)

24-25: Added proper type annotations for class attributes.

Added type annotations for workflow and logger attributes, improving type safety and making the class structure clearer.


33-35: Added informative comment about type limitations.

The comment explaining why dag cannot be type-annotated (because the type is defined in the Snakemake framework) is helpful for maintaining the code in the future.


54-55: Fixed logical condition in resource filtering.

The condition for filtering resources has been corrected by separating the isdigit(value) check from the resource exclusion check, which fixes a potential logical error in the code.

snakemake_interface_executor_plugins/scheduler.py (2)

7-8: Added necessary imports for type annotations.

The imports for Callable from typing and JobExecutorInterface have been correctly added to support the type annotations for the callback attributes.


12-14: Added missing callback attributes with proper type annotations.

The submit_callback, finish_callback, and error_callback attributes have been added with appropriate type annotations, addressing the missing attributes mentioned in the PR description.

snakemake_interface_executor_plugins/executors/real.py (3)

7-7: Good change from Dict to Mapping for better type flexibility.

Changing from Dict to Mapping is a good practice as it focuses on the interface rather than the implementation, allowing more flexibility in the return types while maintaining type safety.


24-28: Well-structured type annotations added to class attributes.

These type annotations correctly document the expected types for class attributes, making the code more maintainable and helping address the mypy issues mentioned in the PR objectives.


185-185: Appropriate return type update to Mapping.

The return type annotation change from Dict[str, str] to Mapping[str, str] aligns with the import change and provides better API design. This addresses part of the type mismatch issues mentioned in the PR objectives.

snakemake_interface_executor_plugins/executors/remote.py (4)

15-15: Good addition of Optional import for nullable types.

Adding Optional to the imports correctly supports the type annotations for attributes that may be None.


39-52: Comprehensive type annotations added to class attributes.

These thorough type annotations clearly document the expected types for all class attributes, addressing the mypy issues mentioned in the PR objectives. The Optional annotation is correctly used for attributes that can be None.


144-144: **Method signature updated to include kwargs parameter.

Adding the **kwargs parameter to get_job_args improves compatibility with the parent class and consistency across the codebase. This addresses the incompatible method signatures issue mentioned in the PR objectives.


134-134:

Details

✅ Verification successful

Type ignore comment added to ExecMode return.

The # type: ignore comment bypasses type checking for this line. While generally such comments should be avoided, it's acceptable here if there's a legitimate reason why standard type checking doesn't work for this specific return.


🏁 Script executed:

#!/bin/bash
# Check the implementation of ExecMode in the codebase to understand why type: ignore is needed

# Look for ExecMode definition
rg -A 5 "class ExecMode" --type py

Length of output: 473


Clarification on the Use of # type: ignore for ExecMode.REMOTE

The current implementation:

return ExecMode.REMOTE  # type: ignore

is acceptable. The ExecMode is defined in snakemake_interface_executor_plugins/settings.py as a subclass of SettingsEnumBase, and the type checker struggles with this dynamic enum, which necessitates bypassing type checks for this return statement.

  • Suggestion (Optional):
    • Consider adding a brief inline note or linking to a related issue for future reference, clarifying why standard type checking fails in this specific instance.
.gitattributes (1)

1-2: Proper Configuration for Pixi Lock File

The entry for pixi.lock is set to use a binary merge strategy and provides YAML syntax highlighting while marking it as generated. This configuration should effectively prevent merge conflicts on the lock file.

.github/workflows/release-please.yml (5)

20-24: Renaming and Conditional Execution in 'publish-pypi' Job

The new publish-pypi job clearly communicates its role in publishing to PyPI. The use of needs: release-please along with the conditional ${{ needs.release-please.outputs.release_created }} ensures that publishing only occurs when a release has been created.


25-27: Updated Checkout Action

Switching to actions/checkout@v4 is a welcome update that leverages the latest improvements in the checkout process.


28-33: Install Pixi Step for Build Environment Setup

Replacing the Poetry installation with the Pixi setup using prefix-dev/setup-pixi@v0.8.3 (with environments: publish and a pinned pixi-version: v0.42.1) is clearly aligned with the project’s toolchain transition. Ensure the version pinning is deliberate for build reproducibility.


34-38: Build Step Using Pixi

Renaming the step to "Build source and wheel distribution + check build" and using the command pixi run --environment publish check-build effectively captures the new build process. The inline comment about building into the dist/ directory is additionally helpful.


39-44: Publish Step for Distribution

The updated publishing step now employs pypa/gh-action-pypi-publish@release/v1 with secure references for PYPI_USERNAME and PYPI_PASSWORD. This change streamlines the distribution process under the new workflow.

.github/workflows/test.yml (10)

10-15: Set Job Permissions Explicitly

The added permission settings (read for contents; write for checks, issues, and pull-requests) are clearly defined and help ensure that the workflow has the appropriate access for its operations.


20-21: Checkout Code for Quality-Control

Using actions/checkout@v4 in the quality-control job is properly updated to leverage the latest checkout improvements.


23-29: Installation of Pixi in Quality-Control Job

The step that installs Pixi with prefix-dev/setup-pixi@v0.8.3 using the development environment (with caching enabled) is well configured. Consistency with the release workflow reinforces the project’s transition away from Poetry.


30-34: Ruff Format Step in Quality-Control

The Ruff Format check using the command pixi run --environment dev format --check (with if: always()) is an effective way to enforce code style standards, ensuring this step executes regardless of previous failures.


35-39: Ruff Lint Step in Quality-Control

The lint check using pixi run --environment dev lint --diff is a solid approach to capture potential code issues. The unconditional execution (if: always()) reinforces its reliability in the quality control process.


40-44: Mypy Type-Checking in Quality-Control

Including a dedicated Mypy step with pixi run --environment dev type-check directly addresses the primary PR objectives regarding type safety. This ensures that any type-related issues are flagged during the CI cycle.


45-47: Quality Control Summary Step

The final "Collect QC" step, which simply echoes a success message, confirms the completion of quality checks. If more detailed reporting becomes necessary later, consider expanding this step.


51-52: Testing Job: Checkout Step

The testing job also benefits from the updated checkout action (actions/checkout@v4), ensuring consistent behavior across workflows.


53-59: Install Pixi Step in Testing Job

This step mirrors the preparation in the quality-control job by installing Pixi with the specified version, environment, and caching enabled. Consistency here is key to maintaining the unified setup across jobs.


60-62: Execute Test Suite via Pixi

The test execution command (pixi run --environment dev test --show-capture=all -s -vv) is sufficiently detailed and should provide comprehensive output for debugging. The verbosity flags will be helpful during test failures.

@jjjermiah jjjermiah moved this to In review in Roadmap Mar 17, 2025
@jjjermiah jjjermiah moved this from In review to In progress in Roadmap Mar 17, 2025
@jjjermiah jjjermiah self-assigned this Mar 17, 2025
@johanneskoester

Copy link
Copy Markdown
Contributor

Is there no caching in the pixi action without the lock file? I don't think the lock file should be in the repo in case of libraries.

Keep the upstream version check and the PR's typing fixes while
enabling the CI mypy job. Match the shared settings parser signature,
and forward remote job kwargs so `cores` overrides still reach the
parent. Add tests for both behaviors.

Verified: mypy found no issues in 17 files, Ruff format/lint pass,
10 tests pass at 61.59% coverage. Oracle approved; upstream CI and
maintainer review remain the merge gates.
Both PR jobs fail in setup-pixi before tests because this repository
does not track pixi.lock. Keep the mypy quality gate, but restore the
upstream no-cache setup until a lockfile is deliberately committed.

Verified: job 124976573330 reports ENOENT on pixi.lock; workflow YAML
parses and git diff --check passes. Local mypy, Ruff and 10 tests
passed before this CI-only edit.
@jjjermiah

Copy link
Copy Markdown
Contributor Author

I refreshed this branch against current main without rewriting its history. Mypy now reports no issues in 17 files; Ruff and all 10 tests pass. The update also preserves cores overrides in remote executors and drops Pixi caching because this repo has no pixi.lock. On head 7003069, upstream quality-control, testing and title-format checks all pass (run 41349657297). Maintainer review is the remaining merge gate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants