Skip to content

Commit 9db76ad

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a11eb98 commit 9db76ad

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

servicex/query_core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ async def get_signed_url(
560560
if progress:
561561
progress.advance(task_id=download_progress, task_type="Download")
562562

563-
transformation_results_enabled = "transformationresults" in await self.servicex.get_resources()
563+
transformation_results_enabled = (
564+
"transformationresults" in await self.servicex.get_resources()
565+
)
564566

565567
while True:
566568
if not cached_record:
@@ -581,7 +583,7 @@ async def get_signed_url(
581583
if transformation_results_enabled:
582584
if "file-path" not in file:
583585
continue
584-
file_path = file.get("file-path", '').replace("/", ":")
586+
file_path = file.get("file-path", "").replace("/", ":")
585587
else:
586588
file_path = file.filename
587589

servicex/servicex_adapter.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646

4747
from servicex.models import TransformRequest, TransformStatus, CachedDataset
4848

49-
T = TypeVar('T')
49+
T = TypeVar("T")
5050

51-
def requires_resource(resource_name: str) -> Callable[[Callable[..., T]], Callable[..., T]]:
51+
52+
def requires_resource(
53+
resource_name: str,
54+
) -> Callable[[Callable[..., T]], Callable[..., T]]:
5255
"""
5356
Decorator to check if a specific API resource is available on the server before executing the method.
5457
@@ -68,9 +71,10 @@ def decorator(func: Callable[..., T]) -> Callable[..., T]:
6871
func_name = func.__name__
6972

7073
# Class-level cache for sync method resources
71-
sync_cache_key = f'_sync_resources_for_{resource_name}'
74+
sync_cache_key = f"_sync_resources_for_{resource_name}"
7275

7376
if is_async:
77+
7478
@wraps(func)
7579
async def async_wrapper(self, *args: Any, **kwargs: Any) -> T:
7680
# Get resources and check availability in one operation
@@ -82,14 +86,15 @@ async def async_wrapper(self, *args: Any, **kwargs: Any) -> T:
8286

8387
return cast(Callable[..., T], async_wrapper)
8488
else:
89+
8590
@wraps(func)
8691
def sync_wrapper(self, *args: Any, **kwargs: Any) -> T:
8792
# Initialize class-level cache attributes if needed
8893
cls = self.__class__
8994
if not hasattr(cls, sync_cache_key):
9095
setattr(cls, sync_cache_key, (None, 0)) # (resources, timestamp)
9196

92-
cache_ttl = getattr(self, '_resources_cache_ttl', 300)
97+
cache_ttl = getattr(self, "_resources_cache_ttl", 300)
9398
cached_resources, timestamp = getattr(cls, sync_cache_key)
9499
current_time = time.time()
95100

@@ -117,8 +122,10 @@ def sync_wrapper(self, *args: Any, **kwargs: Any) -> T:
117122

118123
class ResourceNotAvailableError(Exception):
119124
"""Exception raised when a required resource is not available on the server."""
125+
120126
pass
121127

128+
122129
class AuthorizationError(BaseException):
123130
pass
124131

@@ -140,7 +147,7 @@ def __init__(self, url: str, refresh_token: Optional[str] = None):
140147

141148
self._available_resources: Optional[Dict[str, Any]] = None
142149
self._resources_last_updated: Optional[float] = None
143-
self._resources_cache_ttl = 60*5
150+
self._resources_cache_ttl = 60 * 5
144151

145152
async def get_resources(self) -> Dict[str, Any]:
146153
"""
@@ -153,16 +160,18 @@ async def get_resources(self) -> Dict[str, Any]:
153160
current_time = time.time()
154161

155162
# Return cached resources if they exist and are not expired
156-
if (self._available_resources is not None and
157-
self._resources_last_updated is not None and
158-
current_time - self._resources_last_updated < self._resources_cache_ttl):
163+
if (
164+
self._available_resources is not None
165+
and self._resources_last_updated is not None
166+
and current_time - self._resources_last_updated < self._resources_cache_ttl
167+
):
159168
return self._available_resources
160169

161170
# Fetch resources from server
162171
headers = await self._get_authorization()
163172
async with ClientSession() as session:
164173
async with session.get(
165-
headers=headers, url=f"{self.url}/servicex/resources"
174+
headers=headers, url=f"{self.url}/servicex/resources"
166175
) as r:
167176
if r.status == 403:
168177
raise AuthorizationError(

0 commit comments

Comments
 (0)