Skip to content

Commit

Permalink
Merge pull request #3 from youtype/ruff
Browse files Browse the repository at this point in the history
Apply ruff rules
  • Loading branch information
vemel authored Nov 26, 2024
2 parents bd21701 + cbc6c40 commit 5662140
Show file tree
Hide file tree
Showing 21 changed files with 367 additions and 281 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ jobs:
- "3.13"
- "3.14"
include:
- version: "3.8"
check-consistency: "true"
- version: "3.9"
check-consistency: "true"
- version: "3.10"
check-consistency: "true"
- version: "3.11"
check-consistency: "true"
- version: "3.12"
check-consistency: "true"
- version: "3.13"
check-consistency: "true"
steps:
Expand All @@ -40,6 +50,15 @@ jobs:
uv sync --all-extras --dev
- name: Run pre-commit
run: uvx pre-commit run --all-files
- name: Check types in test.py
run: |
uv build --wheel
OUTPUT=`uvx --python=3.8 --with dist/*.whl mypy test.py || true`
echo $OUTPUT
if [[ ${OUTPUT} != *"Found 1 error"* ]];then
echo "Stubs test failed: $TEST"
exit 1
fi
- name: Stubs consistency check
if: ${{ matrix.check-consistency }}
run: |
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"ruff.nativeServer": "on",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
s3transfer-stubs/py.typed
s3transfer-stubs/*.pyi
include s3transfer-stubs/py.typed
include s3transfer-stubs/*.pyi
41 changes: 27 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ packages = ["s3transfer-stubs"]
[tool.pyright]
include = ["s3transfer-stubs"]
exclude = ["**/__pycache__", "tests", "typestubs"]
ignore = ["test.py"]
reportMissingImports = "error"
reportMissingTypeStubs = false
reportMissingTypeArgument = "error"
Expand Down Expand Up @@ -96,25 +97,32 @@ indent-width = 4
target-version = "py38"

[tool.ruff.lint]
preview = true
select = [
"E4",
"E7",
"E9",
"F",
"B",
"I",
"N",
"D",
"C4",
"C90",
"RUF",
"PYI",
"UP",
"E", # pycodestyle
"F", # pyflakes
"B", # flake8-bugbear
"I", # isort
"N", # pep8-naming
"C4", # flake8-comprehensions
"C90", # mccabe
"RUF", # ruff
"PYI", # flake8-pyi
"UP", # pyupgrade
"CPY", # flake8-copyright
]
fixable = ["ALL"]
unfixable = ["B"]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
exclude = ["test_*.py", "*.pyi"]
exclude = ["test_*.py"]
ignore = [
"N803", # invalid-argument-name
"N818", # exception-name
"PYI010", # non-empty-stub-body
"PYI019", # custom-type-var-return-type
"PYI021", # docstring-in-stub
"PYI048", # stub-body-multiple-statements
]

[tool.ruff.format]
quote-style = "double"
Expand All @@ -123,3 +131,8 @@ skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = false
docstring-code-line-length = "dynamic"

