Skip to content

Commit

Permalink
ci: [pre-commit.ci] pre-commit autoupdate (#1068)
Browse files Browse the repository at this point in the history
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.14 →
v0.2.0](astral-sh/ruff-pre-commit@v0.1.14...v0.2.0)
<!--pre-commit.ci end-->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Improved code robustness by utilizing the `get` method for dictionary
access across several modules. This enhances error handling and code
readability.
- **Bug Fixes**
- Adjusted data type handling in file attribute management for
consistency and reliability.
- **Chores**
- Updated the version of a development tool to enhance the setup
configuration formatting process.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Grzegorz Bokota <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and Czaki authored Feb 6, 2024
1 parent 0e4b301 commit 703a274
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: setup-cfg-fmt
args: ["--include-version-classifiers", "--max-py-version", "3.11"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.2.0
hooks:
- id: ruff
- repo: https://github.com/asottile/pyupgrade
Expand Down
2 changes: 1 addition & 1 deletion package/PartSeg/_roi_mask/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def prev_mask(self):
history.roi_extraction_parameters["selected"],
history.roi_extraction_parameters["parameters"],
)
self.settings.mask = seg["mask"] if "mask" in seg else None
self.settings.mask = seg.get("mask")
self.close()


Expand Down
2 changes: 1 addition & 1 deletion package/PartSeg/common_gui/algorithms_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def algorithm_choose(self, name):
if name not in self.widgets_dict:
if name not in self.property.possible_values:
return
start_dict = {} if name not in self.starting_values else self.starting_values[name]
start_dict = self.starting_values.get(name, {})
self.widgets_dict[name] = self._get_form_widget(self.property.possible_values[name], start_dict)

self.layout().addWidget(self.widgets_dict[name])
Expand Down
2 changes: 1 addition & 1 deletion package/PartSegCore/analysis/load_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_project_from_tar(tar_file, file_path):

if version == Version("1.0"):
seg_dict = np.load(tar_to_buff(tar_file, "segmentation.npz"))
mask = seg_dict["mask"] if "mask" in seg_dict else None
mask = seg_dict.get("mask")
roi = seg_dict["segmentation"]
else:
roi = tifffile.imread(tar_to_buff(tar_file, "segmentation.tif"))
Expand Down
12 changes: 6 additions & 6 deletions package/PartSegCore/analysis/save_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ def _save_cmap(
meta_group.attrs[key] = val

grp = cmap_file["Chimera"]
grp.attrs["CLASS"] = np.string_("GROUP")
grp.attrs["TITLE"] = np.string_("")
grp.attrs["VERSION"] = np.string_("1.0")
grp.attrs["CLASS"] = np.bytes_("GROUP")
grp.attrs["TITLE"] = np.bytes_("")
grp.attrs["VERSION"] = np.bytes_("1.0")

grp = cmap_file["Chimera/image1"]
grp.attrs["CLASS"] = np.string_("GROUP")
grp.attrs["TITLE"] = np.string_("")
grp.attrs["VERSION"] = np.string_("1.0")
grp.attrs["CLASS"] = np.bytes_("GROUP")
grp.attrs["TITLE"] = np.bytes_("")
grp.attrs["VERSION"] = np.bytes_("1.0")
grp.attrs["step"] = np.array(spacing, dtype=np.float32)[::-1] * UNIT_SCALE[cmap_profile["units"].value]

return cmap_file
Expand Down
4 changes: 2 additions & 2 deletions package/PartSegCore/mask/io_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ def load_stack_segmentation_from_tar(tar_file: tarfile.TarFile, file_path: str,
step_changed(6)
return MaskProjectTuple(
file_path=file_path,
image=metadata["base_file"] if "base_file" in metadata else None,
image=metadata.get("base_file"),
roi_info=roi_info,
selected_components=metadata["components"],
mask=mask,
roi_extraction_parameters=metadata["parameters"] if "parameters" in metadata else None,
roi_extraction_parameters=metadata.get("parameters"),
history=history,
spacing=([10 ** (-9), *list(spacing)]) if spacing is not None else None,
frame_thickness=metadata.get("frame_thickness", FRAME_THICKNESS),
Expand Down
2 changes: 1 addition & 1 deletion package/PartSegCore/project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_roi_info_and_mask(self) -> Tuple[ROIInfo, Optional[np.ndarray]]:
self.arrays.seek(0)
alternative = {name: array for name, array in seg.items() if name not in {"roi", "mask"}}
roi_info = ROIInfo(seg["roi"], annotations=self.annotations, alternative=alternative)
mask = seg["mask"] if "mask" in seg else None
mask = seg.get("mask")
return roi_info, mask


Expand Down
2 changes: 1 addition & 1 deletion package/PartSegCore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __setitem__(self, k, v) -> None:
if k in self._dict and isinstance(self._dict[k], EventedDict):
self._dict[k].setted.disconnect(self._propagate_setitem)
self._dict[k].deleted.disconnect(self._propagate_del)
old_value = self._dict[k] if k in self._dict else None
old_value = self._dict.get(k)
with suppress(ValueError):
if old_value == v:
return
Expand Down
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ exclude = '''

[tool.ruff]
line-length = 120
exclude = ["examples/call_simple_threshold.py"]
target-version = "py38"
fix = true

[tool.ruff.lint]
select = [
"F", # Pyflakes
"E", "W", # pycodestyle
Expand Down Expand Up @@ -65,22 +70,19 @@ select = [
ignore = ["A003", "SIM108", "ARG002", "ARG003", "ARG004", "PLR2004",
"PLR0913" # should be reenabled in future version
]
exclude = ["examples/call_simple_threshold.py"]
target-version = "py38"
fix = true

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party=['PartSeg', 'PartSegData','PartSegCore','PartSegImage', 'PartSegCore_compiled_backend']

[tool.ruff.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 15

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"docs/conf.py" = ["A001"]
"package/tests/**" = ["ARG", "PLC1901", "S101", "RUF012"]
"package/PartSegCore/sphinx/*" = ["ARG"]
Expand Down

0 comments on commit 703a274

Please sign in to comment.