Skip to content

Commit 923d473

Browse files
committed
♻️ clean: remove unuse function in utils module.
1 parent 68ffb20 commit 923d473

2 files changed

Lines changed: 1 addition & 62 deletions

File tree

src/ddeutil/workflow/utils.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
"""Utility function model."""
77
from __future__ import annotations
88

9-
import asyncio
109
import stat
1110
import time
1211
from collections.abc import Iterator
1312
from datetime import date, datetime, timedelta
14-
from functools import wraps
1513
from hashlib import md5
1614
from inspect import isfunction
17-
from itertools import chain, islice, product
15+
from itertools import product
1816
from pathlib import Path
1917
from random import randrange
2018
from typing import Any, Final, Optional, TypeVar, Union, overload
@@ -258,34 +256,6 @@ def cross_product(matrix: Matrix) -> Iterator[DictData]:
258256
)
259257

260258

261-
def batch(iterable: Union[Iterator[Any], range], n: int) -> Iterator[Any]:
262-
"""Batch data into iterators of length n. The last batch may be shorter.
263-
264-
Example:
265-
>>> for b in batch(iter('ABCDEFG'), 3):
266-
... print(list(b))
267-
['A', 'B', 'C']
268-
['D', 'E', 'F']
269-
['G']
270-
271-
:param iterable:
272-
:param n: (int) A number of returning batch size.
273-
274-
:rtype: Iterator[Any]
275-
"""
276-
if n < 1:
277-
raise ValueError("n must be at least one")
278-
279-
it: Iterator[Any] = iter(iterable)
280-
while True:
281-
chunk_it = islice(it, n)
282-
try:
283-
first_el = next(chunk_it)
284-
except StopIteration:
285-
return
286-
yield chain((first_el,), chunk_it)
287-
288-
289259
def cut_id(run_id: str, *, num: int = 6) -> str:
290260
"""Cutting running ID with length.
291261
@@ -325,24 +295,3 @@ def dump_all(
325295
elif isinstance(value, BaseModel):
326296
return value.model_dump(by_alias=by_alias)
327297
return value
328-
329-
330-
def awaitable(func):
331-
"""Dynamic function to async or not depend on the called statement."""
332-
333-
@wraps(func)
334-
async def async_wrapper(*args, **kwargs):
335-
return func(*args, **kwargs)
336-
337-
@wraps(func)
338-
def sync_wrapper(*args, **kwargs):
339-
return func(*args, **kwargs)
340-
341-
def dispatch(*args, **kwargs):
342-
try:
343-
asyncio.get_running_loop()
344-
return async_wrapper(*args, **kwargs)
345-
except RuntimeError:
346-
return sync_wrapper(*args, **kwargs)
347-
348-
return dispatch

tests/test_utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77
from ddeutil.workflow.utils import (
88
UTC,
9-
batch,
109
cut_id,
1110
dump_all,
1211
filter_func,
@@ -91,15 +90,6 @@ def test_filter_func():
9190
}
9291

9392

94-
def test_batch():
95-
with pytest.raises(ValueError):
96-
next(batch(range(10), n=-1))
97-
98-
assert [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] == [
99-
list(i) for i in batch(range(10), n=2)
100-
]
101-
102-
10393
def test_make_exec():
10494
test_file: str = "./tmp_test_make_exec.txt"
10595

0 commit comments

Comments
 (0)