Skip to content

Commit 2448fd1

Browse files
authoredFeb 28, 2024··
remove 3.8 compat for executors; update ruff and cleanup (#283)
1 parent 2039bd7 commit 2448fd1

File tree

6 files changed

+18
-64
lines changed

6 files changed

+18
-64
lines changed
 

‎.pre-commit-config.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: sort-simple-yaml
2121
- id: trailing-whitespace
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: 'v0.1.7'
23+
rev: 'v0.2.2'
2424
hooks:
2525
- id: ruff
2626
args: [--fix, --exit-non-zero-on-fix]
@@ -30,8 +30,3 @@ repos:
3030
hooks:
3131
- id: codespell
3232
additional_dependencies: ["tomli"]
33-
- repo: https://github.com/asottile/pyupgrade
34-
rev: v3.15.0
35-
hooks:
36-
- id: pyupgrade
37-
args: [--py38-plus]

‎pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ module = [
103103
ignore-words-list = "cachable,"
104104

105105
[tool.ruff]
106+
output-format = "full"
107+
show-fixes = true
108+
109+
[tool.ruff.lint]
106110
ignore = [
107111
"ISC001", # single-line-implicit-string-concatenation
108112
"PLR2004", # magic-value-comparison
@@ -155,8 +159,6 @@ select = [
155159
"W", # pycodestyle - Warning
156160
"YTT", # flake8-2020
157161
]
158-
show-source = true
159-
show-fixes = true
160162

161163
[tool.ruff.lint.flake8-pytest-style]
162164
fixture-parentheses = false

‎src/dvc_objects/db.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,11 @@ def _oids_with_limit(
259259
prefixes: Optional[Iterable[str]] = None,
260260
jobs: Optional[int] = None,
261261
) -> Iterator[str]:
262-
count = 0
263-
for oid in self._list_oids(prefixes=prefixes, jobs=jobs):
262+
for i, oid in enumerate(self._list_oids(prefixes=prefixes, jobs=jobs), start=1):
264263
yield oid
265-
count += 1
266-
if count > limit:
264+
if i > limit:
267265
logger.debug(
268-
"`_list_oids()` returned max %r oids, "
269-
"skipping remaining results",
266+
"`_list_oids()` returned max %r oids, skipping remaining results",
270267
limit,
271268
)
272269
return
@@ -348,7 +345,7 @@ def _list_oids_traverse(self, remote_size, remote_oids, jobs=None):
348345

349346
yield from self._list_oids(prefixes=traverse_prefixes, jobs=jobs)
350347

351-
def all(self, jobs=None): # noqa: A003
348+
def all(self, jobs=None):
352349
"""Iterate over all oids in this fs.
353350
354351
Hashes will be fetched in parallel threads according to prefix

‎src/dvc_objects/executors.py

+5-45
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,47 @@
11
import asyncio
2-
import queue
3-
import sys
42
from collections.abc import Coroutine, Iterable, Iterator, Sequence
53
from concurrent import futures
64
from itertools import islice
7-
from typing import (
8-
Any,
9-
Callable,
10-
Optional,
11-
TypeVar,
12-
)
5+
from typing import Any, Callable, Optional, TypeVar
136

147
from fsspec import Callback
158

169
_T = TypeVar("_T")
1710

1811

1912
class ThreadPoolExecutor(futures.ThreadPoolExecutor):
20-
_max_workers: int
21-
2213
def __init__(
2314
self, max_workers: Optional[int] = None, cancel_on_error: bool = False, **kwargs
2415
):
2516
super().__init__(max_workers=max_workers, **kwargs)
2617
self._cancel_on_error = cancel_on_error
2718

28-
@property
29-
def max_workers(self) -> int:
30-
return self._max_workers
31-
3219
def imap_unordered(
3320
self, fn: Callable[..., _T], *iterables: Iterable[Any]
3421
) -> Iterator[_T]:
3522
"""Lazier version of map that does not preserve ordering of results.
3623
3724
It does not create all the futures at once to reduce memory usage.
3825
"""
39-
4026
it = zip(*iterables)
41-
if self.max_workers == 1:
27+
if self._max_workers == 1:
4228
for args in it:
4329
yield fn(*args)
4430
return
4531

4632
def create_taskset(n: int) -> set[futures.Future]:
4733
return {self.submit(fn, *args) for args in islice(it, n)}
4834

49-
tasks = create_taskset(self.max_workers * 5)
35+
tasks = create_taskset(self._max_workers * 5)
5036
while tasks:
5137
done, tasks = futures.wait(tasks, return_when=futures.FIRST_COMPLETED)
5238
for fut in done:
5339
yield fut.result()
5440
tasks.update(create_taskset(len(done)))
5541

56-
def shutdown(self, wait=True, *, cancel_futures=False):
57-
if sys.version_info > (3, 9):
58-
return super().shutdown(wait=wait, cancel_futures=cancel_futures)
59-
else: # noqa: RET505
60-
with self._shutdown_lock:
61-
self._shutdown = True
62-
if cancel_futures:
63-
# Drain all work items from the queue, and then cancel their
64-
# associated futures.
65-
while True:
66-
try:
67-
work_item = self._work_queue.get_nowait()
68-
except queue.Empty:
69-
break
70-
if work_item is not None:
71-
work_item.future.cancel()
72-
73-
# Send a wake-up to prevent threads calling
74-
# _work_queue.get(block=True) from permanently blocking.
75-
self._work_queue.put(None) # type: ignore[arg-type]
76-
if wait:
77-
for t in self._threads:
78-
t.join()
79-
8042
def __exit__(self, exc_type, exc_val, exc_tb):
81-
if self._cancel_on_error:
82-
self.shutdown(wait=True, cancel_futures=exc_val is not None)
83-
else:
84-
self.shutdown(wait=True)
43+
cancel_futures = self._cancel_on_error and exc_val is not None
44+
self.shutdown(wait=True, cancel_futures=cancel_futures)
8545
return False
8646

8747

‎src/dvc_objects/fs/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def is_empty(self, path: AnyFSPath) -> bool:
296296
return entry["size"] == 0
297297

298298
@overload
299-
def open( # noqa: A003
299+
def open(
300300
self,
301301
path: AnyFSPath,
302302
mode: Literal["rb", "br", "wb"],
@@ -305,15 +305,15 @@ def open( # noqa: A003
305305
return self.open(path, mode, **kwargs)
306306

307307
@overload
308-
def open( # noqa: A003
308+
def open(
309309
self,
310310
path: AnyFSPath,
311311
mode: Literal["r", "rt", "w"] = "r",
312312
**kwargs: Any,
313313
) -> "TextIO":
314314
...
315315

316-
def open( # noqa: A003
316+
def open(
317317
self,
318318
path: AnyFSPath,
319319
mode: str = "r",

‎src/dvc_objects/fs/local.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def copy(self, path1, path2, recursive=False, on_error=None, **kwargs):
127127
self.rm_file(tmp_info)
128128
raise
129129

130-
def open(self, path, mode="r", encoding=None, **kwargs): # noqa: A003
130+
def open(self, path, mode="r", encoding=None, **kwargs):
131131
return open(path, mode=mode, encoding=encoding) # noqa: SIM115
132132

133133
def symlink(self, path1, path2):

0 commit comments

Comments
 (0)
Please sign in to comment.