Skip to content
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

Add more ruff rules, fix pointed problems, add tests #910

Merged
merged 20 commits into from Mar 21, 2023

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Mar 14, 2023

No description provided.

@@ -272,7 +272,7 @@ def _make_class(typename, types, defaults_dict, base_classes, readonly):
global_state["__name__"] = f"serialize_{typename}"
try:
# pylint: disable=W0122
exec(class_definition, global_state) # nosec
exec(class_definition, global_state) # nosec # noqa: S102
Copy link
Contributor

Choose a reason for hiding this comment

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

Detected the use of exec(). exec() can be dangerous if used to evaluate dynamic content. If this content can be input from outside the program, this may be a code injection vulnerability. Ensure evaluated content is not definable by external sources.

Created by exec-detected.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 14, 2023

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.01%.

Quality metrics Before After Change
Complexity 3.60 ⭐ 3.61 ⭐ 0.01 👎
Method Length 61.72 🙂 61.80 🙂 0.08 👎
Working memory 6.70 🙂 6.70 🙂 0.00
Quality 71.88% 🙂 71.87% 🙂 -0.01% 👎
Other metrics Before After Change
Lines 16795 16865 70
Changed files Quality Before Quality After Quality Change
build_utils/create_and_pack_executable.py 77.43% ⭐ 77.45% ⭐ 0.02% 👍
package/PartSeg/_roi_analysis/main_window.py 65.05% 🙂 65.10% 🙂 0.05% 👍
package/PartSeg/_roi_analysis/profile_export.py 65.77% 🙂 65.77% 🙂 0.00%
package/PartSeg/common_backend/__init__.py 92.22% ⭐ 92.10% ⭐ -0.12% 👎
package/PartSeg/common_backend/base_settings.py 83.57% ⭐ 83.57% ⭐ 0.00%
package/PartSeg/common_gui/algorithms_description.py 74.84% 🙂 74.84% 🙂 0.00%
package/PartSeg/common_gui/error_report.py 60.02% 🙂 60.87% 🙂 0.85% 👍
package/PartSeg/common_gui/main_window.py 70.86% 🙂 70.86% 🙂 0.00%
package/PartSeg/common_gui/mask_widget.py 65.56% 🙂 65.56% 🙂 0.00%
package/PartSeg/plugins/__init__.py 82.59% ⭐ 79.29% ⭐ -3.30% 👎
package/PartSeg/plugins/napari_widgets/mask_create_widget.py 68.90% 🙂 68.83% 🙂 -0.07% 👎
package/PartSeg/plugins/napari_widgets/simple_measurement_widget.py 64.06% 🙂 63.93% 🙂 -0.13% 👎
package/PartSegCore/_old_json_hooks.py 48.58% 😞 48.58% 😞 0.00%
package/PartSegCore/algorithm_describe_base.py 66.67% 🙂 66.67% 🙂 0.00%
package/PartSegCore/class_generator.py 49.56% 😞 49.56% 😞 0.00%
package/PartSegCore/custom_name_generate.py 76.30% ⭐ 76.30% ⭐ 0.00%
package/PartSegCore/io_utils.py 83.15% ⭐ 83.16% ⭐ 0.01% 👍
package/PartSegCore/utils.py 78.66% ⭐ 78.65% ⭐ -0.01% 👎
package/PartSegCore/analysis/calculation_plan.py 79.05% ⭐ 79.06% ⭐ 0.01% 👍
package/PartSegCore/analysis/io_utils.py 92.14% ⭐ 92.10% ⭐ -0.04% 👎
package/PartSegCore/analysis/load_functions.py 68.26% 🙂 68.26% 🙂 0.00%
package/PartSegCore/analysis/measurement_base.py 76.06% ⭐ 76.07% ⭐ 0.01% 👍
package/PartSegCore/analysis/measurement_calculation.py 71.05% 🙂 71.04% 🙂 -0.01% 👎
package/PartSegCore/analysis/batch_processing/batch_backend.py 64.84% 🙂 64.87% 🙂 0.03% 👍
package/PartSegCore/analysis/batch_processing/parallel_backend.py 75.04% ⭐ 75.05% ⭐ 0.01% 👍
package/PartSegCore/mask/io_functions.py 66.63% 🙂 66.63% 🙂 0.00%
package/PartSegCore/napari_plugins/save_mask_roi.py 69.86% 🙂 71.04% 🙂 1.18% 👍
package/PartSegCore/plugins/__init__.py 89.19% ⭐ 84.36% ⭐ -4.83% 👎
package/PartSegCore/segmentation/algorithm_base.py 81.08% ⭐ 81.09% ⭐ 0.01% 👍
package/PartSegCore/segmentation/border_smoothing.py 80.96% ⭐ 80.96% ⭐ 0.00%
package/PartSegCore/segmentation/mu_mid_point.py 92.57% ⭐ 92.58% ⭐ 0.01% 👍
package/PartSegCore/segmentation/noise_filtering.py 92.16% ⭐ 92.17% ⭐ 0.01% 👍
package/PartSegCore/segmentation/restartable_segmentation_algorithms.py 74.57% 🙂 74.57% 🙂 0.00%
package/PartSegCore/segmentation/segmentation_algorithm.py 70.54% 🙂 70.55% 🙂 0.01% 👍
package/PartSegCore/segmentation/threshold.py 80.98% ⭐ 80.98% ⭐ 0.00%
package/PartSegCore/segmentation/watershed.py 72.55% 🙂 72.55% 🙂 0.00%
package/PartSegImage/channel_class.py 91.07% ⭐ 90.61% ⭐ -0.46% 👎
package/PartSegImage/image.py 70.50% 🙂 70.22% 🙂 -0.28% 👎
package/PartSegImage/image_reader.py 61.98% 🙂 61.69% 🙂 -0.29% 👎
package/PartSegImage/tifffile_fixes.py 30.16% 😞 30.16% 😞 0.00%
package/tests/test_PartSeg/test_check_release.py 77.53% ⭐ 77.60% ⭐ 0.07% 👍
package/tests/test_PartSeg/test_common_backend.py 73.44% 🙂 73.44% 🙂 0.00%
package/tests/test_PartSeg/test_common_gui.py 76.71% ⭐ 76.62% ⭐ -0.09% 👎
package/tests/test_PartSegCore/test_analysis_batch.py 62.53% 🙂 62.52% 🙂 -0.01% 👎
package/tests/test_PartSegCore/test_napari_plugins.py 84.51% ⭐ 84.37% ⭐ -0.14% 👎
package/tests/test_PartSegCore/test_segmentation.py 73.00% 🙂 73.00% 🙂 0.00%
package/tests/test_PartSegImage/test_image_writer.py 69.59% 🙂 69.59% 🙂 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
package/PartSegCore/analysis/batch_processing/batch_backend.py FileData.add_data_part 26 😞 301 ⛔ 21 ⛔ 18.56% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
package/PartSegImage/tifffile_fixes.py _xml2dict 34 ⛔ 240 ⛔ 20.62% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
package/PartSegCore/class_generator.py _make_class 16 🙂 437 ⛔ 22 ⛔ 22.42% ⛔ Try splitting into smaller methods. Extract out complex expressions
package/PartSegImage/image.py Image.__init__ 15 🙂 324 ⛔ 20 ⛔ 26.16% 😞 Try splitting into smaller methods. Extract out complex expressions
package/PartSegCore/segmentation/restartable_segmentation_algorithms.py BaseMultiScaleOpening.calculation_run 15 🙂 401 ⛔ 15 😞 29.10% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Pull Request #910 refactored by [Sourcery](https://sourcery.ai/github/).

