Skip to content

fix: address mypy issues #83

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jjjermiah
Copy link
Contributor

@jjjermiah jjjermiah commented Mar 16, 2025

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

  • Chores

    • Streamlined build and release workflows for more reliable package publishing and improved version control.
  • Tests

    • Upgraded automated quality control and testing processes with modern tooling to ensure robust validation before release.
  • Refactor

    • Enhanced internal maintainability by refining type definitions and interface structures, paving the way for smoother future updates.

Overall, these improvements contribute to a more stable and efficient release process for end users.

Copy link
Contributor

coderabbitai bot commented Mar 16, 2025

📝 Walkthrough

Walkthrough

This pull request implements several updates across configuration, workflow, and executor modules. The changes include adding a new entry in the Git attributes to handle the pixi.lock file as a binary file with YAML highlighting, and modifications to GitHub workflows to rename jobs and switch from Poetry to Pixi for dependency installation, building, testing, and publishing. Additionally, the update enhances several Snakemake executor and interface classes with new typed attributes, revised method signatures, and expanded callback properties, alongside minor updates to the ignore rules in the .gitignore file.

Changes

File(s) Change Summary
.gitattributes Added entry to treat pixi.lock as binary with YAML highlighting and generated marker.
.gitignore Added ignore entries for .pixi directory and *.egg-info files.
.github/workflows/release-please.yml
.github/workflows/test.yml
Workflows updated: renamed jobs (e.g., publishpublish-pypi, formattingquality-control), updated checkout from v3 to v4, removed Poetry steps in favor of Pixi installation, and restructured steps for building, quality control, testing, and publishing. Permissions were added in test.yml.
snakemake_interface_executor_plugins/executors/base.py
snakemake_interface_executor_plugins/executors/real.py
snakemake_interface_executor_plugins/executors/remote.py
Enhanced executor classes with new typed attributes (e.g., workflow, logger, executor_settings, etc.) and updated method signatures with improved type annotations (e.g., accepting additional **kwargs in get_job_args).
snakemake_interface_executor_plugins/jobs.py
snakemake_interface_executor_plugins/scheduler.py
snakemake_interface_executor_plugins/workflow.py
Updated job and workflow interfaces: changed return type for get_target_spec to List[TargetSpec], added callback attributes (submit_callback, finish_callback, error_callback) in the scheduler interface, and introduced new abstract properties (executor_settings and dag) in the workflow interface.

Sequence Diagram(s)

sequenceDiagram
  participant Event as "GitHub Event"
  participant Runner as "GitHub Runner"
  participant Checkout as "Checkout Action (v4)"
  participant Setup as "Pixi Setup (v0.8.3)"
  participant Build as "Build (pixi check-build)"
  participant Publish as "Publish to PyPI"

  Event->>Runner: Trigger release
  Runner->>Checkout: Checkout code
  Checkout->>Setup: Set up Pixi environment
  Setup->>Build: Execute build step
  Build->>Publish: Publish distribution
Loading
sequenceDiagram
  participant Event as "GitHub Event"
  participant Runner as "GitHub Runner"
  participant QC as "Quality-Control Job"
  participant Test as "Testing Job"

  Event->>Runner: Trigger test workflow
  Runner->>QC: Start Quality-Control Job
  QC->>QC: Set permissions & Checkout (v4)
  QC->>QC: Install Pixi (dev)
  QC->>QC: Run Ruff Format, Ruff Lint, Mypy
  QC->>QC: Complete quality checks
  Runner->>Test: Start Testing Job
  Test->>Test: Checkout (v4) & Install Pixi
  Test->>Test: Execute test suite
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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:

✅ 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
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.

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