Skip to content

Commit 8ba084d

Browse files
authored
chore!: Update apify-client and apify-shared to v2.0 (#548)
1 parent 4a541a4 commit 8ba084d

File tree

9 files changed

+71
-88
lines changed

9 files changed

+71
-88
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ keywords = [
3434
"scraping",
3535
]
3636
dependencies = [
37-
"apify-client<2.0.0",
38-
"apify-shared<2.0.1",
37+
"apify-client>=2.0.0,<3.0.0",
38+
"apify-shared>=2.0.0,<3.0.0",
3939
"crawlee@git+https://github.com/apify/crawlee-python.git@master",
4040
"cachetools>=5.5.0",
4141
"cryptography>=42.0.0",

src/apify/_actor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from apify_client import ApifyClientAsync
1515
from apify_shared.consts import ActorEnvVars, ActorExitCodes, ApifyEnvVars
16-
from apify_shared.utils import maybe_extract_enum_member_value
1716
from crawlee import service_locator
1817
from crawlee.events import (
1918
Event,
@@ -31,7 +30,7 @@
3130
from apify._crypto import decrypt_input_secrets, load_private_key
3231
from apify._models import ActorRun
3332
from apify._proxy_configuration import ProxyConfiguration
34-
from apify._utils import docs_group, docs_name, get_system_info, is_running_in_ipython
33+
from apify._utils import docs_group, docs_name, get_system_info, is_running_in_ipython, maybe_extract_enum_member_value
3534
from apify.events import ApifyEventManager, EventManager, LocalEventManager
3635
from apify.log import _configure_logging, logger
3736
from apify.storage_clients import ApifyStorageClient

src/apify/_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import builtins
44
import sys
5+
from enum import Enum
56
from importlib import metadata
6-
from typing import TYPE_CHECKING, Literal
7+
from typing import TYPE_CHECKING, Any, Literal
78

89
if TYPE_CHECKING:
910
from collections.abc import Callable
@@ -81,3 +82,10 @@ def wrapper(func: Callable) -> Callable:
8182
return func
8283

8384
return wrapper
85+
86+
87+
def maybe_extract_enum_member_value(maybe_enum_member: Any) -> Any:
88+
"""Extract the value of an enumeration member if it is an Enum, otherwise return the original value."""
89+
if isinstance(maybe_enum_member, Enum):
90+
return maybe_enum_member.value
91+
return maybe_enum_member

src/apify/storage_clients/_apify/_dataset_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def get_data(
198198
desc: bool = False,
199199
fields: list[str] | None = None,
200200
omit: list[str] | None = None,
201-
unwind: str | None = None,
201+
unwind: list[str] | None = None,
202202
skip_empty: bool = False,
203203
skip_hidden: bool = False,
204204
flatten: list[str] | None = None,
@@ -229,7 +229,7 @@ async def iterate_items(
229229
desc: bool = False,
230230
fields: list[str] | None = None,
231231
omit: list[str] | None = None,
232-
unwind: str | None = None,
232+
unwind: list[str] | None = None,
233233
skip_empty: bool = False,
234234
skip_hidden: bool = False,
235235
) -> AsyncIterator[dict]:

tests/integration/test_actor_api_helpers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ async def main() -> None:
4040

4141
assert env_dict.get('is_at_home') is True
4242
assert env_dict.get('token') is not None
43-
assert env_dict.get('actor_events_ws_url') is not None
43+
assert env_dict.get('events_websocket_url') is not None
4444
assert env_dict.get('input_key') is not None
4545

46-
assert len(env_dict.get('actor_id', '')) == 17
47-
assert len(env_dict.get('actor_run_id', '')) == 17
46+
assert len(env_dict.get('id', '')) == 17
47+
assert len(env_dict.get('build_id', '')) == 17
48+
assert len(env_dict.get('run_id', '')) == 17
4849
assert len(env_dict.get('user_id', '')) == 17
4950

5051
actor = await make_actor(label='get-env', main_func=main)

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,15 @@ async def test_actor_is_not_at_home_when_local() -> None:
3131
assert is_at_home is False
3232

3333

34-
async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0912
34+
async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) -> None:
3535
ignored_env_vars = {
36-
ApifyEnvVars.INPUT_KEY,
37-
ApifyEnvVars.MEMORY_MBYTES,
38-
ApifyEnvVars.STARTED_AT,
39-
ApifyEnvVars.TIMEOUT_AT,
40-
ApifyEnvVars.DEFAULT_DATASET_ID,
41-
ApifyEnvVars.DEFAULT_KEY_VALUE_STORE_ID,
42-
ApifyEnvVars.DEFAULT_REQUEST_QUEUE_ID,
4336
ApifyEnvVars.SDK_LATEST_VERSION,
4437
ApifyEnvVars.LOG_FORMAT,
4538
ApifyEnvVars.LOG_LEVEL,
4639
ActorEnvVars.STANDBY_PORT,
4740
ApifyEnvVars.PERSIST_STORAGE,
4841
}
4942

50-
legacy_env_vars = {
51-
ApifyEnvVars.ACT_ID: ActorEnvVars.ID,
52-
ApifyEnvVars.ACT_RUN_ID: ActorEnvVars.RUN_ID,
53-
ApifyEnvVars.ACTOR_ID: ActorEnvVars.ID,
54-
ApifyEnvVars.ACTOR_BUILD_ID: ActorEnvVars.BUILD_ID,
55-
ApifyEnvVars.ACTOR_BUILD_NUMBER: ActorEnvVars.BUILD_NUMBER,
56-
ApifyEnvVars.ACTOR_RUN_ID: ActorEnvVars.RUN_ID,
57-
ApifyEnvVars.ACTOR_TASK_ID: ActorEnvVars.TASK_ID,
58-
ApifyEnvVars.CONTAINER_URL: ActorEnvVars.WEB_SERVER_URL,
59-
ApifyEnvVars.CONTAINER_PORT: ActorEnvVars.WEB_SERVER_PORT,
60-
}
61-
6243
# Set up random env vars
6344
expected_get_env = dict[str, Any]()
6445
expected_get_env[ApifyEnvVars.LOG_LEVEL.name.lower()] = 'INFO'
@@ -134,9 +115,7 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
134115

135116
# We need this override so that the actor doesn't fail when connecting to the platform events websocket
136117
monkeypatch.delenv(ActorEnvVars.EVENTS_WEBSOCKET_URL)
137-
monkeypatch.delenv(ApifyEnvVars.ACTOR_EVENTS_WS_URL)
138118
expected_get_env[ActorEnvVars.EVENTS_WEBSOCKET_URL.name.lower()] = None
139-
expected_get_env[ApifyEnvVars.ACTOR_EVENTS_WS_URL.name.lower()] = None
140119

141120
# Adjust expectations for timedelta fields
142121
for env_name, env_value in expected_get_env.items():
@@ -148,10 +127,6 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
148127
expected_get_env[ApifyEnvVars.DEDICATED_CPUS.name.lower()]
149128
)
150129

151-
# Update expectations for legacy configuration
152-
for old_name, new_name in legacy_env_vars.items():
153-
expected_get_env[old_name.name.lower()] = expected_get_env[new_name.name.lower()]
154-
155130
await Actor.init()
156131
assert Actor.get_env() == expected_get_env
157132

tests/unit/actor/test_actor_lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def handler(websocket: websockets.asyncio.server.ServerConnection) -> None
148148

149149
async with websockets.asyncio.server.serve(handler, host='localhost') as ws_server:
150150
port: int = ws_server.sockets[0].getsockname()[1] # type: ignore[index]
151-
monkeypatch.setenv(ApifyEnvVars.ACTOR_EVENTS_WS_URL, f'ws://localhost:{port}')
151+
monkeypatch.setenv(ActorEnvVars.EVENTS_WEBSOCKET_URL, f'ws://localhost:{port}')
152152

153153
mock_run_client = Mock()
154154
mock_run_client.run.return_value.get = AsyncMock(

0 commit comments

Comments
 (0)