Skip to content

Commit 77292b1

Browse files
authored
black -> ruff format + cleanup (zarr-developers#1639)
* black -> ruff + cleanup * format * Preserve git blame * pre-commit fix
1 parent 4e6cca2 commit 77292b1

36 files changed

+58
-296
lines changed

.flake8

-2
This file was deleted.

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# lint codebase with black and ruff
22
4e348d6b80c96da461fd866576c971b8a659ba15
3+
# migrate from black to ruff format
4+
22cea005629913208a85799372e045f353744add

.pre-commit-config.yaml

+6-11
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,22 @@ default_language_version:
77
python: python3
88
repos:
99
- repo: https://github.com/charliermarsh/ruff-pre-commit
10-
# Ruff version.
11-
rev: 'v0.0.224'
10+
rev: 'v0.2.1'
1211
hooks:
1312
- id: ruff
14-
# Respect `exclude` and `extend-exclude` settings.
15-
args: ["--force-exclude"]
16-
- repo: https://github.com/psf/black
17-
rev: 22.12.0
18-
hooks:
19-
- id: black
13+
args: ["--fix", "--show-fixes"]
14+
- id: ruff-format
2015
- repo: https://github.com/codespell-project/codespell
21-
rev: v2.2.5
16+
rev: v2.2.6
2217
hooks:
2318
- id: codespell
2419
args: ["-L", "ba,ihs,kake,nd,noe,nwo,te,fo,zar", "-S", "fixture"]
2520
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.4.0
21+
rev: v4.5.0
2722
hooks:
2823
- id: check-yaml
2924
- repo: https://github.com/pre-commit/mirrors-mypy
30-
rev: v1.7.1
25+
rev: v1.8.0
3126
hooks:
3227
- id: mypy
3328
files: src

bench/compress_normal.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from zarr import blosc
99

1010
if __name__ == "__main__":
11-
1211
sys.path.insert(0, "..")
1312

1413
# setup

pyproject.toml

+2-16
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ serve = "sphinx-autobuild docs docs/_build --ignore 'docs/_autoapi/**/*' --host
127127

128128
[tool.ruff]
129129
line-length = 100
130-
exclude = [
130+
force-exclude = true
131+
extend-exclude = [
131132
".bzr",
132133
".direnv",
133134
".eggs",
@@ -146,21 +147,6 @@ exclude = [
146147
"docs"
147148
]
148149

149-
[tool.black]
150-
line-length = 100
151-
exclude = '''
152-
/(
153-
\.git
154-
| \.mypy_cache
155-
| \.venv
156-
| _build
157-
| buck-out
158-
| build
159-
| dist
160-
| docs
161-
)/
162-
'''
163-
164150
[tool.mypy]
165151
python_version = "3.8"
166152
ignore_missing_imports = true

src/zarr/_storage/absstore.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(
8787
"https://{}.blob.core.windows.net/".format(account_name),
8888
container,
8989
credential=account_key,
90-
**blob_service_kwargs
90+
**blob_service_kwargs,
9191
)
9292

9393
self.client = client
@@ -240,7 +240,6 @@ def __setitem__(self, key, value):
240240
super().__setitem__(key, value)
241241

242242
def rmdir(self, path=None):
243-
244243
if not path:
245244
# Currently allowing clear to delete everything as in v2
246245

src/zarr/_storage/store.py

-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ def _rmdir_from_keys(store: StoreLike, path: Optional[str] = None) -> None:
629629

630630

631631
def _rmdir_from_keys_v3(store: StoreV3, path: str = "") -> None:
632-
633632
meta_dir = meta_root + path
634633
meta_dir = meta_dir.rstrip("/")
635634
_rmdir_from_keys(store, meta_dir)

src/zarr/_storage/v3.py

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def _get_files_and_dirs_from_path(store, path):
118118

119119

120120
class FSStoreV3(FSStore, StoreV3):
121-
122121
# FSStoreV3 doesn't use this (FSStore uses it within _normalize_key)
123122
_META_KEYS = ()
124123

src/zarr/attrs.py

-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Attributes(MutableMapping):
2626
"""
2727

2828
def __init__(self, store, key=".zattrs", read_only=False, cache=True, synchronizer=None):
29-
3029
self._version = getattr(store, "_store_version", 2)
3130
_Store = Store if self._version == 2 else StoreV3
3231
self.store = _Store._ensure_store(store)
@@ -73,7 +72,6 @@ def __getitem__(self, item):
7372
return self.asdict()[item]
7473

7574
def _write_op(self, f, *args, **kwargs):
76-
7775
# guard condition
7876
if self.read_only:
7977
raise PermissionError("attributes are read-only")
@@ -89,7 +87,6 @@ def __setitem__(self, item, value):
8987
self._write_op(self._setitem_nosync, item, value)
9088

9189
def _setitem_nosync(self, item, value):
92-
9390
# load existing data
9491
d = self._get_nosync()
9592

@@ -106,7 +103,6 @@ def __delitem__(self, item):
106103
self._write_op(self._delitem_nosync, item)
107104

108105
def _delitem_nosync(self, key):
109-
110106
# load existing data
111107
d = self._get_nosync()
112108

@@ -128,7 +124,6 @@ def put(self, d):
128124
self._write_op(self._put_nosync, dict(attributes=d))
129125

130126
def _put_nosync(self, d):
131-
132127
d_to_check = d if self._version == 2 else d["attributes"]
133128
if not all(isinstance(item, str) for item in d_to_check):
134129
# TODO: Raise an error for non-string keys
@@ -178,7 +173,6 @@ def update(self, *args, **kwargs):
178173
self._write_op(self._update_nosync, *args, **kwargs)
179174

180175
def _update_nosync(self, *args, **kwargs):
181-
182176
# load existing data
183177
d = self._get_nosync()
184178

src/zarr/convenience.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,8 @@ def copy_store(
675675

676676
# setup logging
677677
with _LogWriter(log) as log:
678-
679678
# iterate over source keys
680679
for source_key in sorted(source.keys()):
681-
682680
# filter to keys under source path
683681
if source_store_version == 2:
684682
if not source_key.startswith(source_path):
@@ -757,7 +755,7 @@ def copy(
757755
log=None,
758756
if_exists="raise",
759757
dry_run=False,
760-
**create_kws
758+
**create_kws,
761759
):
762760
"""Copy the `source` array or group into the `dest` group.
763761
@@ -878,7 +876,6 @@ def copy(
878876

879877
# setup logging
880878
with _LogWriter(log) as log:
881-
882879
# do the copying
883880
n_copied, n_skipped, n_bytes_copied = _copy(
884881
log,
@@ -890,7 +887,7 @@ def copy(
890887
without_attrs=without_attrs,
891888
if_exists=if_exists,
892889
dry_run=dry_run,
893-
**create_kws
890+
**create_kws,
894891
)
895892

896893
# log a final message with a summary of what happened
@@ -948,12 +945,10 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
948945

949946
# take action
950947
if do_copy:
951-
952948
# log a message about what we're going to do
953949
log("copy {} {} {}".format(source.name, source.shape, source.dtype))
954950

955951
if not dry_run:
956-
957952
# clear the way
958953
if exists:
959954
del dest[name]
@@ -1038,12 +1033,10 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10381033

10391034
# take action
10401035
if do_copy:
1041-
10421036
# log action
10431037
log("copy {}".format(source.name))
10441038

10451039
if not dry_run:
1046-
10471040
# clear the way
10481041
if exists_array:
10491042
del dest[name]
@@ -1056,7 +1049,6 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10561049
grp.attrs.update(source.attrs)
10571050

10581051
else:
1059-
10601052
# setup for dry run without creating any groups in the
10611053
# destination
10621054
if dest is not None:
@@ -1076,7 +1068,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10761068
without_attrs=without_attrs,
10771069
if_exists=if_exists,
10781070
dry_run=dry_run,
1079-
**create_kws
1071+
**create_kws,
10801072
)
10811073
n_copied += c
10821074
n_skipped += s
@@ -1099,7 +1091,7 @@ def copy_all(
10991091
log=None,
11001092
if_exists="raise",
11011093
dry_run=False,
1102-
**create_kws
1094+
**create_kws,
11031095
):
11041096
"""Copy all children of the `source` group into the `dest` group.
11051097
@@ -1189,7 +1181,6 @@ def copy_all(
11891181

11901182
# setup logging
11911183
with _LogWriter(log) as log:
1192-
11931184
for k in source.keys():
11941185
c, s, b = _copy(
11951186
log,
@@ -1201,7 +1192,7 @@ def copy_all(
12011192
without_attrs=without_attrs,
12021193
if_exists=if_exists,
12031194
dry_run=dry_run,
1204-
**create_kws
1195+
**create_kws,
12051196
)
12061197
n_copied += c
12071198
n_skipped += s
@@ -1262,7 +1253,6 @@ def is_zarr_key(key):
12621253
return key.endswith(".zarray") or key.endswith(".zgroup") or key.endswith(".zattrs")
12631254

12641255
else:
1265-
12661256
assert_zarr_v3_api_available()
12671257

12681258
sfx = _get_metadata_suffix(store) # type: ignore

src/zarr/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ def hexdigest(self, hashname="sha1"):
25362536
checksum = binascii.hexlify(self.digest(hashname=hashname))
25372537

25382538
# This is a bytes object on Python 3 and we want a str.
2539-
if type(checksum) is not str:
2539+
if not isinstance(checksum, str):
25402540
checksum = checksum.decode("utf8")
25412541

25422542
return checksum

src/zarr/creation.py

-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def create(
234234

235235

236236
def _kwargs_compat(compressor, fill_value, kwargs):
237-
238237
# to be compatible with h5py, as well as backwards-compatible with Zarr
239238
# 1.x, accept 'compression' and 'compression_opts' keyword arguments
240239

@@ -697,7 +696,6 @@ def open_array(
697696

698697

699698
def _like_args(a, kwargs):
700-
701699
shape, chunks = _get_shape_chunks(a)
702700
if shape is not None:
703701
kwargs.setdefault("shape", shape)

0 commit comments

Comments
 (0)