Skip to content

Commit

Permalink
cruft: update template (#61)
Browse files Browse the repository at this point in the history
* cruft: update template

* gha: temporarily disable tests on py3.12
  • Loading branch information
efiop authored Feb 3, 2024
1 parent 43f7022 commit 9fcb2d6
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/iterative/cookiecutter-dvc-plugin/",
"commit": "91159828cdce86290b97bf4985732651805523c4",
"commit": "da6f5faa767006bd66ed6164e9c573bc098cb346",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: 3.9
- name: Install
run: |
pip install --upgrade pip wheel
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
pyv: ["3.8", "3.9", "3.10", "3.11"]
# NOTE: 3.12 is temporarily disabled waiting for
# https://github.com/fsspec/universal_pathlib/pull/152
pyv: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
31 changes: 6 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repos:
language: fail
files: \.rej$
repo: local
- hooks:
- id: black
language_version: python3
repo: https://github.com/ambv/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.2.0'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
Expand All @@ -26,21 +27,6 @@ repos:
- ba,datas,fo,uptodate
repo: https://github.com/codespell-project/codespell
rev: v2.1.0
- hooks:
- id: isort
language_version: python3
repo: https://github.com/timothycrosley/isort
rev: 5.12.0
- hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
repo: https://github.com/pycqa/flake8
rev: 3.9.2
- repo: local
hooks:
- id: mypy
Expand All @@ -49,11 +35,6 @@ repos:
files: ^dvc_s3/
language: system
types: [python]
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
- hooks:
- args:
- -i
Expand Down
21 changes: 10 additions & 11 deletions dvc_s3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import threading
from collections import defaultdict
from typing import Any, Dict, Optional, Tuple
from typing import Any, ClassVar, Optional
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit

from funcy import first, wrap_prop

from dvc.utils.objects import cached_property
from dvc_objects.fs.base import ObjectFileSystem
from dvc_objects.fs.errors import ConfigError
from funcy import first, wrap_prop

_AWS_CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".aws", "config")

Expand Down Expand Up @@ -40,19 +41,19 @@ def human_readable_to_bytes(value: str) -> int:
# pylint:disable=abstract-method
class S3FileSystem(ObjectFileSystem):
protocol = "s3"
REQUIRES = {"s3fs": "s3fs", "boto3": "boto3"}
REQUIRES: ClassVar[dict[str, str]] = {"s3fs": "s3fs", "boto3": "boto3"}
PARAM_CHECKSUM = "etag"

VERSION_ID_KEY = "versionId"

