Skip to content

Commit 7840c5a

Browse files
committed
utilize lazy object proxy
1 parent 7090ff0 commit 7840c5a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ html5lib = { version = ">=1.0", optional = true }
5454
# https://github.com/apify/crawlee-python/issues/774
5555
httpx = { version = "~=0.27.0", extras = ["brotli", "http2"] }
5656
inquirer = ">=3.3.0"
57+
lazy-object-proxy = ">=1.10.0"
5758
lxml = { version = ">=5.2.0", optional = true }
5859
more_itertools = ">=10.2.0"
5960
parsel = { version = ">=1.9.0", optional = true }
@@ -66,7 +67,7 @@ sortedcollections = ">=2.1.0"
6667
tldextract = ">=5.1.0"
6768
typer = ">=0.12.0"
6869
typing-extensions = ">=4.1.0"
69-
yarl = "^1.18.0"
70+
yarl = ">=1.18.0"
7071

7172
[tool.poetry.group.dev.dependencies]
7273
build = "~1.2.0"
@@ -205,6 +206,10 @@ warn_return_any = true
205206
warn_unreachable = true
206207
warn_unused_ignores = true
207208

209+
[[tool.mypy.overrides]]
210+
module = ['lazy_object_proxy']
211+
ignore_missing_imports = true
212+
208213
[tool.basedpyright]
209214
pythonVersion = "3.9"
210215
typeCheckingMode = "standard"

src/crawlee/service_container.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from lazy_object_proxy import Proxy as LazyObjectProxy
4+
35
from crawlee._utils.docs import docs_group
46
from crawlee.base_storage_client._base_storage_client import BaseStorageClient
57
from crawlee.configuration import Configuration
@@ -91,7 +93,8 @@ def storage_client_was_set(self) -> bool:
9193
@docs_group('Functions')
9294
def get_configuration() -> Configuration:
9395
"""Get the configuration."""
94-
return _service_locator.configuration
96+
proxy_config: Configuration = LazyObjectProxy(lambda: _service_locator.configuration)
97+
return proxy_config
9598

9699

97100
@docs_group('Functions')
@@ -113,7 +116,8 @@ def set_configuration(configuration: Configuration) -> None:
113116
@docs_group('Functions')
114117
def get_event_manager() -> EventManager:
115118
"""Get the event manager."""
116-
return _service_locator.event_manager
119+
proxy_event_manager: EventManager = LazyObjectProxy(lambda: _service_locator.event_manager)
120+
return proxy_event_manager
117121

118122

119123
@docs_group('Functions')
@@ -135,7 +139,8 @@ def set_event_manager(event_manager: EventManager) -> None:
135139
@docs_group('Functions')
136140
def get_storage_client() -> BaseStorageClient:
137141
"""Get the storage client."""
138-
return _service_locator.storage_client
142+
proxy_storage_client: BaseStorageClient = LazyObjectProxy(lambda: _service_locator.storage_client)
143+
return proxy_storage_client
139144

140145

141146
@docs_group('Functions')

0 commit comments

Comments
 (0)