Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 6, 2024

Choose a reason for hiding this comment

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

Consider adding error handling for the case where seg does not contain the expected structure or types, to improve robustness.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The dict.get returns None if the key is absent, so error handling is not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Czaki: Acknowledged. Your approach with dict.get effectively handles the scenario where the key might be absent by returning None. This indeed simplifies the need for additional error handling in this context. Thank you for the clarification.

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