Skip to content

Commit 708078b

Browse files
vdusekhonzajavorek
andauthored
Use absolute imports (#177)
Closes #160 Co-authored-by: Honza Javorek <[email protected]>
1 parent e6174f2 commit 708078b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+137
-149
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Create a new subpackage for Scrapy pipelines
88
- Remove some noqas thanks to the new Ruff release
9+
- Replace relative imports with absolute imports
910
- Replace asserts with custom checks in Scrapy subpackage
1011

1112
### Fixed

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ requires-python = ">=3.8"
2626
# compatibility with a wide range of external packages. This decision was discussed in detail in the following PR:
2727
# https://github.com/apify/apify-sdk-python/pull/154
2828
dependencies = [
29-
"apify-client ~= 1.6.0",
30-
"apify-shared ~= 1.1.0",
29+
"apify-client ~= 1.6.2",
30+
"apify-shared ~= 1.1.1",
3131
"aiofiles >= 22.1.0",
3232
"aioshutil >= 1.0",
3333
"colorama >= 0.4.6",
@@ -111,7 +111,6 @@ ignore = [
111111
"S303", # Use of insecure MD2, MD4, MD5, or SHA1 hash function
112112
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
113113
"TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...
114-
"TID252", # Relative imports from parent modules are bannedRuff
115114
"TRY003", # Avoid specifying long messages outside the exception class
116115

117116
# TODO: Remove this once the following issue is fixed
@@ -139,6 +138,7 @@ indent-style = "space"
139138
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
140139
"S101", # Use of assert detected
141140
"T20", # flake8-print
141+
"TID252", # Relative imports from parent modules are banned
142142
"TRY301", # Abstract `raise` to an inner function
143143
]
144144

@@ -147,7 +147,7 @@ docstring-quotes = "double"
147147
inline-quotes = "single"
148148

149149
[tool.ruff.lint.isort]
150-
known-first-party = ["apify", "apify_client", "apify_shared"]
150+
known-local-folder = ["apify"]
151151

152152
[tool.ruff.lint.pydocstyle]
153153
convention = "google"

src/apify/_crypto.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import secrets
55
from typing import Any
66

7+
from apify_shared.utils import ignore_docs
78
from cryptography.exceptions import InvalidTag as InvalidTagException
89
from cryptography.hazmat.primitives import hashes, serialization
910
from cryptography.hazmat.primitives.asymmetric import padding, rsa
1011
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
1112

12-
from apify_shared.utils import ignore_docs
13-
14-
from .consts import ENCRYPTED_INPUT_VALUE_REGEXP
13+
from apify.consts import ENCRYPTED_INPUT_VALUE_REGEXP
1514

1615
ENCRYPTION_KEY_LENGTH = 32
1716
ENCRYPTION_IV_LENGTH = 16

src/apify/_memory_storage/file_storage_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
import aiofiles
66
from aiofiles.os import makedirs
7-
87
from apify_shared.utils import json_dumps
98

10-
from .._utils import force_remove
9+
from apify._utils import force_remove
1110

1211

1312
async def update_metadata(*, data: dict, entity_directory: str, write_metadata: bool) -> None:

src/apify/_memory_storage/memory_storage_client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
import aioshutil
99
from aiofiles import ospath
1010
from aiofiles.os import rename, scandir
11-
1211
from apify_shared.consts import ApifyEnvVars
1312
from apify_shared.utils import ignore_docs
1413

15-
from .._utils import maybe_parse_bool
16-
from .resource_clients.dataset import DatasetClient
17-
from .resource_clients.dataset_collection import DatasetCollectionClient
18-
from .resource_clients.key_value_store import KeyValueStoreClient
19-
from .resource_clients.key_value_store_collection import KeyValueStoreCollectionClient
20-
from .resource_clients.request_queue import RequestQueueClient
21-
from .resource_clients.request_queue_collection import RequestQueueCollectionClient
14+
from apify._memory_storage.resource_clients.dataset import DatasetClient
15+
from apify._memory_storage.resource_clients.dataset_collection import DatasetCollectionClient
16+
from apify._memory_storage.resource_clients.key_value_store import KeyValueStoreClient
17+
from apify._memory_storage.resource_clients.key_value_store_collection import KeyValueStoreCollectionClient
18+
from apify._memory_storage.resource_clients.request_queue import RequestQueueClient
19+
from apify._memory_storage.resource_clients.request_queue_collection import RequestQueueCollectionClient
20+
from apify._utils import maybe_parse_bool
2221

2322
"""
2423
Memory storage emulates data storages that are available on the Apify platform.

src/apify/_memory_storage/resource_clients/base_resource_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if TYPE_CHECKING:
1111
from typing_extensions import Self
1212

13-
from ..memory_storage_client import MemoryStorageClient
13+
from apify._memory_storage.memory_storage_client import MemoryStorageClient
1414

1515

1616
@ignore_docs

src/apify/_memory_storage/resource_clients/base_resource_collection_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from apify_shared.models import ListPage
88
from apify_shared.utils import ignore_docs
99

10-
from ..file_storage_utils import update_metadata
11-
from .base_resource_client import BaseResourceClient
10+
from apify._memory_storage.file_storage_utils import update_metadata
11+
from apify._memory_storage.resource_clients.base_resource_client import BaseResourceClient
1212

1313
if TYPE_CHECKING:
14-
from ..memory_storage_client import MemoryStorageClient
14+
from apify._memory_storage.memory_storage_client import MemoryStorageClient
1515

1616

1717
ResourceClientType = TypeVar('ResourceClientType', bound=BaseResourceClient, contravariant=True) # noqa: PLC0105

src/apify/_memory_storage/resource_clients/dataset.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
from typing import TYPE_CHECKING, Any, AsyncIterator
88

99
import aioshutil
10-
1110
from apify_shared.models import ListPage
1211
from apify_shared.utils import ignore_docs
1312

14-
from ..._crypto import crypto_random_object_id
15-
from ..._utils import force_rename, raise_on_duplicate_storage, raise_on_non_existing_storage
16-
from ...consts import StorageTypes
17-
from ..file_storage_utils import _update_dataset_items, update_metadata
18-
from .base_resource_client import BaseResourceClient
13+
from apify._crypto import crypto_random_object_id
14+
from apify._memory_storage.file_storage_utils import _update_dataset_items, update_metadata
15+
from apify._memory_storage.resource_clients.base_resource_client import BaseResourceClient
16+
from apify._utils import force_rename, raise_on_duplicate_storage, raise_on_non_existing_storage
17+
from apify.consts import StorageTypes
1918

2019
if TYPE_CHECKING:
2120
from apify_shared.types import JSONSerializable
2221

23-
from ..memory_storage_client import MemoryStorageClient
22+
from apify._memory_storage.memory_storage_client import MemoryStorageClient
2423

2524
# This is what API returns in the x-apify-pagination-limit
2625
# header when no limit query parameter is used.

src/apify/_memory_storage/resource_clients/dataset_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from apify_shared.utils import ignore_docs
66

7-
from .base_resource_collection_client import BaseResourceCollectionClient
8-
from .dataset import DatasetClient
7+
from apify._memory_storage.resource_clients.base_resource_collection_client import BaseResourceCollectionClient
8+
from apify._memory_storage.resource_clients.dataset import DatasetClient
99

1010
if TYPE_CHECKING:
1111
from apify_shared.models import ListPage

src/apify/_memory_storage/resource_clients/key_value_store.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@
1313
import aiofiles
1414
import aioshutil
1515
from aiofiles.os import makedirs
16-
1716
from apify_shared.utils import ignore_docs, is_file_or_bytes, json_dumps
1817

19-
from ..._crypto import crypto_random_object_id
20-
from ..._utils import (
18+
from apify._crypto import crypto_random_object_id
19+
from apify._memory_storage.file_storage_utils import update_metadata
20+
from apify._memory_storage.resource_clients.base_resource_client import BaseResourceClient
21+
from apify._utils import (
2122
force_remove,
2223
force_rename,
2324
guess_file_extension,
2425
maybe_parse_body,
2526
raise_on_duplicate_storage,
2627
raise_on_non_existing_storage,
2728
)
28-
from ...consts import DEFAULT_API_PARAM_LIMIT, StorageTypes
29-
from ...log import logger
30-
from ..file_storage_utils import update_metadata
31-
from .base_resource_client import BaseResourceClient
29+
from apify.consts import DEFAULT_API_PARAM_LIMIT, StorageTypes
30+
from apify.log import logger
3231

3332
if TYPE_CHECKING:
3433
from typing_extensions import NotRequired
3534

36-
from ..memory_storage_client import MemoryStorageClient
35+
from apify._memory_storage.memory_storage_client import MemoryStorageClient
3736

3837

3938
class KeyValueStoreRecord(TypedDict):

src/apify/_memory_storage/resource_clients/key_value_store_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from apify_shared.utils import ignore_docs
66

7-
from .base_resource_collection_client import BaseResourceCollectionClient
8-
from .key_value_store import KeyValueStoreClient
7+
from apify._memory_storage.resource_clients.base_resource_collection_client import BaseResourceCollectionClient
8+
from apify._memory_storage.resource_clients.key_value_store import KeyValueStoreClient
99

1010
if TYPE_CHECKING:
1111
from apify_shared.models import ListPage

src/apify/_memory_storage/resource_clients/request_queue.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
from typing import TYPE_CHECKING
99

1010
import aioshutil
11-
from sortedcollections import ValueSortedDict
12-
1311
from apify_shared.utils import filter_out_none_values_recursively, ignore_docs, json_dumps
12+
from sortedcollections import ValueSortedDict
1413

15-
from ..._crypto import crypto_random_object_id
16-
from ..._utils import force_rename, raise_on_duplicate_storage, raise_on_non_existing_storage, unique_key_to_request_id
17-
from ...consts import StorageTypes
18-
from ..file_storage_utils import delete_request, update_metadata, update_request_queue_item
19-
from .base_resource_client import BaseResourceClient
14+
from apify._crypto import crypto_random_object_id
15+
from apify._memory_storage.file_storage_utils import delete_request, update_metadata, update_request_queue_item
16+
from apify._memory_storage.resource_clients.base_resource_client import BaseResourceClient
17+
from apify._utils import force_rename, raise_on_duplicate_storage, raise_on_non_existing_storage, unique_key_to_request_id
18+
from apify.consts import StorageTypes
2019

2120
if TYPE_CHECKING:
22-
from ..memory_storage_client import MemoryStorageClient
21+
from apify._memory_storage.memory_storage_client import MemoryStorageClient
2322

2423

2524
@ignore_docs

src/apify/_memory_storage/resource_clients/request_queue_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from apify_shared.utils import ignore_docs
66

7-
from .base_resource_collection_client import BaseResourceCollectionClient
8-
from .request_queue import RequestQueueClient
7+
from apify._memory_storage.resource_clients.base_resource_collection_client import BaseResourceCollectionClient
8+
from apify._memory_storage.resource_clients.request_queue import RequestQueueClient
99

1010
if TYPE_CHECKING:
1111
from apify_shared.models import ListPage

src/apify/_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import psutil
3636
from aiofiles import ospath
3737
from aiofiles.os import remove, rename
38-
3938
from apify_shared.consts import (
4039
BOOL_ENV_VARS,
4140
BOOL_ENV_VARS_TYPE,
@@ -57,7 +56,7 @@
5756
maybe_extract_enum_member_value,
5857
)
5958

60-
from .consts import REQUEST_ID_LENGTH, StorageTypes
59+
from apify.consts import REQUEST_ID_LENGTH, StorageTypes
6160

6261
T = TypeVar('T')
6362

src/apify/actor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from apify_shared.consts import ActorEnvVars, ActorEventTypes, ActorExitCodes, ApifyEnvVars, WebhookEventType
1313
from apify_shared.utils import ignore_docs, maybe_extract_enum_member_value
1414

15-
from ._crypto import decrypt_input_secrets, load_private_key
16-
from ._utils import (
15+
from apify._crypto import decrypt_input_secrets, load_private_key
16+
from apify._utils import (
1717
dualproperty,
1818
fetch_and_parse_env_var,
1919
get_cpu_usage_percent,
@@ -23,18 +23,18 @@
2323
run_func_at_interval_async,
2424
wrap_internal,
2525
)
26-
from .config import Configuration
27-
from .consts import EVENT_LISTENERS_TIMEOUT_SECS
28-
from .event_manager import EventManager
29-
from .log import logger
30-
from .proxy_configuration import ProxyConfiguration
31-
from .storages import Dataset, KeyValueStore, RequestQueue, StorageClientManager
26+
from apify.config import Configuration
27+
from apify.consts import EVENT_LISTENERS_TIMEOUT_SECS
28+
from apify.event_manager import EventManager
29+
from apify.log import logger
30+
from apify.proxy_configuration import ProxyConfiguration
31+
from apify.storages import Dataset, KeyValueStore, RequestQueue, StorageClientManager
3232

3333
if TYPE_CHECKING:
3434
import logging
3535
from types import TracebackType
3636

37-
from ._memory_storage import MemoryStorageClient
37+
from apify._memory_storage import MemoryStorageClient
3838

3939
T = TypeVar('T')
4040
MainReturnType = TypeVar('MainReturnType')

src/apify/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from apify_shared.consts import ActorEnvVars, ApifyEnvVars
44

5-
from ._utils import fetch_and_parse_env_var
5+
from apify._utils import fetch_and_parse_env_var
66

77

88
class Configuration:

src/apify/event_manager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Union
99

1010
import websockets.client
11-
from pyee.asyncio import AsyncIOEventEmitter
12-
1311
from apify_shared.utils import ignore_docs, maybe_extract_enum_member_value, parse_date_fields
12+
from pyee.asyncio import AsyncIOEventEmitter
1413

15-
from .log import logger
14+
from apify.log import logger
1615

1716
if TYPE_CHECKING:
1817
from apify_shared.consts import ActorEventTypes
1918

20-
from .config import Configuration
19+
from apify.config import Configuration
2120

2221
ListenerType = Union[Callable[[], None], Callable[[Any], None], Callable[[], Coroutine[Any, Any, None]], Callable[[Any], Coroutine[Any, Any, None]]]
2322

src/apify/log.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import traceback
77
from typing import Any
88

9-
from colorama import Fore, Style, just_fix_windows_console
10-
119
from apify_shared.utils import ignore_docs
10+
from colorama import Fore, Style, just_fix_windows_console
1211

1312
just_fix_windows_console()
1413

src/apify/proxy_configuration.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
from urllib.parse import urljoin, urlparse
88

99
import httpx
10-
1110
from apify_shared.consts import ApifyEnvVars
1211
from apify_shared.utils import ignore_docs
1312

14-
from .config import Configuration
15-
from .log import logger
13+
from apify.config import Configuration
14+
from apify.log import logger
1615

1716
if TYPE_CHECKING:
18-
from typing_extensions import NotRequired
19-
2017
from apify_client import ApifyClientAsync
18+
from typing_extensions import NotRequired
2119

2220
APIFY_PROXY_VALUE_REGEX = re.compile(r'^[\w._~]+$')
2321
COUNTRY_CODE_REGEX = re.compile(r'^[A-Z]{2}$')

src/apify/scrapy/middlewares/apify_proxy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
'To use this module, you need to install the "scrapy" extra. Run "pip install apify[scrapy]".',
1313
) from exc
1414

15-
from ...actor import Actor
16-
from ...proxy_configuration import ProxyConfiguration
17-
from ..utils import get_basic_auth_header
15+
from apify.actor import Actor
16+
from apify.proxy_configuration import ProxyConfiguration
17+
from apify.scrapy.utils import get_basic_auth_header
1818

1919

2020
class ApifyHttpProxyMiddleware:

src/apify/scrapy/middlewares/apify_retry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
'To use this module, you need to install the "scrapy" extra. Run "pip install apify[scrapy]".',
1414
) from exc
1515

16-
from ...actor import Actor
17-
from ..utils import nested_event_loop, open_queue_with_custom_client, to_apify_request
16+
from apify.actor import Actor
17+
from apify.scrapy.utils import nested_event_loop, open_queue_with_custom_client, to_apify_request
1818

1919
if TYPE_CHECKING:
20-
from ...storages import RequestQueue
20+
from apify.storages import RequestQueue
2121

2222

2323
class ApifyRetryMiddleware(RetryMiddleware):

src/apify/scrapy/pipelines/actor_dataset_push.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'To use this module, you need to install the "scrapy" extra. Run "pip install apify[scrapy]".',
1010
) from exc
1111

12-
from ...actor import Actor
12+
from apify.actor import Actor
1313

1414

1515
class ActorDatasetPushPipeline:

0 commit comments

Comments
 (0)