Skip to content

Commit

Permalink
Add sync client for v2 (#137)
Browse files Browse the repository at this point in the history
* Add better support for transfer jobs in mv/cp/rm

* Fix type

* Add upload method

* Add download method

* Add aiofiles dep

* Pin aiofiles to 23.2.1 to maintain support for python 3.7

* Fix mypy errors

* Fix aiofiles version

* Fix types-aiofiles version

* Add sync client

* Fix mypy errors

* Add docs for sync client
  • Loading branch information
ekouts authored Dec 3, 2024
1 parent 95b3770 commit 3525518
Show file tree
Hide file tree
Showing 13 changed files with 998 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy-unasync]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion docs/source/reference_async_v2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The library also provides an asynchronous API for the client:

The ``AsyncFirecrest`` class
****************************
.. autoclass:: firecrest.v2.AsyncClient.AsyncFirecrest
.. autoclass:: firecrest.v2.AsyncFirecrest
:members:
:undoc-members:
:show-inheritance:
11 changes: 11 additions & 0 deletions docs/source/reference_sync_v2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FirecREST objects
==============================

Here is the API for the client:

The ``Firecrest`` class
****************************
.. autoclass:: firecrest.v2.Firecrest
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/reference_v2_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ API v2
:maxdepth: 2
:caption: Contents:

reference_sync_v2
reference_async_v2
3 changes: 3 additions & 0 deletions firecrest/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause
#

from firecrest.v2._async.Client import AsyncFirecrest
from firecrest.v2._sync.Client import Firecrest
20 changes: 3 additions & 17 deletions firecrest/v2/AsyncClient.py → firecrest/v2/_async/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import pathlib
import ssl

import requests

from contextlib import asynccontextmanager
from io import BytesIO
from packaging.version import Version, parse
from typing import Any, ContextManager, Optional, List
from typing import Any, Optional, List

from firecrest.utilities import (
parse_retry_after, slurm_state_completed, time_block
slurm_state_completed, time_block
)
from firecrest.FirecrestException import (
FirecrestException,
Expand Down Expand Up @@ -55,18 +53,6 @@ def sleep_generator():
value *= 2 # Double the value for each iteration


@asynccontextmanager
async def async_file_context(file):
if isinstance(file, (str, pathlib.Path)):
# Open the file asynchronously if it's a string or path
async with aiofiles.open(file, "rb") as f:
print('opened file')
yield f
else:
# Use the file as-is if it's already a BytesIO or similar
yield file


class AsyncFirecrest:
"""
This is the basic class you instantiate to access the FirecREST API v2.
Expand Down Expand Up @@ -867,7 +853,7 @@ async def attach_to_job(
:param system_name: the system name where the filesystem belongs to
:param jobid: the ID of the job
command: the command to be executed
:param command: the command to be executed
:calls: PUT `/compute/{system_name}/jobs/{jobid}/attach`
"""
resp = await self._put_request(
Expand Down
Empty file added firecrest/v2/_async/__init__.py
Empty file.
Loading

0 comments on commit 3525518

Please sign in to comment.