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):

0 commit comments

Comments
 (0)