[tool.ruff.lint.flake8-copyright]
# author = "Vlad Emelianov"
min-file-size = 200
notice-rgx = "(?i)Copyright [0-9]{4}"
46 changes: 25 additions & 21 deletions s3transfer-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""
Copyright 2024 Vlad Emelianov
"""

import logging
from queue import Queue
from typing import IO, Any, Callable, Dict, Iterator, List, Mapping, Optional, Type, TypeVar, Union
from typing import IO, Any, Callable, Iterator, Mapping, TypeVar

from botocore.awsrequest import AWSRequest
from botocore.client import BaseClient
Expand All @@ -26,35 +30,35 @@ class QueueShutdownError(Exception): ...
class ReadFileChunk:
def __init__(
self,
fileobj: Union[IO[Any], str, bytes],
fileobj: IO[Any] | str | bytes,
start_byte: int,
chunk_size: int,
full_file_size: int,
callback: Optional[Callable[..., Any]] = ...,
callback: Callable[..., Any] | None = ...,
enable_callback: bool = ...,
) -> None: ...
@classmethod
def from_filename(
cls: Type[_R],
cls: type[_R],
filename: str,
start_byte: int,
chunk_size: int,
callback: Optional[Callable[..., Any]] = ...,
callback: Callable[..., Any] | None = ...,
enable_callback: bool = ...,
) -> _R: ...
def read(self, amount: Optional[int] = ...) -> str: ...
def read(self, amount: int | None = ...) -> str: ...
def enable_callback(self) -> None: ...
def disable_callback(self) -> None: ...
def seek(self, where: int) -> None: ...
def close(self) -> None: ...
def tell(self) -> int: ...
def __len__(self) -> int: ...
def __enter__(self: _R) -> _R: ...
def __exit__(self, *args: Any, **kwargs: Any) -> None: ...
def __exit__(self, *args: object, **kwargs: Any) -> None: ...
def __iter__(self) -> Iterator[str]: ...

class StreamReaderProgress:
def __init__(self, stream: Any, callback: Optional[Callable[..., Any]] = ...) -> None: ...
def __init__(self, stream: Any, callback: Callable[..., Any] | None = ...) -> None: ...
def read(self, *args: Any, **kwargs: Any) -> str: ...

class OSUtils:
Expand All @@ -67,13 +71,13 @@ class OSUtils:
def rename_file(self, current_filename: str, new_filename: str) -> None: ...

class MultipartUploader:
UPLOAD_PART_ARGS: List[str]
UPLOAD_PART_ARGS: list[str]
def __init__(
self,
client: BaseClient,
config: TransferConfig,
osutil: OSUtils,
executor_cls: Type[BaseExecutor] = ...,
executor_cls: type[BaseExecutor] = ...,
) -> None: ...
def upload_file(
self,
Expand All @@ -95,16 +99,16 @@ class MultipartDownloader:
client: BaseClient,
config: TransferConfig,
osutil: OSUtils,
executor_cls: Type[BaseExecutor] = ...,
executor_cls: type[BaseExecutor] = ...,
) -> None: ...
def download_file(
self,
bucket: str,
key: str,
filename: str,
object_size: int,
extra_args: Dict[str, Any],
callback: Optional[Callable[..., Any]] = ...,
extra_args: dict[str, Any],
callback: Callable[..., Any] | None = ...,
) -> None: ...

class TransferConfig:
Expand All @@ -123,27 +127,27 @@ class TransferConfig:
) -> None: ...

class S3Transfer:
ALLOWED_DOWNLOAD_ARGS: List[str]
ALLOWED_UPLOAD_ARGS: List[str]
ALLOWED_DOWNLOAD_ARGS: list[str]
ALLOWED_UPLOAD_ARGS: list[str]
def __init__(
self,
client: BaseClient,
config: Optional[TransferConfig] = ...,
osutil: Optional[OSUtils] = ...,
config: TransferConfig | None = ...,
osutil: OSUtils | None = ...,
) -> None: ...
def upload_file(
self,
filename: str,
bucket: str,
key: str,
callback: Optional[Callable[..., Any]] = ...,
extra_args: Optional[Dict[str, Any]] = ...,
callback: Callable[..., Any] | None = ...,
extra_args: dict[str, Any] | None = ...,
) -> None: ...
def download_file(
self,
bucket: str,
key: str,
filename: str,
extra_args: Optional[Dict[str, Any]] = ...,
callback: Optional[Callable[..., Any]] = ...,
extra_args: dict[str, Any] | None = ...,
callback: Callable[..., Any] | None = ...,
) -> None: ...
24 changes: 13 additions & 11 deletions s3transfer-stubs/bandwidth.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import IO, Any, Optional, TypeVar, Union
"""
Copyright 2024 Vlad Emelianov
"""

from typing import IO, Any, TypeVar

from s3transfer.futures import TransferCoordinator

Expand All @@ -16,23 +20,21 @@ class TimeUtils:
def sleep(self, value: float) -> None: ...

class BandwidthLimiter:
def __init__(
self, leaky_bucket: LeakyBucket, time_utils: Optional[TimeUtils] = ...
) -> None: ...
def __init__(self, leaky_bucket: LeakyBucket, time_utils: TimeUtils | None = ...) -> None: ...
def get_bandwith_limited_stream(
self,
fileobj: Union[IO[Any], str, bytes],
fileobj: IO[Any] | str | bytes,
transfer_coordinator: TransferCoordinator,
enabled: bool = ...,
) -> BandwidthLimitedStream: ...

class BandwidthLimitedStream:
def __init__(
self,
fileobj: Union[IO[Any], str, bytes],
fileobj: IO[Any] | str | bytes,
leaky_bucket: LeakyBucket,
transfer_coordinator: TransferCoordinator,
time_utils: Optional[TimeUtils] = ...,
time_utils: TimeUtils | None = ...,
bytes_threshold: int = ...,
) -> None: ...
def enable_bandwidth_limiting(self) -> None: ...
Expand All @@ -44,15 +46,15 @@ class BandwidthLimitedStream:
def tell(self) -> int: ...
def close(self) -> None: ...
def __enter__(self: _R) -> _R: ...
def __exit__(self, *args: Any, **kwargs: Any) -> None: ...
def __exit__(self, *args: object, **kwargs: Any) -> None: ...

class LeakyBucket:
def __init__(
self,
max_rate: int,
time_utils: Optional[TimeUtils] = ...,
rate_tracker: Optional[BandwidthRateTracker] = ...,
consumption_scheduler: Optional[ConsumptionScheduler] = ...,
time_utils: TimeUtils | None = ...,
rate_tracker: BandwidthRateTracker | None = ...,
consumption_scheduler: ConsumptionScheduler | None = ...,
) -> None: ...
def consume(self, amt: int, request_token: RequestToken) -> int: ...

Expand Down
14 changes: 9 additions & 5 deletions s3transfer-stubs/compat.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""
Copyright 2024 Vlad Emelianov
"""

