Skip to content

Commit

Permalink
drop python 3.8 (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop authored Feb 20, 2024
1 parent 82ba22d commit d89a3f2
Show file tree
Hide file tree
Showing 32 changed files with 146 additions and 151 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
pyv: ['3.8', '3.9', '3.10', '3.11', '3.12']
pyv: ['3.9', '3.10', '3.11', '3.12']
include:
- {os: ubuntu-latest, pyv: 'pypy3.8'}
- {os: ubuntu-latest, pyv: 'pypy3.9'}
- {os: macos-14, pyv: '3.11'}

steps:
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ license = {text = "Apache-2.0"}
authors = [{ name = "Iterative", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 4 - Beta",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dynamic = ["version"]
dependencies = [
"funcy>=1.14",
Expand Down
6 changes: 3 additions & 3 deletions src/dvc_data/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import sys
from threading import RLock
from typing import Any, BinaryIO, ClassVar, Dict, Optional, Type, Union
from typing import Any, BinaryIO, ClassVar, Optional, Union

import fsspec
from tqdm import tqdm
Expand Down Expand Up @@ -39,7 +39,7 @@ class Tqdm(tqdm):
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
)
BAR_FMT_NOTOTAL = "{desc}{bar:b}|{postfix[info]}{n_fmt} [{elapsed}, {rate_fmt:>11}]"
BYTES_DEFAULTS: ClassVar[Dict[str, Any]] = {
BYTES_DEFAULTS: ClassVar[dict[str, Any]] = {
"unit": "B",
"unit_scale": True,
"unit_divisor": 1024,
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(
size: Optional[int] = None,
value: int = 0,
progress_bar: Optional["tqdm"] = None,
tqdm_cls: Optional[Type["tqdm"]] = None,
tqdm_cls: Optional[type["tqdm"]] = None,
**tqdm_kwargs,
):
tqdm_kwargs.pop("total", None)
Expand Down
3 changes: 1 addition & 2 deletions src/dvc_data/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from itertools import accumulate
from pathlib import Path
from posixpath import relpath
from typing import List

import click
import typer
Expand Down Expand Up @@ -580,7 +579,7 @@ def checkout(
path: Path = typer.Argument(..., resolve_path=True),
relink: bool = False,
force: bool = False,
type: List[LinkEnum] = typer.Option(["copy"]), # noqa: A002
type: list[LinkEnum] = typer.Option(["copy"]), # noqa: A002
):
odb = get_odb(type=[t.value for t in type])
oid = from_shortoid(odb, oid)
Expand Down
10 changes: 5 additions & 5 deletions src/dvc_data/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import posixpath
import typing
from collections import deque
from typing import Any, BinaryIO, NamedTuple, Optional, Tuple
from typing import Any, BinaryIO, NamedTuple, Optional

from fsspec import AbstractFileSystem
from fsspec.callbacks import DEFAULT_CALLBACK
Expand Down Expand Up @@ -43,7 +43,7 @@ def join(cls, *parts: str) -> str:
return posixpath.join(*parts)

@classmethod
def parts(cls, path: str) -> Tuple[str, ...]:
def parts(cls, path: str) -> tuple[str, ...]:
ret = []
while True:
path, part = posixpath.split(path)
Expand Down Expand Up @@ -77,10 +77,10 @@ def relpath(self, path: str, start: Optional[str] = None) -> str:
start = "."
return posixpath.relpath(self.abspath(path), start=self.abspath(start))

def relparts(self, path: str, start: Optional[str] = None) -> Tuple[str, ...]:
def relparts(self, path: str, start: Optional[str] = None) -> tuple[str, ...]:
return self.parts(self.relpath(path, start=start))

def _get_key(self, path: str) -> Tuple[str, ...]:
def _get_key(self, path: str) -> tuple[str, ...]:
path = self.abspath(path)
if path == self.root_marker:
return ()
Expand Down Expand Up @@ -125,7 +125,7 @@ def _cache_remote_file(
fs: "FileSystem",
path: "AnyFSPath",
hash_info: Optional["HashInfo"],
) -> Tuple["FileSystem", "AnyFSPath"]:
) -> tuple["FileSystem", "AnyFSPath"]:
from dvc_objects.fs.local import LocalFileSystem

odb: "HashFileDB" = cache_storage.odb
Expand Down
3 changes: 2 additions & 1 deletion src/dvc_data/hashfile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""DVC data."""
import logging
from typing import TYPE_CHECKING, Iterator, Union, cast
from collections.abc import Iterator
from typing import TYPE_CHECKING, Union, cast

from .tree import Tree

Expand Down
3 changes: 2 additions & 1 deletion src/dvc_data/hashfile/_ignore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Any, Iterator
from collections.abc import Iterator
from typing import TYPE_CHECKING, Any

from typing_extensions import Protocol

Expand Down
10 changes: 5 additions & 5 deletions src/dvc_data/hashfile/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hashlib
import logging
import os
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, cast
from typing import TYPE_CHECKING, Any, Optional, cast

from fsspec.callbacks import DEFAULT_CALLBACK, Callback

Expand Down Expand Up @@ -45,7 +45,7 @@ def _upload_file(
odb: "HashFileDB",
upload_odb: "HashFileDB",
callback: Optional[Callback] = None,
) -> Tuple[Meta, HashFile]:
) -> tuple[Meta, HashFile]:
from dvc_objects.fs.utils import tmp_fname

from .hash import HashStreamFile
Expand Down Expand Up @@ -131,7 +131,7 @@ def _build_tree(

# NOTE: we know for sure that root starts with path, so we can use
# faster string manipulation instead of a more robust relparts()
rel_key: Tuple[Optional[Any], ...] = ()
rel_key: tuple[Optional[Any], ...] = ()
if root != path:
rel_key = tuple(root[len(path) + 1 :].split(fs.sep))

Expand Down Expand Up @@ -160,7 +160,7 @@ def _build_tree(
return tree_meta, tree


_url_cache: Dict[str, str] = {}
_url_cache: dict[str, str] = {}


def _make_staging_url(fs: "FileSystem", odb: "HashFileDB", path: Optional[str]):
Expand Down Expand Up @@ -232,7 +232,7 @@ def build(
upload: bool = False,
dry_run: bool = False,
**kwargs,
) -> Tuple["HashFileDB", "Meta", "HashFile"]:
) -> tuple["HashFileDB", "Meta", "HashFile"]:
"""Stage (prepare) objects from the given path for addition to an ODB.
Returns at tuple of (object_store, object) where addition to the ODB can
Expand Down
4 changes: 2 additions & 2 deletions src/dvc_data/hashfile/checkout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from itertools import chain
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional

from dvc_objects.fs.generic import test_links, transfer
from fsspec.callbacks import DEFAULT_CALLBACK
Expand All @@ -24,7 +24,7 @@ def __init__(self, path: str) -> None:


class CheckoutError(Exception):
def __init__(self, paths: List[str]) -> None:
def __init__(self, paths: list[str]) -> None:
self.paths = paths
super().__init__("Checkout failed")

Expand Down
8 changes: 4 additions & 4 deletions src/dvc_data/hashfile/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from contextlib import suppress
from copy import copy
from typing import TYPE_CHECKING, Callable, ClassVar, List, Optional, Union
from typing import TYPE_CHECKING, Callable, ClassVar, Optional, Union

from dvc_objects.db import ObjectDB
from dvc_objects.errors import ObjectFormatError
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_index(odb) -> "ObjectDBIndexBase":

class HashFileDB(ObjectDB):
DEFAULT_VERIFY = False
DEFAULT_CACHE_TYPES: ClassVar[List[str]] = ["copy"]
DEFAULT_CACHE_TYPES: ClassVar[list[str]] = ["copy"]
CACHE_MODE: Optional[int] = None

def __init__(self, fs: "FileSystem", path: str, read_only: bool = False, **config):
Expand All @@ -72,9 +72,9 @@ def get(self, oid: str) -> HashFile:

def add(
self,
path: Union["AnyFSPath", List["AnyFSPath"]],
path: Union["AnyFSPath", list["AnyFSPath"]],
fs: "FileSystem",
oid: Union[str, List[str]],
oid: Union[str, list[str]],
hardlink: bool = False,
callback: "Callback" = DEFAULT_CALLBACK,
check_exists: bool = True,
Expand Down
9 changes: 5 additions & 4 deletions src/dvc_data/hashfile/db/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Iterable, Iterator, Set
from collections.abc import Iterable, Iterator
from typing import TYPE_CHECKING

from dvc_objects.errors import ObjectDBError

Expand Down Expand Up @@ -44,7 +45,7 @@ def update(self, dir_hashes: Iterable[str], file_hashes: Iterable[str]) -> None:
pass

@abstractmethod
def intersection(self, hashes: Set[str]) -> Iterator[str]:
def intersection(self, hashes: set[str]) -> Iterator[str]:
pass


Expand Down Expand Up @@ -73,7 +74,7 @@ def clear(self) -> None:
def update(self, dir_hashes: Iterable[str], file_hashes: Iterable[str]) -> None:
pass

def intersection(self, hashes: Set[str]) -> Iterator[str]:
def intersection(self, hashes: set[str]) -> Iterator[str]:
yield from []


Expand Down Expand Up @@ -131,6 +132,6 @@ def update(self, dir_hashes: Iterable[str], file_hashes: Iterable[str]) -> None:
except Timeout as exc:
raise ObjectDBError("Failed to update ODB index") from exc

def intersection(self, hashes: Set[str]) -> Iterator[str]:
def intersection(self, hashes: set[str]) -> Iterator[str]:
"""Iterate over values from `hashes` which exist in the index."""
yield from hashes.intersection(self.index.keys())
4 changes: 2 additions & 2 deletions src/dvc_data/hashfile/db/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import stat
from functools import partial
from typing import ClassVar, List
from typing import ClassVar

from dvc_objects.db import noop, wrap_iter
from dvc_objects.errors import ObjectDBError, ObjectFormatError
Expand All @@ -19,7 +19,7 @@


class LocalHashFileDB(HashFileDB):
DEFAULT_CACHE_TYPES: ClassVar[List[str]] = ["reflink", "copy"]
DEFAULT_CACHE_TYPES: ClassVar[list[str]] = ["reflink", "copy"]
CACHE_MODE = 0o444
UNPACKED_DIR_SUFFIX = ".unpacked"

Expand Down
10 changes: 5 additions & 5 deletions src/dvc_data/hashfile/db/migrate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import partial, wraps
from typing import TYPE_CHECKING, Any, Callable, Dict, List, NamedTuple, Tuple
from typing import TYPE_CHECKING, Any, Callable, NamedTuple

from dvc_objects.executors import ThreadPoolExecutor
from fsspec.callbacks import DEFAULT_CALLBACK
Expand All @@ -14,8 +14,8 @@
class PreparedMigration(NamedTuple):
src: "HashFileDB"
dest: "HashFileDB"
paths: List[str]
oids: List[str]
paths: list[str]
oids: list[str]


def migrate(
Expand Down Expand Up @@ -65,7 +65,7 @@ def _hash_task(
path: str,
callback: "Callback" = DEFAULT_CALLBACK,
**kwargs,
) -> Tuple[str, str]:
) -> tuple[str, str]:
from dvc_data.hashfile.hash import hash_file

func = _wrap_hash_file(callback, hash_file)
Expand All @@ -79,7 +79,7 @@ def _hash_task(
def _wrap_hash_file(callback: "Callback", fn: Callable):
@wraps(fn)
def func(path: str, *args, **kwargs):
kw: Dict[str, Any] = dict(kwargs)
kw: dict[str, Any] = dict(kwargs)
with callback.branched(path, path) as child:
res = fn(path, *args, callback=child, **kw)
callback.relative_update()
Expand Down
8 changes: 4 additions & 4 deletions src/dvc_data/hashfile/db/reference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Callable, Optional, Union

from dvc_data.hashfile.obj import HashFile

Expand All @@ -15,7 +15,7 @@
class ReferenceHashFileDB(HashFileDB):
def __init__(self, fs: "FileSystem", path: str, **config):
super().__init__(fs, path, **config)
self._obj_cache: Dict["str", "HashFile"] = {}
self._obj_cache: dict["str", "HashFile"] = {}

def __hash__(self):
return hash((self.fs.protocol, self.path, *self._obj_cache.keys()))
Expand All @@ -31,9 +31,9 @@ def get(self, oid: str):

def add(
self,
path: Union["AnyFSPath", List["AnyFSPath"]],
path: Union["AnyFSPath", list["AnyFSPath"]],
fs: "FileSystem",
oid: Union[str, List[str]],
oid: Union[str, list[str]],
hardlink: bool = False,
callback: Optional["Callback"] = None,
check_exists: bool = True,
Expand Down
14 changes: 7 additions & 7 deletions src/dvc_data/hashfile/diff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import reprlib
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
from typing import TYPE_CHECKING, Optional

from attrs import asdict, define, field

Expand All @@ -19,7 +19,7 @@
@define(hash=True, order=True)
class TreeEntry:
in_cache: bool = field(default=False, eq=False)
key: Tuple[str, ...] = ()
key: tuple[str, ...] = ()
meta: Optional["Meta"] = field(default=None, eq=False)
oid: Optional["HashInfo"] = None

Expand Down Expand Up @@ -55,16 +55,16 @@ def __bool__(self):

@define
class DiffResult:
added: List[Change] = field(factory=list, repr=reprlib.repr)
modified: List[Change] = field(factory=list, repr=reprlib.repr)
deleted: List[Change] = field(factory=list, repr=reprlib.repr)
unchanged: List[Change] = field(factory=list, repr=reprlib.repr)
added: list[Change] = field(factory=list, repr=reprlib.repr)
modified: list[Change] = field(factory=list, repr=reprlib.repr)
deleted: list[Change] = field(factory=list, repr=reprlib.repr)
unchanged: list[Change] = field(factory=list, repr=reprlib.repr)

def __bool__(self):
return bool(self.added or self.modified or self.deleted)

@property
def stats(self) -> Dict[str, int]:
def stats(self) -> dict[str, int]:
return {k: len(v) for k, v in asdict(self).items() if k != "unchanged"}


Expand Down
3 changes: 2 additions & 1 deletion src/dvc_data/hashfile/gc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING, Iterable, Optional
from collections.abc import Iterable
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from .db import HashFileDB
Expand Down
Loading

0 comments on commit d89a3f2

Please sign in to comment.