Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 13, 2024
1 parent 0d999cb commit cc730e9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
14 changes: 7 additions & 7 deletions platform_storage_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,12 @@ async def handle_error_if_streamed(
error_class: type[web.HTTPError] = web.HTTPBadRequest,
) -> None:
if response.prepared:
error_dict = dict(
error=str_error,
errno=errorcode[errno]
if errno is not None and errno in errorcode
else errno,
)
error_dict = {
"error": str_error,
"errno": (
errorcode[errno] if errno is not None and errno in errorcode else errno
),
}
await response.write(json.dumps(error_dict).encode())
else:
raise _http_exception(error_class, str_error, errno=errno)
Expand Down Expand Up @@ -862,7 +862,7 @@ def make_tracing_trace_configs(config: Config) -> list[aiohttp.TraceConfig]:
async def create_app(config: Config) -> web.Application:
app = web.Application(
middlewares=[handle_exceptions],
handler_args=dict(keepalive_timeout=config.server.keep_alive_timeout_s),
handler_args={"keepalive_timeout": config.server.keep_alive_timeout_s},
)
app[CONFIG_KEY] = config

Expand Down
41 changes: 20 additions & 21 deletions platform_storage_api/fs/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,21 @@ async def _iterate_in_chunks(
yield chunk

def _scandir_iter(self, path: PurePath) -> Iterator[FileStatus]:
with self._resolve_dir_fd(path) as dirfd:
with os.scandir(dirfd) as scandir_it:
for entry in scandir_it:
if entry.is_symlink():
target = os.readlink(entry.name, dir_fd=dirfd)
yield self._create_linkstatus(
PurePath(entry.name),
entry.stat(follow_symlinks=False),
target=target,
)
else:
yield self._create_filestatus(
PurePath(entry.name),
entry.stat(follow_symlinks=False),
entry.is_dir(follow_symlinks=False),
)
with self._resolve_dir_fd(path) as dirfd, os.scandir(dirfd) as scandir_it:
for entry in scandir_it:
if entry.is_symlink():
target = os.readlink(entry.name, dir_fd=dirfd)
yield self._create_linkstatus(
PurePath(entry.name),
entry.stat(follow_symlinks=False),
target=target,
)
else:
yield self._create_filestatus(
PurePath(entry.name),
entry.stat(follow_symlinks=False),
entry.is_dir(follow_symlinks=False),
)

async def _iterstatus_iter(
self, dir_iter: Iterator[FileStatus]
Expand Down Expand Up @@ -566,11 +565,11 @@ async def remove(self, path: PurePath, *, recursive: bool = False) -> None:
await self._loop.run_in_executor(self._executor, self._remove, path, recursive)

def _rename(self, old: PurePath, new: PurePath) -> None:
with self._resolve_dir_fd(old.parent) as src_dir_fd:
with self._resolve_dir_fd(new.parent) as dst_dir_fd:
os.rename(
old.name, new.name, src_dir_fd=src_dir_fd, dst_dir_fd=dst_dir_fd
)
with (
self._resolve_dir_fd(old.parent) as src_dir_fd,
self._resolve_dir_fd(new.parent) as dst_dir_fd,
):
os.rename(old.name, new.name, src_dir_fd=src_dir_fd, dst_dir_fd=dst_dir_fd)

async def rename(self, old: PurePath, new: PurePath) -> None:
await self._loop.run_in_executor(self._executor, self._rename, old, new)
Expand Down
2 changes: 1 addition & 1 deletion platform_storage_api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def rename(

@trace
async def disk_usage(
self, path: Optional[Union[PurePath, str]] = None
self, path: Union[PurePath, str, None] = None
) -> DiskUsageInfo:
real_path = await self._path_resolver.resolve_path(PurePath(path or "/"))
return await self._fs.disk_usage(real_path)
2 changes: 1 addition & 1 deletion tests/integration/test_api_sharing_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import yarl

from platform_storage_api.fs.local import FileStatusType
from tests.integration.conftest import ApiConfig, status_iter_response_to_list

from .auth import _User, _UserFactory
from tests.integration.conftest import ApiConfig, status_iter_response_to_list


class TestStorageListAndResourceSharing:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_api_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

from platform_storage_api.api import WSStorageOperation
from platform_storage_api.fs.local import FileStatusType

from .auth import _User, _UserFactory
from tests.integration.conftest import (
ApiConfig,
get_filestatus_dict,
get_liststatus_dict,
)

from .auth import _User, _UserFactory


def ws_request(
op: WSStorageOperation, id: int, path: Optional[str] = None, **kwargs: Any
Expand Down

0 comments on commit cc730e9

Please sign in to comment.