_GRANTS = {
_GRANTS: ClassVar[dict[str, str]] = {
"grant_full_control": "GrantFullControl",
"grant_read": "GrantRead",
"grant_read_acp": "GrantReadACP",
"grant_write_acp": "GrantWriteACP",
}

_TRANSFER_CONFIG_ALIASES = {
_TRANSFER_CONFIG_ALIASES: ClassVar[dict[str, str]] = {
"max_queue_size": "max_io_queue",
"max_concurrent_requests": "max_concurrency",
"multipart_threshold": "multipart_threshold",
Expand All @@ -63,7 +64,7 @@ def getcwd(self):
return self.fs.root_marker

@classmethod
def split_version(cls, path: str) -> Tuple[str, Optional[str]]:
def split_version(cls, path: str) -> tuple[str, Optional[str]]:
parts = list(urlsplit(path))
query = parse_qs(parts[3])
if cls.VERSION_ID_KEY in query:
Expand Down Expand Up @@ -91,15 +92,15 @@ def version_path(cls, path: str, version_id: Optional[str]) -> str:
@classmethod
def coalesce_version(
cls, path: str, version_id: Optional[str]
) -> Tuple[str, Optional[str]]:
) -> tuple[str, Optional[str]]:
path, path_version_id = cls.split_version(path)
versions = {ver for ver in (version_id, path_version_id) if ver}
if len(versions) > 1:
raise ValueError("Path version mismatch: '{path}', '{version_id}'")
return path, (versions.pop() if versions else None)

@classmethod
def _get_kwargs_from_urls(cls, urlpath: str) -> Dict[str, Any]:
def _get_kwargs_from_urls(cls, urlpath: str) -> dict[str, Any]:
ret = super()._get_kwargs_from_urls(urlpath)
url_query = ret.get("url_query")
if url_query is not None:
Expand Down Expand Up @@ -210,9 +211,7 @@ def _prepare_credentials(self, **config):

# config kwargs
session_config = login_info["config_kwargs"]
session_config["s3"] = self._load_aws_config_file(
login_info["profile"]
)
session_config["s3"] = self._load_aws_config_file(login_info["profile"])

shared_creds = config.get("credentialpath")
if shared_creds:
Expand Down
4 changes: 0 additions & 4 deletions dvc_s3/tests/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# pylint: disable=unused-import
# noqa
from dvc.testing.benchmarks.cli.stories.use_cases.test_sharing import ( # noqa
test_sharing as test_sharing_s3,
)
5 changes: 3 additions & 2 deletions dvc_s3/tests/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os
import uuid

from funcy import cached_property

from dvc.testing.cloud import Cloud
from dvc.testing.path_info import CloudURLInfo
from funcy import cached_property


class S3(Cloud, CloudURLInfo):
Expand Down Expand Up @@ -58,7 +59,7 @@ def is_dir(self):
def exists(self):
return self.is_file() or self.is_dir()

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
def mkdir(self, mode=0o777, parents=False, exist_ok=False): # noqa: ARG002
assert mode == 0o777
assert parents

Expand Down
4 changes: 2 additions & 2 deletions dvc_s3/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from dvc.testing.fixtures import * # noqa, pylint: disable=wildcard-import,unused-import
from dvc.testing.fixtures import * # noqa: F403

from .fixtures import * # noqa, pylint: disable=wildcard-import,unused-import
from .fixtures import * # noqa: F403
14 changes: 7 additions & 7 deletions dvc_s3/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _make_s3():

@pytest.fixture
# pylint: disable-next=redefined-outer-name,unused-argument
def make_s3_version_aware(versioning, tmp_s3_path, s3_server):
def make_s3_version_aware(versioning, tmp_s3_path, s3_server): # noqa: ARG001
def _make_s3():
return FakeS3(str(tmp_s3_path).rstrip("/"), config=s3_server)

Expand All @@ -29,29 +29,29 @@ def _make_s3():

@pytest.fixture
def s3(make_s3): # pylint: disable=redefined-outer-name
yield make_s3()
return make_s3()


@pytest.fixture
def cloud(make_cloud):
yield make_cloud(typ="s3")
return make_cloud(typ="s3")


@pytest.fixture
def remote(make_remote):
yield make_remote(name="upstream", typ="s3")
return make_remote(name="upstream", typ="s3")


@pytest.fixture
def remote_version_aware(make_remote_version_aware):
yield make_remote_version_aware(name="upstream", typ="s3")
return make_remote_version_aware(name="upstream", typ="s3")


@pytest.fixture
def remote_worktree(make_remote_worktree):
yield make_remote_worktree(name="upstream", typ="s3")
return make_remote_worktree(name="upstream", typ="s3")


@pytest.fixture
def workspace(make_workspace):
yield make_workspace(name="workspace", typ="s3")
return make_workspace(name="workspace", typ="s3")
11 changes: 1 addition & 10 deletions dvc_s3/tests/test_dvc.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import pytest
from dvc.testing.api_tests import ( # noqa, pylint: disable=unused-import
TestAPI,
)
from dvc.testing.remote_tests import ( # noqa, pylint: disable=unused-import
TestRemote,
TestRemoteVersionAware,
)

from dvc.testing.workspace_tests import TestGetUrl as _TestGetUrl
from dvc.testing.workspace_tests import TestImport as _TestImport
from dvc.testing.workspace_tests import ( # noqa, pylint: disable=unused-import
TestImportURLVersionAware,
)
from dvc.testing.workspace_tests import TestLsUrl as _TestLsUrl
from dvc.testing.workspace_tests import TestToRemote as _TestToRemote

Expand Down
17 changes: 8 additions & 9 deletions dvc_s3/tests/test_s3.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os

import pytest
from dvc.fs import ConfigError

from dvc.fs import ConfigError
from dvc_s3 import S3FileSystem

bucket_name = "bucket-name"
prefix = "some/prefix"
url = f"s3://{bucket_name}/{prefix}"
key_id = "key-id"
key_secret = "key-secret"
session_token = "session-token"
key_secret = "key-secret" # noqa: S105
session_token = "session-token" # noqa: S105


@pytest.fixture(autouse=True, name="grants")
Expand Down Expand Up @@ -43,12 +43,12 @@ def test_s3_config_credentialpath(monkeypatch):
monkeypatch.setattr(os, "environ", environment)

config = {"url": url, "credentialpath": "somewhere"}
S3FileSystem(**config).fs_args # pylint: disable=W0106
S3FileSystem(**config).fs_args # noqa: B018
assert environment["AWS_SHARED_CREDENTIALS_FILE"] == "somewhere"
environment.clear()

config = {"url": url, "configpath": "somewhere"}
S3FileSystem(**config).fs_args # pylint: disable=W0106
S3FileSystem(**config).fs_args # noqa: B018
assert environment["AWS_CONFIG_FILE"] == "somewhere"
environment.clear()

Expand All @@ -57,7 +57,7 @@ def test_s3_config_credentialpath(monkeypatch):
"credentialpath": "somewhere",
"configpath": "elsewhere",
}
S3FileSystem(**config).fs_args # pylint: disable=W0106
S3FileSystem(**config).fs_args # noqa: B018
assert environment["AWS_SHARED_CREDENTIALS_FILE"] == "somewhere"
assert environment["AWS_CONFIG_FILE"] == "elsewhere"
environment.clear()
Expand Down Expand Up @@ -105,8 +105,7 @@ def test_grants():

extra_args = fs.fs_args["s3_additional_kwargs"]
assert (
extra_args["GrantRead"]
== "id=read-permission-id,id=other-read-permission-id"
extra_args["GrantRead"] == "id=read-permission-id,id=other-read-permission-id"
)
assert extra_args["GrantReadACP"] == "id=read-acp-permission-id"
assert extra_args["GrantWriteACP"] == "id=write-acp-permission-id"
Expand All @@ -119,7 +118,7 @@ def test_grants_mutually_exclusive_acl_error(grants):

fs = S3FileSystem(**config)
with pytest.raises(ConfigError):
fs.fs_args # pylint: disable=W0104
fs.fs_args # noqa: B018


def test_sse_kms_key_id():
Expand Down
2 changes: 1 addition & 1 deletion dvc_s3/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def test_conversions_human_readable_to_bytes(test_input, expected):

@pytest.mark.parametrize("invalid_input", ["foo", "10XB", "1000Pb", "fooMiB"])
def test_conversions_human_readable_to_bytes_invalid(invalid_input):
with pytest.raises(ValueError):
with pytest.raises(ValueError): # noqa: PT011
human_readable_to_bytes(invalid_input)
Loading

0 comments on commit 9fcb2d6

Please sign in to comment.