import os
from multiprocessing.managers import BaseManager as _BaseManager
from typing import IO, Any, Callable, Type, Union
from typing import IO, Any, Callable

rename_file = os.rename

class BaseManager(_BaseManager): ...

def accepts_kwargs(func: Callable[..., Any]) -> bool: ...

SOCKET_ERROR: Type[ConnectionError]
SOCKET_ERROR: type[ConnectionError]
MAXINT: None

def seekable(fileobj: Union[IO[Any], str, bytes]) -> bool: ...
def readable(fileobj: Union[IO[Any], str, bytes]) -> bool: ...
def fallocate(fileobj: Union[IO[Any], str, bytes], size: int) -> None: ...
def seekable(fileobj: IO[Any] | str | bytes) -> bool: ...
def readable(fileobj: IO[Any] | str | bytes) -> bool: ...
def fallocate(fileobj: IO[Any] | str | bytes, size: int) -> None: ...
4 changes: 1 addition & 3 deletions s3transfer-stubs/constants.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import List

KB: int
MB: int
GB: int
ALLOWED_DOWNLOAD_ARGS: List[str]
ALLOWED_DOWNLOAD_ARGS: list[str]
USER_AGENT: str
PROCESS_USER_AGENT: str
12 changes: 7 additions & 5 deletions s3transfer-stubs/copies.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Dict, List
"""
Copyright 2024 Vlad Emelianov
"""

from s3transfer.tasks import CompleteMultipartUploadTask as CompleteMultipartUploadTask
from s3transfer.tasks import CreateMultipartUploadTask as CreateMultipartUploadTask
Expand All @@ -10,10 +12,10 @@ from s3transfer.utils import get_callbacks as get_callbacks
from s3transfer.utils import get_filtered_dict as get_filtered_dict

class CopySubmissionTask(SubmissionTask):
EXTRA_ARGS_TO_HEAD_ARGS_MAPPING: Dict[str, str]
UPLOAD_PART_COPY_ARGS: List[str]
CREATE_MULTIPART_ARGS_BLACKLIST: List[str]
COMPLETE_MULTIPART_ARGS: List[str]
EXTRA_ARGS_TO_HEAD_ARGS_MAPPING: dict[str, str]
UPLOAD_PART_COPY_ARGS: list[str]
CREATE_MULTIPART_ARGS_BLACKLIST: list[str]
COMPLETE_MULTIPART_ARGS: list[str]

class CopyObjectTask(Task): ...
class CopyPartTask(Task): ...
Loading

0 comments on commit 5662140

Please sign in to comment.