If you're happy with these changes, merge this Pull Request using the
*Squash and merge* strategy.

**NOTE**: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings
as
necessary. If Sourcery finds no refactorings at any point, this Pull
Request
will be closed automatically.

See our documentation
[here](https://docs.sourcery.ai/GitHub/Using-Sourcery-for-GitHub/).

<details>
<summary>Run Sourcery locally</summary>
<p>
Reduce the feedback loop during development by using the Sourcery editor
plugin:
</p>
<ul>
<li><a href="https://sourcery.ai/download/?editor=vscode">VS
Code</a></li>
<li><a
href="https://sourcery.ai/download/?editor=pycharm">PyCharm</a></li>
</ul>
</details>

<details>
<summary>Review changes via command line</summary>
<p>To manually merge these changes, make sure you're on the
<code>upgrade_ruff_configuration</code> branch, then run:</p>
<pre>
git fetch origin sourcery/upgrade_ruff_configuration
git merge --ff-only FETCH_HEAD
git reset HEAD^
</pre>
</details>

Help us
[improve](https://research.typeform.com/to/j06Spdfr?type=pr_refactor&github_login=Czaki&base_repo=https%3A%2F%2Fgithub.com%2F4DNucleome%2FPartSeg.git&base_remote_ref=refs%2Fpull%2F910%2Fhead&base_ref=upgrade_ruff_configuration&base_sha=185d8a030287b111e46a4e58cc65b2505d3c97ab&head_repo=https%3A%2F%2Fgithub.com%2F4DNucleome%2FPartSeg.git&head_ref=sourcery%2Fupgrade_ruff_configuration&base_pr_number=910&base_pr_state=open)
this pull request!

Co-authored-by: Sourcery AI <>
@deprecated-napari-hub-preview-bot
Copy link

Preview page for your plugin is ready here:
https://preview.napari-hub.org/4DNucleome/PartSeg/910
Updated: 2023-03-20T22:40:58.466117

@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 93.67% and project coverage change: +0.09 🎉

Comparison is base (d9c33f4) 91.16% compared to head (7ae1033) 91.26%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #910      +/-   ##
===========================================
+ Coverage    91.16%   91.26%   +0.09%     
===========================================
  Files          197      197              
  Lines        30333    30365      +32     
===========================================
+ Hits         27653    27712      +59     
+ Misses        2680     2653      -27     
Impacted Files Coverage Δ
package/PartSeg/_roi_analysis/profile_export.py 93.67% <ø> (ø)
package/PartSeg/common_gui/main_window.py 88.60% <ø> (+0.37%) ⬆️
package/PartSeg/common_gui/mask_widget.py 93.86% <ø> (ø)
package/PartSeg/plugins/__init__.py 67.64% <ø> (-0.93%) ⬇️
...rtSeg/plugins/napari_widgets/mask_create_widget.py 89.47% <0.00%> (ø)
...lugins/napari_widgets/simple_measurement_widget.py 93.68% <ø> (ø)
package/PartSegCore/algorithm_describe_base.py 86.25% <ø> (ø)
package/PartSegCore/analysis/io_utils.py 89.36% <0.00%> (ø)
package/PartSegCore/analysis/measurement_base.py 90.35% <ø> (ø)
package/PartSegCore/custom_name_generate.py 100.00% <ø> (ø)
... and 36 more

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

sourcery-ai bot and others added 4 commits March 20, 2023 16:56
Pull Request #910 refactored by [Sourcery](https://sourcery.ai/github/).

If you're happy with these changes, merge this Pull Request using the
*Squash and merge* strategy.

**NOTE**: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings
as
necessary. If Sourcery finds no refactorings at any point, this Pull
Request
will be closed automatically.

See our documentation
[here](https://docs.sourcery.ai/GitHub/Using-Sourcery-for-GitHub/).

<details>
<summary>Run Sourcery locally</summary>
<p>
Reduce the feedback loop during development by using the Sourcery editor
plugin:
</p>
<ul>
<li><a href="https://sourcery.ai/download/?editor=vscode">VS
Code</a></li>
<li><a
href="https://sourcery.ai/download/?editor=pycharm">PyCharm</a></li>
</ul>
</details>

<details>
<summary>Review changes via command line</summary>
<p>To manually merge these changes, make sure you're on the
<code>upgrade_ruff_configuration</code> branch, then run:</p>
<pre>
git fetch origin sourcery/upgrade_ruff_configuration
git merge --ff-only FETCH_HEAD
git reset HEAD^
</pre>
</details>

Help us
[improve](https://research.typeform.com/to/j06Spdfr?type=pr_refactor&github_login=Czaki&base_repo=https%3A%2F%2Fgithub.com%2F4DNucleome%2FPartSeg.git&base_remote_ref=refs%2Fpull%2F910%2Fhead&base_ref=upgrade_ruff_configuration&base_sha=8b009c2863e796ab24375001f1061cb6ea2f6844&head_repo=https%3A%2F%2Fgithub.com%2F4DNucleome%2FPartSeg.git&head_ref=sourcery%2Fupgrade_ruff_configuration&base_pr_number=910&base_pr_state=open)
this pull request!

Co-authored-by: Sourcery AI <>
@sonarcloud
Copy link

sonarcloud bot commented Mar 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Czaki Czaki changed the title Add more ruff rules Add more ruff rules, fix pointed problems Mar 21, 2023
@Czaki Czaki changed the title Add more ruff rules, fix pointed problems Add more ruff rules, fix pointed problems, add tests Mar 21, 2023
@Czaki Czaki merged commit 7239fef into develop Mar 21, 2023
44 of 46 checks passed
@Czaki Czaki deleted the upgrade_ruff_configuration branch March 21, 2023 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant