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

black -> ruff format + cleanup #1639

Merged
merged 6 commits into from
Apr 8, 2024
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: 0 additions & 2 deletions .flake8

This file was deleted.

2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# lint codebase with black and ruff
4e348d6b80c96da461fd866576c971b8a659ba15
# migrate from black to ruff format
22cea005629913208a85799372e045f353744add
17 changes: 6 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.224'
rev: 'v0.2.1'
hooks:
- id: ruff
# Respect `exclude` and `extend-exclude` settings.
args: ["--force-exclude"]
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
args: ["-L", "ba,ihs,kake,nd,noe,nwo,te,fo,zar", "-S", "fixture"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.8.0
hooks:
- id: mypy
files: src
Expand Down
1 change: 0 additions & 1 deletion bench/compress_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from zarr import blosc

if __name__ == "__main__":

sys.path.insert(0, "..")

# setup
Expand Down
18 changes: 2 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ serve = "sphinx-autobuild docs docs/_build --ignore 'docs/_autoapi/**/*' --host

[tool.ruff]
line-length = 100
exclude = [
force-exclude = true
extend-exclude = [
".bzr",
".direnv",
".eggs",
Expand All @@ -146,21 +147,6 @@ exclude = [
"docs"
]

[tool.black]
line-length = 100
exclude = '''
/(
\.git
| \.mypy_cache
| \.venv
| _build
| buck-out
| build
| dist
| docs
)/
'''

[tool.mypy]
python_version = "3.8"
ignore_missing_imports = true
Expand Down
3 changes: 1 addition & 2 deletions src/zarr/_storage/absstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
"https://{}.blob.core.windows.net/".format(account_name),
container,
credential=account_key,
**blob_service_kwargs
**blob_service_kwargs,
)

self.client = client
Expand Down Expand Up @@ -240,7 +240,6 @@ def __setitem__(self, key, value):
super().__setitem__(key, value)

def rmdir(self, path=None):

if not path:
# Currently allowing clear to delete everything as in v2

Expand Down
1 change: 0 additions & 1 deletion src/zarr/_storage/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ def _rmdir_from_keys(store: StoreLike, path: Optional[str] = None) -> None:


def _rmdir_from_keys_v3(store: StoreV3, path: str = "") -> None:

meta_dir = meta_root + path
meta_dir = meta_dir.rstrip("/")
_rmdir_from_keys(store, meta_dir)
Expand Down
1 change: 0 additions & 1 deletion src/zarr/_storage/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def _get_files_and_dirs_from_path(store, path):


class FSStoreV3(FSStore, StoreV3):

# FSStoreV3 doesn't use this (FSStore uses it within _normalize_key)
_META_KEYS = ()

Expand Down
6 changes: 0 additions & 6 deletions src/zarr/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Attributes(MutableMapping):
"""

def __init__(self, store, key=".zattrs", read_only=False, cache=True, synchronizer=None):

self._version = getattr(store, "_store_version", 2)
_Store = Store if self._version == 2 else StoreV3
self.store = _Store._ensure_store(store)
Expand Down Expand Up @@ -73,7 +72,6 @@ def __getitem__(self, item):
return self.asdict()[item]

def _write_op(self, f, *args, **kwargs):

# guard condition
if self.read_only:
raise PermissionError("attributes are read-only")
Expand All @@ -89,7 +87,6 @@ def __setitem__(self, item, value):
self._write_op(self._setitem_nosync, item, value)

def _setitem_nosync(self, item, value):

# load existing data
d = self._get_nosync()

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

def _delitem_nosync(self, key):

# load existing data
d = self._get_nosync()

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

def _put_nosync(self, d):

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

def _update_nosync(self, *args, **kwargs):

# load existing data
d = self._get_nosync()

Expand Down
20 changes: 5 additions & 15 deletions src/zarr/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,8 @@ def copy_store(

# setup logging
with _LogWriter(log) as log:

# iterate over source keys
for source_key in sorted(source.keys()):

# filter to keys under source path
if source_store_version == 2:
if not source_key.startswith(source_path):
Expand Down Expand Up @@ -757,7 +755,7 @@ def copy(
log=None,
if_exists="raise",
dry_run=False,
**create_kws
**create_kws,
):
"""Copy the `source` array or group into the `dest` group.

Expand Down Expand Up @@ -878,7 +876,6 @@ def copy(

# setup logging
with _LogWriter(log) as log:

# do the copying
n_copied, n_skipped, n_bytes_copied = _copy(
log,
Expand All @@ -890,7 +887,7 @@ def copy(
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)

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

# take action
if do_copy:

# log a message about what we're going to do
log("copy {} {} {}".format(source.name, source.shape, source.dtype))

if not dry_run:

# clear the way
if exists:
del dest[name]
Expand Down Expand Up @@ -1038,12 +1033,10 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_

# take action
if do_copy:

# log action
log("copy {}".format(source.name))

if not dry_run:

# clear the way
if exists_array:
del dest[name]
Expand All @@ -1056,7 +1049,6 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
grp.attrs.update(source.attrs)

else:

# setup for dry run without creating any groups in the
# destination
if dest is not None:
Expand All @@ -1076,7 +1068,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)
n_copied += c
n_skipped += s
Expand All @@ -1099,7 +1091,7 @@ def copy_all(
log=None,
if_exists="raise",
dry_run=False,
**create_kws
**create_kws,
):
"""Copy all children of the `source` group into the `dest` group.

Expand Down Expand Up @@ -1189,7 +1181,6 @@ def copy_all(

# setup logging
with _LogWriter(log) as log:

for k in source.keys():
c, s, b = _copy(
log,
Expand All @@ -1201,7 +1192,7 @@ def copy_all(
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)
n_copied += c
n_skipped += s
Expand Down Expand Up @@ -1262,7 +1253,6 @@ def is_zarr_key(key):
return key.endswith(".zarray") or key.endswith(".zgroup") or key.endswith(".zattrs")

else:

assert_zarr_v3_api_available()

sfx = _get_metadata_suffix(store) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,7 @@ def hexdigest(self, hashname="sha1"):
checksum = binascii.hexlify(self.digest(hashname=hashname))

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

return checksum
Expand Down
2 changes: 0 additions & 2 deletions src/zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def create(


def _kwargs_compat(compressor, fill_value, kwargs):

# to be compatible with h5py, as well as backwards-compatible with Zarr
# 1.x, accept 'compression' and 'compression_opts' keyword arguments

Expand Down Expand Up @@ -697,7 +696,6 @@ def open_array(


def _like_args(a, kwargs):

shape, chunks = _get_shape_chunks(a)
if shape is not None:
kwargs.setdefault("shape", shape)
Expand Down
Loading
Loading