-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: Fix napari 0.5.0 compatybility #1116
Conversation
🧙 Sourcery has finished reviewing your pull request! Tips
|
WalkthroughThe recent changes primarily involve updating the PartSeg package and its associated tests to accommodate the new napari version 5.0. These updates include adding conditional checks based on the napari version, modifying the way colormaps are handled, and updating test cases to reflect changes in rendering methods. Additionally, there is an update in the pyproject.toml to restrict the numpy version to below 2. Changes
Tip AI model upgrade
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- package/PartSeg/_roi_mask/image_view.py (2 hunks)
- package/PartSeg/common_backend/base_settings.py (3 hunks)
- package/PartSeg/common_gui/error_report.py (3 hunks)
- package/PartSeg/common_gui/napari_image_view.py (3 hunks)
- pyproject.toml (1 hunks)
Additional comments not posted (10)
package/PartSeg/_roi_mask/image_view.py (2)
1-2
: Import statement additions are appropriate.The added imports for
version
andparse_version
are necessary for the version checking logic introduced later.Also applies to: 3-3
10-10
: Version check and conditional logic are correct.The
_napari_ge_0_5_0
check and the corresponding conditional logic ensure compatibility withnapari
version 0.5.0.Also applies to: 22-25
pyproject.toml (1)
57-57
: Dependency version range update is appropriate.The change to the
numpy
dependency version range ensures compatibility withmahotas
by requiring a rebuild fornumpy
2.package/PartSeg/common_gui/error_report.py (2)
15-15
: Import statement additions are appropriate.The added imports for
version
andparse_version
are necessary for the version checking logic introduced later.Also applies to: 22-22
58-58
: Version check and conditional logic are correct.The
_napari_ge_5
check and the corresponding conditional logic ensure compatibility withnapari
version 0.5.0.Also applies to: 88-91
package/PartSeg/common_backend/base_settings.py (3)
20-20
: Import statement addition is appropriate.The added import for
parse_version
is necessary for the version checking logic introduced later.
41-41
: Version check is correct.The
_napari_ge_5
check ensures compatibility withnapari
version 0.5.0.
274-275
: Conditional logic in thetheme
property is correct.The conditional logic ensures the
theme
property returns the correct value based on thenapari
version.package/PartSeg/common_gui/napari_image_view.py (2)
45-45
: LGTM! Version check for napari 0.5.0a1.The version check
_napari_ge_5
is correctly implemented usingparse_version
.
969-974
: LGTM! Conditionalview
property based on napari version.The
view
property is correctly implemented to returnself.canvas.view
if_napari_ge_5
is True.
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- package/PartSeg/common_gui/error_report.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- package/PartSeg/common_gui/error_report.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- package/PartSeg/common_gui/napari_image_view.py (4 hunks)
- package/PartSeg/plugins/napari_widgets/search_label_widget.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- package/PartSeg/common_gui/napari_image_view.py
@@ -4,6 +4,7 @@ | |||
from magicgui.widgets import Container, HBox, PushButton, SpinBox, create_widget | |||
from napari import Viewer | |||
from napari.layers import Labels | |||
from napari.utils import DirectLabelColormap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant entry in color_dict
.
The color_dict
parameter in DirectLabelColormap
has a redundant entry for None
. The DirectLabelColormap
can handle missing keys without explicit None
entry.
- colormap=DirectLabelColormap(color_dict={0: (0, 0, 0, 0), 1: "white", None: (0, 0, 0, 0)}),
+ colormap=DirectLabelColormap(color_dict={0: (0, 0, 0, 0), 1: "white"}),
Also applies to: 81-81
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- package/PartSeg/common_gui/napari_image_view.py (3 hunks)
- package/PartSeg/plugins/napari_widgets/lables_control.py (2 hunks)
- package/PartSeg/plugins/napari_widgets/search_label_widget.py (2 hunks)
- package/tests/test_PartSeg/test_channel_control.py (3 hunks)
- package/tests/test_PartSeg/test_napari_image_view.py (3 hunks)
- package/tests/test_PartSeg/test_napari_widgets.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- package/PartSeg/plugins/napari_widgets/search_label_widget.py
Additional comments not posted (18)
package/PartSeg/plugins/napari_widgets/lables_control.py (3)
1-1
: Consider importingversion
andparse_version
together.To improve readability and maintainability, consider importing
version
andparse_version
in a single import statement.from importlib.metadata import version from packaging.version import parse as parse_versionAlso applies to: 6-6
13-13
: Ensure the version check is correctly implemented.The version check logic seems correct, but ensure that
parse_version(version("napari"))
correctly retrieves the napari version at runtime.
44-47
: Ensure correct colormap assignment based on napari version.The conditional logic for assigning colormap based on the napari version is correctly implemented. Ensure that
layer.colormap
andlayer.color
are the correct attributes for the respective napari versions.Verification successful
Correct colormap assignment based on napari version.
The conditional logic for colormap assignment based on the napari version is correctly implemented. The attributes
layer.colormap
andlayer.color
are valid and appropriately used for the respective napari versions.
package/PartSeg/plugins/napari_widgets/lables_control.py
:layer.colormap = labels
,layer.color = labels
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the colormap assignment is correctly handled based on napari version. # Test: Check the attributes of a napari Labels layer. Expect: colormap for napari >= 0.5.0 and color for napari < 0.5.0. python -c "from napari.layers import Labels; from packaging.version import parse as parse_version; from importlib.metadata import version; print(hasattr(Labels, 'colormap'), hasattr(Labels, 'color'))"Length of output: 288
Script:
#!/bin/bash # Description: Verify that the colormap assignment is correctly handled based on napari version. # Search for the colormap attribute in the Labels class ast-grep --lang python --pattern $'class Labels:\n $$$\n colormap = $_\n $$$' # Search for the color attribute in the Labels class ast-grep --lang python --pattern $'class Labels:\n $$$\n color = $_\n $$$'Length of output: 154
Script:
#!/bin/bash # Description: Verify that the colormap assignment is correctly handled based on napari version. # Search for colormap references in the napari codebase rg --word-regexp 'colormap' # Search for color references in the napari codebase rg --word-regexp 'color'Length of output: 32800
package/tests/test_PartSeg/test_napari_image_view.py (4)
4-4
: Consider importingversion
andparse_version
together.To improve readability and maintainability, consider importing
version
andparse_version
in a single import statement.from importlib.metadata import version from packaging.version import parse as parse_versionAlso applies to: 11-11
33-36
: Ensure the conditional logic forEXPECTED_RANGE
is correct.The conditional logic for setting
EXPECTED_RANGE
based on the napari version is correctly implemented. Ensure thatEXPECTED_RANGE
values are appropriate for the respective napari versions.
259-259
: Ensure theEXPECTED_RANGE
is correctly applied.The usage of
EXPECTED_RANGE
in the test case is correctly implemented. Ensure that the value ofEXPECTED_RANGE
is appropriate for the napari version and the test case.
30-30
: Ensure the version check is correctly implemented.The version check logic seems correct, but ensure that
parse_version(version("napari"))
correctly retrieves the napari version at runtime.package/tests/test_PartSeg/test_channel_control.py (2)
312-317
: Ensure the_render()
method is correctly implemented.The replacement of
canvas.render()
with_render()
method calls onviewer_widget
instances is correctly implemented. Ensure that the_render()
method is correctly defined and behaves as expected.Verification successful
Ensure the
_render()
method is correctly implemented.The replacement of
canvas.render()
with_render()
method calls onviewer_widget
instances is correctly implemented. The_render()
method is defined and conditionally calls the appropriate render method based on the version of thenapari
library.
_render
method implementation:def _render(self): if _napari_ge_5: return self.canvas._scene_canvas.render() return self.canvas.render()Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the `_render()` method on `viewer_widget` instances is correctly implemented. # Test: Check the definition of `_render()` method. Expect: Correct method definition. rg --type python 'def _render' package/PartSeg/common_gui/napari_image_view.pyLength of output: 111
Script:
#!/bin/bash # Description: Verify that the `_render()` method on `viewer_widget` instances is correctly implemented. # Test: Check the definition of `_render()` method. Expect: Correct method definition. rg 'def _render' package/PartSeg/common_gui/napari_image_view.pyLength of output: 89
Script:
#!/bin/bash # Description: Extract the implementation details of the `_render()` method in `package/PartSeg/common_gui/napari_image_view.py`. # Test: Retrieve the full implementation of `_render` method. ast-grep --lang python --pattern 'def _render(self): $$$' package/PartSeg/common_gui/napari_image_view.pyLength of output: 453
331-337
: Ensure the_render()
method is correctly implemented.The replacement of
canvas.render()
with_render()
method calls onviewer_widget
instances is correctly implemented. Ensure that the_render()
method is correctly defined and behaves as expected.Verification successful
The
_render()
method is correctly implemented.The
_render()
method in theviewer_widget
class is correctly defined and properly calls the appropriate rendering functions based on the version of Napari being used.
- File:
package/PartSeg/common_gui/napari_image_view.py
- Lines: 1-10
def _render(self): if _napari_ge_5: return self.canvas._scene_canvas.render() return self.canvas.render()Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the `_render()` method on `viewer_widget` instances is correctly implemented. # Test: Check the definition of `_render()` method. Expect: Correct method definition. rg --type python 'def _render' package/PartSeg/common_gui/napari_image_view.pyLength of output: 111
Script:
#!/bin/bash # Description: Verify that the `_render()` method on `viewer_widget` instances is correctly implemented. # Test: Check the definition of `_render()` method. Expect: Correct method definition. ast-grep --lang python --pattern 'def _render($_) { $$$ }'Length of output: 506
Script:
#!/bin/bash # Description: Verify that the `_render()` method on `viewer_widget` instances is correctly implemented. # Test: Check the definition of `_render()` method. Expect: Correct method definition. ast-grep --lang python --pattern 'def _render($$):'Length of output: 53
Script:
#!/bin/bash # Description: Verify the existence of `_render()` or similarly named methods in the codebase. # Test: List all method definitions in the repository. ast-grep --lang python --pattern 'def $FUNC($$):'Length of output: 51
Script:
#!/bin/bash # Description: Verify the existence of `_render()` method in the codebase. # Test: Search for the `_render` method definition in the entire repository. rg 'def _render'Length of output: 89
Script:
#!/bin/bash # Description: Extract the implementation of the `_render()` method. # Test: Extract the `_render` method implementation from the specified file. ast-grep --lang python --pattern 'def _render($$): { $$$ }' package/PartSeg/common_gui/napari_image_view.pyLength of output: 109
Script:
#!/bin/bash # Description: Extract the implementation of the `_render()` method. # Test: Extract the `_render` method implementation from the specified file. rg -A 10 'def _render' package/PartSeg/common_gui/napari_image_view.pyLength of output: 312
package/tests/test_PartSeg/test_napari_widgets.py (4)
4-4
: Consider importingversion
andparse_version
together.To improve readability and maintainability, consider importing
version
andparse_version
in a single import statement.from importlib.metadata import version from packaging.version import parse as parse_versionAlso applies to: 14-14
378-380
: Ensure correct colormap and color_mode assignment in test cases.The usage of
check_auto_mode
andcheck_direct_mode
functions in the test cases is correctly implemented. Ensure that the colormap and color_mode attributes are appropriately assigned based on the napari version.
60-60
: Ensure the version check is correctly implemented.The version check logic seems correct, but ensure that
parse_version(version("napari"))
correctly retrieves the napari version at runtime.Verification successful
The version check is correctly implemented.
The static analysis confirms that
parse_version(version("napari"))
is used correctly to retrieve and compare thenapari
version.
package/tests/test_PartSeg/test_napari_widgets.py
: Line 60Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the version check for napari is correctly implemented. # Test: Print the napari version. Expect: Correct napari version string. python -c "from importlib.metadata import version; print(version('napari'))"Length of output: 158
Script:
#!/bin/bash # Description: Verify that the version check for napari is correctly implemented. # Test: Print the napari version. Expect: Correct napari version string. python3 -c "from importlib.metadata import version; print(version('napari'))"Length of output: 160
Script:
#!/bin/bash # Description: Verify the usage of parse_version and version functions in the codebase. # Search for the usage of parse_version in the codebase echo "Searching for parse_version usage..." rg 'parse_version' # Search for the usage of version function from importlib.metadata in the codebase echo "Searching for version function usage..." rg 'from importlib.metadata import version'Length of output: 4573
62-81
: Ensure correct colormap and color_mode assignment based on napari version.The conditional logic for colormap and color_mode assignment based on the napari version is correctly implemented. Ensure that
CyclicLabelColormap
,DirectLabelColormap
, andcolor_mode
attributes are appropriate for the respective napari versions.Verification successful
Ensure correct colormap and color_mode assignment based on napari version.
The imports and usage of
CyclicLabelColormap
andDirectLabelColormap
are correctly implemented in the test filepackage/tests/test_PartSeg/test_napari_widgets.py
. The conditional logic ensures that these colormaps are assigned based on the napari version. Additionally, thecolor_mode
attribute is checked correctly in the alternative branch of the conditional logic.
package/tests/test_PartSeg/test_napari_widgets.py
: Correct usage ofCyclicLabelColormap
andDirectLabelColormap
.package/PartSeg/common_gui/napari_image_view.py
: Correct usage ofDirectLabelColormap
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the colormap and color_mode attributes are correctly handled based on napari version. # Test: Check the attributes of a napari Labels layer. Expect: Correct colormap and color_mode attributes. python -c "from napari.layers import Labels; from packaging.version import parse as parse_version; from importlib.metadata import version; print(hasattr(Labels, 'colormap'), hasattr(Labels, 'color_mode'))"Length of output: 293
Script:
#!/bin/bash # Search for usage of 'colormap' in the 'Labels' layer ast-grep --lang python --pattern $'class Labels($_) {\n $$$\n self.colormap = $_\n $$$\n}' # Search for usage of 'color_mode' in the 'Labels' layer ast-grep --lang python --pattern $'class Labels($_) {\n $$$\n self.color_mode = $_\n $$$\n}'Length of output: 873
Script:
#!/bin/bash # Search for the definition of the 'Labels' class and inspect its methods or attributes ast-grep --lang python --pattern $'class Labels($_) {\n $$$\n}' # Search for imports of 'CyclicLabelColormap' and 'DirectLabelColormap' rg 'from napari.utils.colormaps import CyclicLabelColormap' rg 'from napari.utils.colormaps import DirectLabelColormap'Length of output: 973
Script:
#!/bin/bash # Search for usage of 'CyclicLabelColormap' in the codebase rg 'CyclicLabelColormap' # Search for usage of 'DirectLabelColormap' in the codebase rg 'DirectLabelColormap'Length of output: 731
package/PartSeg/common_gui/napari_image_view.py (5)
45-46
: Version check for napari 0.5.0 compatibility added.The version check
_napari_ge_5
is correctly implemented.
48-55
: New functionget_highlight_colormap
added.The function correctly handles colormap based on the napari version.
853-853
: Updated_mark_layer
function to useget_highlight_colormap
.The function correctly integrates the new colormap handling.
979-983
: New_render
method added toNapariQtViewer
class.The method correctly handles rendering based on the napari version.
984-989
: Newview
property added toNapariQtViewer
class.The property correctly returns the canvas view based on the napari version.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1116 +/- ##
===========================================
- Coverage 92.95% 92.91% -0.05%
===========================================
Files 205 205
Lines 32464 32519 +55
===========================================
+ Hits 30177 30215 +38
- Misses 2287 2304 +17 ☔ View full report in Codecov by Sentry. |
Quality Gate passedIssues Measures |
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- package/tests/test_PartSeg/test_common_backend.py (1 hunks)
Files skipped from review due to trivial changes (1)
- package/tests/test_PartSeg/test_common_backend.py
Summary by CodeRabbit
New Features
Bug Fixes
Dependencies
numpy
dependency to version >= 1.18.5 but < 2.Tests