Skip to content

Commit 421abf8

Browse files
committed
New client commit
1 parent 0c64180 commit 421abf8

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/apify/_actor.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,21 @@ def new_client(
492492
(increases exponentially from this value).
493493
timeout: The socket timeout of the HTTP requests sent to the Apify API.
494494
"""
495-
token = token or self.configuration.token
496-
api_url = api_url or self.configuration.api_base_url
497-
return ApifyClientAsync(
498-
token=token,
499-
api_url=api_url,
500-
max_retries=max_retries,
501-
min_delay_between_retries_millis=int(min_delay_between_retries.total_seconds() * 1000)
502-
if min_delay_between_retries is not None
503-
else None,
504-
timeout_secs=int(timeout.total_seconds()) if timeout else None,
505-
)
495+
kwargs = {
496+
'token': token or self.configuration.token,
497+
'api_url': api_url or self.configuration.api_base_url,
498+
}
499+
500+
if max_retries is not None:
501+
kwargs['max_retries'] = max_retries
502+
503+
if min_delay_between_retries is not None:
504+
kwargs['min_delay_between_retries_millis'] = int(min_delay_between_retries.total_seconds() * 1000)
505+
506+
if timeout is not None:
507+
kwargs['timeout_secs'] = int(timeout.total_seconds())
508+
509+
return ApifyClientAsync(**kwargs) # ty: ignore[invalid-argument-type]
506510

507511
async def open_dataset(
508512
self,

tests/e2e/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ async def _make_actor(
237237
if (main_func and main_py) or (main_func and source_files) or (main_py and source_files):
238238
raise TypeError('Cannot specify more than one of `main_func`, `main_py` and `source_files` arguments')
239239

240-
client = ApifyClientAsync(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR))
240+
api_url = os.getenv(_API_URL_ENV_VAR)
241+
client = (
242+
ApifyClientAsync(token=apify_token)
243+
if api_url is None
244+
else ApifyClientAsync(token=apify_token, api_url=api_url)
245+
)
246+
241247
actor_name = generate_unique_resource_name(label)
242248

243249
# Get the source of main_func and convert it into a reasonable main_py file.
@@ -331,7 +337,12 @@ async def _make_actor(
331337

332338
# Delete all the generated Actors.
333339
for actor_id in actors_for_cleanup:
334-
apify_client = ApifyClient(token=apify_token, api_url=os.getenv(_API_URL_ENV_VAR))
340+
api_url = os.getenv(_API_URL_ENV_VAR)
341+
342+
apify_client = (
343+
ApifyClient(token=apify_token) if api_url is None else ApifyClient(token=apify_token, api_url=api_url)
344+
)
345+
335346
actor_client = apify_client.actor(actor_id)
336347
actor = actor_client.get()
337348

tests/integration/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def apify_token() -> str:
3737
def apify_client_async(apify_token: str) -> ApifyClientAsync:
3838
"""Create an instance of the ApifyClientAsync."""
3939
api_url = os.getenv(_API_URL_ENV_VAR)
40-
41-
return ApifyClientAsync(apify_token, api_url=api_url)
40+
return ApifyClientAsync(apify_token) if api_url is None else ApifyClientAsync(apify_token, api_url=api_url)
4241

4342

4443
@pytest.fixture

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)