Skip to content

Commit b81f5b4

Browse files
committed
address feedback
1 parent 8d7dc8c commit b81f5b4

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

src/crawlee/service_locator.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
from crawlee.errors import ServiceConflictError
77
from crawlee.events._event_manager import EventManager
88

9-
__all__ = [
10-
'get_configuration',
11-
'get_event_manager',
12-
'get_storage_client',
13-
'set_configuration',
14-
'set_event_manager',
15-
'set_storage_client',
16-
]
9+
__all__ = list[str]() # Prefer "from crawlee import service_locator"
1710

1811

1912
class _ServiceLocator:

src/crawlee/statistics/_statistics.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
if TYPE_CHECKING:
2121
from types import TracebackType
2222

23-
from crawlee.events import EventManager
24-
2523
TStatisticsState = TypeVar('TStatisticsState', bound=StatisticsState, default=StatisticsState)
2624

2725
logger = getLogger(__name__)
@@ -67,7 +65,6 @@ class Statistics(Generic[TStatisticsState]):
6765
def __init__(
6866
self,
6967
*,
70-
event_manager: EventManager | None = None,
7168
persistence_enabled: bool = False,
7269
persist_state_kvs_name: str = 'default',
7370
persist_state_key: str | None = None,
@@ -77,9 +74,6 @@ def __init__(
7774
log_interval: timedelta = timedelta(minutes=1),
7875
state_model: type[TStatisticsState] = cast(Any, StatisticsState), # noqa: B008 - in an ideal world, TStatisticsState would be inferred from this argument, but I haven't managed to do that
7976
) -> None:
80-
if event_manager:
81-
service_locator.set_event_manager(event_manager)
82-
8377
self._id = Statistics.__next_id
8478
Statistics.__next_id += 1
8579

tests/unit/basic_crawler/test_basic_crawler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import httpx
1616
import pytest
1717

18-
from crawlee import ConcurrencySettings, EnqueueStrategy, Glob, service_locator
18+
from crawlee import ConcurrencySettings, EnqueueStrategy, Glob
1919
from crawlee._request import BaseRequestData, Request
2020
from crawlee._types import BasicCrawlingContext, EnqueueLinksKwargs, HttpHeaders
2121
from crawlee.basic_crawler import BasicCrawler
@@ -863,16 +863,16 @@ async def handler(context: BasicCrawlingContext) -> None:
863863
}
864864

865865

866+
@pytest.mark.only
866867
async def test_respects_no_persist_storage() -> None:
867-
config = Configuration(persist_storage=False)
868-
service_locator.set_configuration(config)
869-
crawler = BasicCrawler()
868+
configuration = Configuration(persist_storage=False)
869+
crawler = BasicCrawler(configuration=configuration)
870870

871871
@crawler.router.default_handler
872872
async def handler(context: BasicCrawlingContext) -> None:
873873
await context.push_data({'something': 'something'})
874874

875-
datasets_path = Path(config.storage_dir) / 'datasets' / 'default'
875+
datasets_path = Path(configuration.storage_dir) / 'datasets' / 'default'
876876
assert not datasets_path.exists() or list(datasets_path.iterdir()) == []
877877

878878

0 commit comments

Comments
 (0)