Skip to content

Commit bfecd40

Browse files
committed
ref: cleanup with ruff
1 parent 299f4be commit bfecd40

4 files changed

Lines changed: 37 additions & 24 deletions

File tree

‎CHANGELOG‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.10.2
22
- enh: add `flush` method to `DevNull` null writer
3+
- ref: partial cleanup with ruff
34
0.10.1
45
- enh: add `--info` flag (prints runtime info) for `chipstream-cli`
56
- setup: bump dcnum to 0.30.1 (basin-based background in input file)

‎chipstream/cli/cli_proc.py‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pathlib
22
import time
3-
from typing import List, Literal
3+
from typing import Literal
44

55
import click
66
import dcnum.logic
@@ -19,11 +19,11 @@ def process_dataset(
1919
path_in: pathlib.Path,
2020
path_out: pathlib.Path,
2121
background_method: str,
22-
background_kwargs: List[str],
22+
background_kwargs: list[str],
2323
segmentation_method: str,
24-
segmentation_kwargs: List[str],
25-
feature_kwargs: List[str],
26-
gate_kwargs: List[str],
24+
segmentation_kwargs: list[str],
25+
feature_kwargs: list[str],
26+
gate_kwargs: list[str],
2727
pixel_size: float,
2828
index_mapping: int | slice | None,
2929
# Below this line are arguments that do not affect the pipeline ID
@@ -63,37 +63,37 @@ def process_dataset(
6363
click.echo(f"Data ID:\t{dat_id}")
6464

6565
# background keyword arguments
66-
bg_kwargs = validate_background_kwargs(background_method,
67-
background_kwargs)
66+
bg_kwargs_dict = validate_background_kwargs(background_method,
67+
background_kwargs)
6868
if (background_method == "sparsemed"
69-
and "offset_correction" not in bg_kwargs):
69+
and "offset_correction" not in bg_kwargs_dict):
7070
# We are using the 'sparsemed' background algorithm, and the user
7171
# did not specify whether they want to perform flickering
7272
# correction. Thus, we automatically check whether we need that.
7373
with dcnum.read.HDF5Data(path_in) as hd:
74-
bg_kwargs["offset_correction"] = \
74+
bg_kwargs_dict["offset_correction"] = \
7575
dcnum.read.detect_flickering(hd.image)
7676
bg_cls = cm.get_available_background_methods()[background_method]
77-
bg_id = bg_cls.get_ppid_from_ppkw(bg_kwargs)
77+
bg_id = bg_cls.get_ppid_from_ppkw(bg_kwargs_dict)
7878
click.echo(f"Background ID:\t{bg_id}")
7979

8080
# segmenter keyword arguments
81-
seg_kwargs = validate_segmentation_kwargs(segmentation_method,
82-
segmentation_kwargs)
81+
seg_kwargs_dict = validate_segmentation_kwargs(segmentation_method,
82+
segmentation_kwargs)
8383
seg_cls = cm.get_segmenters()[segmentation_method]
84-
seg_id = seg_cls.get_ppid_from_ppkw(seg_kwargs)
84+
seg_id = seg_cls.get_ppid_from_ppkw(seg_kwargs_dict)
8585
click.echo(f"Segmenter ID:\t{seg_id}")
8686

8787
# feature keyword arguments
88-
feat_kwargs = validate_feature_kwargs(feature_kwargs)
88+
feat_kwargs_dict = validate_feature_kwargs(feature_kwargs)
8989
feat_cls = cm.QueueEventExtractor
90-
feat_id = feat_cls.get_ppid_from_ppkw(feat_kwargs)
90+
feat_id = feat_cls.get_ppid_from_ppkw(feat_kwargs_dict)
9191
click.echo(f"Feature ID:\t{feat_id}")
9292

9393
# gate keyword arguments
9494
gate_cls = cm.Gate
95-
gate_kwargs = validate_gate_kwargs(gate_kwargs)
96-
gate_id = gate_cls.get_ppid_from_ppkw(gate_kwargs)
95+
gate_kwargs_dict = validate_gate_kwargs(gate_kwargs)
96+
gate_id = gate_cls.get_ppid_from_ppkw(gate_kwargs_dict)
9797
click.echo(f"Gate ID:\t{gate_id}")
9898

9999
# compute pipeline hash
@@ -116,13 +116,13 @@ def process_dataset(
116116
data_code="hdf",
117117
data_kwargs=data_kwargs,
118118
background_code=bg_cls.get_ppid_code(),
119-
background_kwargs=bg_kwargs,
119+
background_kwargs=bg_kwargs_dict,
120120
segmenter_code=seg_cls.get_ppid_code(),
121-
segmenter_kwargs=seg_kwargs,
121+
segmenter_kwargs=seg_kwargs_dict,
122122
feature_code=feat_cls.get_ppid_code(),
123-
feature_kwargs=feat_kwargs,
123+
feature_kwargs=feat_kwargs_dict,
124124
gate_code=gate_cls.get_ppid_code(),
125-
gate_kwargs=gate_kwargs,
125+
gate_kwargs=gate_kwargs_dict,
126126
basin_strategy=basin_strategy,
127127
compression=compression,
128128
num_procs=num_cpus,
@@ -152,7 +152,7 @@ def process_dataset(
152152
if status["state"] in ["done", "error"]:
153153
break
154154
time.sleep(.3) # don't use 100% CPU
155-
print("") # new line
155+
print() # new line
156156

157157
if status["state"] == "error":
158158
runner.join(delete_temporary_files=False)

‎chipstream/cli/cli_valid.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
from typing import Any
23
import warnings
34

45
from dcnum.meta import ppid
@@ -26,7 +27,7 @@ def validate_background_kwargs(bg_method, args):
2627
return kwargs
2728

2829

29-
def validate_feature_kwargs(args):
30+
def validate_feature_kwargs(args: list[str]) -> dict[str, Any]:
3031
# Get list of valid keyword arguments
3132
feat_cls = cm.QueueEventExtractor
3233
feat_code = feat_cls.get_ppid_code()
@@ -46,7 +47,7 @@ def validate_feature_kwargs(args):
4647
return kwargs
4748

4849

49-
def validate_gate_kwargs(args):
50+
def validate_gate_kwargs(args: list[str]) -> dict[str, Any]:
5051
spec = inspect.getfullargspec(cm.Gate.__init__)
5152
valid_kw_appr = spec.kwonlyargs
5253
annot_appr = spec.annotations

‎pyproject.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ packages = ["chipstream"]
5656
[tool.setuptools_scm]
5757
write_to = "chipstream/_version.py"
5858
version_scheme = "post-release"
59+
60+
[tool.ruff.lint]
61+
ignore = [
62+
# Do not organize imports (we have our own scheme)
63+
"I001",
64+
# Allow catching blind exceptions
65+
"BLE001",
66+
# Allow catching blind exceptions
67+
"S110",
68+
"S112",
69+
]

0 commit comments

Comments
 (0)