PartSeg icon indicating copy to clipboard operation
PartSeg copied to clipboard

chore: Drop python 3.8

Open Czaki opened this issue 1 year ago • 3 comments

Python 3.8 reached EOL so it is time to drop it.

Summary by Sourcery

Drop support for Python 3.8 across the codebase and CI configuration. Update type annotations to use modern Python syntax and refactor code for improved readability and consistency.

Enhancements:

  • Update type annotations to use Python 3.9+ syntax, replacing typing.List and typing.Dict with list and dict.
  • Refactor test cases to use updated type annotations and improve readability.
  • Refactor code to use context managers with parentheses for better readability and consistency.

CI:

  • Remove Python 3.8 from the CI configuration as it has reached end-of-life.

Summary by CodeRabbit

  • New Features

    • Updated Python version support for testing workflows to include versions 3.9 to 3.12.
    • Enhanced type hinting across various components for improved code clarity and modern practices.
  • Bug Fixes

    • Corrected inconsistencies in method signatures and type annotations throughout the codebase.
  • Documentation

    • Improved docstring formatting for consistency and clarity.
  • Refactor

    • Refactored methods and classes to utilize built-in types over typing module constructs for better readability.

Czaki avatar Oct 09 '24 12:10 Czaki

Reviewer's Guide by Sourcery

This pull request drops support for Python 3.8 and updates the codebase to use more modern Python syntax, particularly with type annotations. The changes primarily involve updating type hints to use the new syntax introduced in Python 3.9+, such as using list[int] instead of List[int]. Additionally, some minor code style improvements and syntax updates have been made throughout the project.

Class diagram for updated type annotations

classDiagram
    class ComponentsInfo {
        np.ndarray roi_components
        np.ndarray mask_components
        dict[int, list[int]] components_translation
        bool has_components()
    }

    class MeasurementResult {
        ComponentsInfo components_info
        OrderedDict _data_dict
        dict[str, str] _units_dict
        dict[str, tuple[PerComponent, AreaType]] _type_dict
        void set_filename(str path_fo_file)
        tuple[bool, bool] get_component_info(bool all_components)
        list[str] get_labels(bool expand, bool all_components)
        list[str] get_units(bool all_components)
        list[list[MeasurementValueType]] get_separated(bool all_components)
    }

    class MaskProjectTuple {
        Union[Image, str, None] image
        Optional[np.ndarray] mask
        ROIInfo roi_info
        dict[str, AdditionalLayerDescription] additional_layers
        list[int] selected_components
        dict[int, Optional[ROIExtractionProfile]] roi_extraction_parameters
        list[HistoryElement] history
        str errors
        Optional[list[float]] spacing
        Optional[np.ndarray] points
        int frame_thickness
    }

    class ImageInfo {
        Image image
        list[NapariImage] layers
        list[tuple[NoiseFilterType, float]] filter_info
        Optional[Labels] mask
        Optional[np.ndarray] mask_array
        Optional[Labels] roi
        int roi_count
        Optional[Labels] highlight
        bool coords_in(Union[list[int], np.ndarray] coords)
        np.ndarray translated_coords(Union[list[int], np.ndarray] coords)
    }

File-Level Changes

Change Details Files
Drop support for Python 3.8
  • Remove Python 3.8 from CI/CD workflows
  • Update minimum Python version in configuration files
.github/workflows/tests.yml
azure-pipelines.yml
.pre-commit-config.yaml
Update type annotations to use Python 3.9+ syntax
  • Replace List, Dict, Tuple, and Set with their lowercase equivalents
  • Update typing.Union to use the `
operator where applicable</li><li>Remove explicittyping` imports where possible
Update syntax for context managers
  • Use parenthesized context managers for multiple context managers
package/tests/test_PartSeg/test_channel_control.py
package/PartSegImage/image_reader.py
package/PartSeg/_launcher/check_version.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Oct 09 '24 12:10 sourcery-ai[bot]

Walkthrough

This pull request includes modifications to the workflow files for testing napari widgets, updating Python version compatibility, and adjusting type annotations in several files. The workflows now exclude Python 3.8, focusing on versions 3.9 to 3.12. The napari versions tested have also been updated. Additionally, type annotations have been modernized across various classes and functions, reflecting a shift from the typing module to built-in types. The overall structure of the workflows and modules remains intact while implementing these changes.

Changes

File Path Change Summary
.github/workflows/test_napari_widgets.yml Updated napari versions in test-latest-release and test-pyqt5 jobs, modified trigger branches for the workflow.
.github/workflows/tests.yml Excluded Python 3.8 from base-test, base-test-main, and updated Python versions for other jobs.
package/PartSeg/plugins/napari_widgets/lables_control.py Updated parameter type from List to list in constructors of NapariLabelShow and NapariLabelChoose.
package/PartSegCore/register.py Updated register function's target parameter type from Type[AlgorithmDescribeBase] to type[AlgorithmDescribeBase].
Various files in package/PartSeg and package/PartSegCore Updated type hints to use built-in types instead of typing across multiple classes and functions.

Possibly related PRs

  • #1148: The changes in this PR involve updates to the napari version in the workflow configuration for testing, which directly relates to the updates made in the main PR regarding the napari parameter in the .github/workflows/test_napari_widgets.yml file.
  • #1192: This PR includes modifications to the napari_image_view.py file that enhance compatibility with different versions of napari, which aligns with the main PR's focus on updating napari versions in the testing workflows.
  • #1203: The changes in this PR to the .github/workflows/tests.yml file include enhancements to the testing framework, which may relate to the overall structure and configuration updates seen in the main PR's workflow files.

Suggested labels

skip check PR title

🐇 In the fields of code we play,
Python's new versions lead the way.
Dependencies fresh, we hop along,
Modernizing our project, making it strong!
With every change, our code takes flight,
A brighter future, oh what a sight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4e7e31fb4378aedef382cfc3b49643663289b983 and c06e15d0190e31a797fef0bc8f02dc5e2684f56c.

📒 Files selected for processing (4)
  • .github/workflows/test_napari_widgets.yml (2 hunks)
  • .github/workflows/tests.yml (4 hunks)
  • package/PartSeg/plugins/napari_widgets/lables_control.py (4 hunks)
  • package/PartSegCore/register.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/test_napari_widgets.yml
  • .github/workflows/tests.yml
  • package/PartSeg/plugins/napari_widgets/lables_control.py
  • package/PartSegCore/register.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

coderabbitai[bot] avatar Oct 09 '24 12:10 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 99.70674% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.12%. Comparing base (24978a5) to head (c06e15d). Report is 24 commits behind head on develop.

Files with missing lines Patch % Lines
package/PartSegCore/algorithm_describe_base.py 92.85% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1206      +/-   ##
===========================================
- Coverage    93.13%   93.12%   -0.01%     
===========================================
  Files          210      210              
  Lines        33149    33149              
===========================================
- Hits         30873    30870       -3     
- Misses        2276     2279       +3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Oct 15 '24 22:10 codecov[bot]

@coderabbitai full review

Czaki avatar Oct 17 '24 11:10 Czaki

:white_check_mark: Actions performed

Full review triggered.

coderabbitai[bot] avatar Oct 17 '24 11:10 coderabbitai[bot]