Skip to content

Commit 9ce6e14

Browse files
barjinvdusek
andauthored
docs: Add @docs_group decorator (#655)
Adds support for the `@docs_group` decorator, which sets the symbol's group in the documentation. Adds the decorators as per the list in #650 . Hides the undecorated symbols under the project root (but keeps those in classes etc., so class / object methods + properties are still documented). ![obrazek](https://github.com/user-attachments/assets/f196f75b-015e-4247-a6bf-f062cb93e97a) Closes #650 --------- Co-authored-by: Vlada Dusek <[email protected]>
1 parent d26aeb7 commit 9ce6e14

Some content is hidden

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

50 files changed

+199
-25
lines changed

src/crawlee/_autoscaling/autoscaled_pool.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import TYPE_CHECKING, Awaitable, Callable
1111

1212
from crawlee._types import ConcurrencySettings
13+
from crawlee._utils.docs import docs_group
1314
from crawlee._utils.recurring_task import RecurringTask
1415

1516
if TYPE_CHECKING:
@@ -32,6 +33,7 @@ def __init__(self) -> None:
3233
self.result: asyncio.Future = asyncio.Future()
3334

3435

36+
@docs_group('Classes')
3537
class AutoscaledPool:
3638
"""Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
3739

src/crawlee/_autoscaling/snapshotter.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from crawlee._autoscaling.types import ClientSnapshot, CpuSnapshot, EventLoopSnapshot, MemorySnapshot, Snapshot
1212
from crawlee._utils.byte_size import ByteSize
13+
from crawlee._utils.docs import docs_group
1314
from crawlee._utils.recurring_task import RecurringTask
1415
from crawlee.events._types import Event, EventSystemInfoData
1516

@@ -21,6 +22,7 @@
2122
logger = getLogger(__name__)
2223

2324

25+
@docs_group('Classes')
2426
class Snapshotter:
2527
"""Monitors and logs system resource usage at predefined intervals for performance optimization.
2628

src/crawlee/_autoscaling/system_status.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from more_itertools import pairwise
1010

1111
from crawlee._autoscaling.types import LoadRatioInfo, Snapshot, SystemInfo
12+
from crawlee._utils.docs import docs_group
1213
from crawlee._utils.math import compute_weighted_avg
1314

1415
if TYPE_CHECKING:
@@ -17,6 +18,7 @@
1718
logger = getLogger(__name__)
1819

1920

21+
@docs_group('Classes')
2022
class SystemStatus:
2123
"""Provides a simple interface for evaluating system resource usage from snapshots collected by `Snapshotter`.
2224

src/crawlee/_request.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from crawlee._types import EnqueueStrategy, HttpHeaders, HttpMethod, HttpPayload, JsonSerializable
2323
from crawlee._utils.crypto import crypto_random_object_id
24+
from crawlee._utils.docs import docs_group
2425
from crawlee._utils.requests import compute_unique_key, unique_key_to_request_id
2526
from crawlee._utils.urls import extract_query_params, validate_http_url
2627

@@ -227,6 +228,7 @@ def get_query_param_from_url(self, param: str, *, default: str | None = None) ->
227228
return values[0]
228229

229230

231+
@docs_group('Data structures')
230232
class Request(BaseRequestData):
231233
"""Represents a request in the Crawlee framework, containing the necessary information for crawling operations.
232234

src/crawlee/_types.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from pydantic import ConfigDict, Field, PlainValidator, RootModel
2020
from typing_extensions import NotRequired, TypeAlias, TypedDict, Unpack
2121

22+
from crawlee._utils.docs import docs_group
23+
2224
if TYPE_CHECKING:
2325
import logging
2426
import re
@@ -97,6 +99,7 @@ def __len__(self) -> int:
9799
return len(self.root)
98100

99101

102+
@docs_group('Data structures')
100103
class EnqueueStrategy(str, Enum):
101104
"""Strategy for deciding which links should be followed and which ones should be ignored."""
102105

@@ -117,6 +120,7 @@ class EnqueueStrategy(str, Enum):
117120
the same protocol, domain, and port, ensuring a strict scope for the crawl."""
118121

119122

123+
@docs_group('Data structures')
120124
class ConcurrencySettings:
121125
"""Concurrency settings for AutoscaledPool."""
122126

@@ -333,6 +337,7 @@ def __call__(
333337

334338

335339
@dataclass(frozen=True)
340+
@docs_group('Data structures')
336341
class BasicCrawlingContext:
337342
"""Basic crawling context intended to be extended by crawlers."""
338343

src/crawlee/_utils/docs.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
3+
from typing import Callable, Literal
4+
5+
GroupName = Literal['Classes', 'Abstract classes', 'Data structures', 'Errors', 'Functions']
6+
7+
8+
def docs_group(group_name: GroupName) -> Callable: # noqa: ARG001
9+
"""Decorator to mark symbols for rendering and grouping in documentation.
10+
11+
This decorator is used purely for documentation purposes and does not alter the behavior
12+
of the decorated callable.
13+
"""
14+
15+
def wrapper(func: Callable) -> Callable:
16+
return func
17+
18+
return wrapper

src/crawlee/base_storage_client/_base_dataset_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING, AsyncContextManager, AsyncIterator
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from httpx import Response
810

911
from crawlee._types import JsonSerializable
1012
from crawlee.base_storage_client._models import DatasetItemsListPage, DatasetMetadata
1113

1214

15+
@docs_group('Abstract classes')
1316
class BaseDatasetClient(ABC):
1417
"""Abstract base class for dataset resource clients.
1518

src/crawlee/base_storage_client/_base_dataset_collection_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from crawlee.base_storage_client._models import DatasetListPage, DatasetMetadata
810

911

12+
@docs_group('Abstract classes')
1013
class BaseDatasetCollectionClient(ABC):
1114
"""Abstract base class for dataset collection clients.
1215

src/crawlee/base_storage_client/_base_key_value_store_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING, Any, AsyncContextManager
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from httpx import Response
810

@@ -13,6 +15,7 @@
1315
)
1416

1517

18+
@docs_group('Abstract classes')
1619
class BaseKeyValueStoreClient(ABC):
1720
"""Abstract base class for key-value store resource clients.
1821

src/crawlee/base_storage_client/_base_key_value_store_collection_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from crawlee.base_storage_client._models import KeyValueStoreListPage, KeyValueStoreMetadata
810

911

12+
@docs_group('Abstract classes')
1013
class BaseKeyValueStoreCollectionClient(ABC):
1114
"""Abstract base class for key-value store collection clients.
1215

src/crawlee/base_storage_client/_base_request_queue_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from collections.abc import Sequence
810

@@ -17,6 +19,7 @@
1719
)
1820

1921

22+
@docs_group('Abstract classes')
2023
class BaseRequestQueueClient(ABC):
2124
"""Abstract base class for request queue resource clients.
2225

src/crawlee/base_storage_client/_base_request_queue_collection_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING
55

6+
from crawlee._utils.docs import docs_group
7+
68
if TYPE_CHECKING:
79
from crawlee.base_storage_client._models import RequestQueueListPage, RequestQueueMetadata
810

911

12+
@docs_group('Abstract classes')
1013
class BaseRequestQueueCollectionClient(ABC):
1114
"""Abstract base class for request queue collection clients.
1215

src/crawlee/base_storage_client/_base_storage_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from abc import ABC, abstractmethod
66
from typing import TYPE_CHECKING
77

8+
from crawlee._utils.docs import docs_group
9+
810
if TYPE_CHECKING:
911
from ._base_dataset_client import BaseDatasetClient
1012
from ._base_dataset_collection_client import BaseDatasetCollectionClient
@@ -14,6 +16,7 @@
1416
from ._base_request_queue_collection_client import BaseRequestQueueCollectionClient
1517

1618

19+
@docs_group('Abstract classes')
1720
class BaseStorageClient(ABC):
1821
"""Defines an abstract base for storage clients.
1922

src/crawlee/base_storage_client/_models.py

+19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from crawlee._request import Request
1212
from crawlee._types import HttpMethod
13+
from crawlee._utils.docs import docs_group
1314
from crawlee._utils.urls import validate_http_url
1415

1516
KvsValueType = TypeVar('KvsValueType', default=Any)
@@ -27,6 +28,7 @@ class _BaseStorageMetadata(BaseModel):
2728
modified_at: Annotated[datetime, Field(alias='modifiedAt')]
2829

2930

31+
@docs_group('Data structures')
3032
class DatasetMetadata(_BaseStorageMetadata):
3133
"""Model for a dataset metadata."""
3234

@@ -35,6 +37,7 @@ class DatasetMetadata(_BaseStorageMetadata):
3537
item_count: Annotated[int, Field(alias='itemCount')]
3638

3739

40+
@docs_group('Data structures')
3841
class KeyValueStoreMetadata(_BaseStorageMetadata):
3942
"""Model for a key-value store metadata."""
4043

@@ -43,6 +46,7 @@ class KeyValueStoreMetadata(_BaseStorageMetadata):
4346
user_id: Annotated[str, Field(alias='userId')]
4447

4548

49+
@docs_group('Data structures')
4650
class RequestQueueMetadata(_BaseStorageMetadata):
4751
"""Model for a request queue metadata."""
4852

@@ -57,6 +61,7 @@ class RequestQueueMetadata(_BaseStorageMetadata):
5761
resource_directory: Annotated[str, Field(alias='resourceDirectory')]
5862

5963

64+
@docs_group('Data structures')
6065
class KeyValueStoreRecord(BaseModel, Generic[KvsValueType]):
6166
"""Model for a key-value store record."""
6267

@@ -68,6 +73,7 @@ class KeyValueStoreRecord(BaseModel, Generic[KvsValueType]):
6873
filename: Annotated[str | None, Field(alias='filename', default=None)]
6974

7075

76+
@docs_group('Data structures')
7177
class KeyValueStoreRecordMetadata(BaseModel):
7278
"""Model for a key-value store record metadata."""
7379

@@ -77,6 +83,7 @@ class KeyValueStoreRecordMetadata(BaseModel):
7783
content_type: Annotated[str, Field(alias='contentType')]
7884

7985

86+
@docs_group('Data structures')
8087
class KeyValueStoreKeyInfo(BaseModel):
8188
"""Model for a key-value store key info."""
8289

@@ -86,6 +93,7 @@ class KeyValueStoreKeyInfo(BaseModel):
8693
size: Annotated[int, Field(alias='size')]
8794

8895

96+
@docs_group('Data structures')
8997
class KeyValueStoreListKeysPage(BaseModel):
9098
"""Model for listing keys in the key-value store."""
9199

@@ -99,6 +107,7 @@ class KeyValueStoreListKeysPage(BaseModel):
99107
next_exclusive_start_key: Annotated[str | None, Field(alias='nextExclusiveStartKey', default=None)]
100108

101109

110+
@docs_group('Data structures')
102111
class RequestQueueHeadState(BaseModel):
103112
"""Model for the request queue head state."""
104113

@@ -111,6 +120,7 @@ class RequestQueueHeadState(BaseModel):
111120
had_multiple_clients: Annotated[bool, Field(alias='hadMultipleClients')]
112121

113122

123+
@docs_group('Data structures')
114124
class RequestQueueHead(BaseModel):
115125
"""Model for the request queue head."""
116126

@@ -122,6 +132,7 @@ class RequestQueueHead(BaseModel):
122132
items: Annotated[list[Request], Field(alias='items', default_factory=list)]
123133

124134

135+
@docs_group('Data structures')
125136
class RequestQueueHeadWithLocks(RequestQueueHead):
126137
"""Model for request queue head with locks."""
127138

@@ -149,34 +160,39 @@ class _BaseListPage(BaseModel):
149160
"""Indicates if the returned list is in descending order."""
150161

151162

163+
@docs_group('Data structures')
152164
class DatasetListPage(_BaseListPage):
153165
"""Model for a single page of dataset items returned from a collection list method."""
154166

155167
items: Annotated[list[DatasetMetadata], Field(default_factory=list)]
156168
"""The list of dataset items returned on this page."""
157169

158170

171+
@docs_group('Data structures')
159172
class KeyValueStoreListPage(_BaseListPage):
160173
"""Model for a single page of key-value store items returned from a collection list method."""
161174

162175
items: Annotated[list[KeyValueStoreMetadata], Field(default_factory=list)]
163176
"""The list of key-value store items returned on this page."""
164177

165178

179+
@docs_group('Data structures')
166180
class RequestQueueListPage(_BaseListPage):
167181
"""Model for a single page of request queue items returned from a collection list method."""
168182

169183
items: Annotated[list[RequestQueueMetadata], Field(default_factory=list)]
170184
"""The list of request queue items returned on this page."""
171185

172186

187+
@docs_group('Data structures')
173188
class DatasetItemsListPage(_BaseListPage):
174189
"""Model for a single page of dataset items returned from a collection list method."""
175190

176191
items: Annotated[list[dict], Field(default_factory=list)]
177192
"""The list of dataset items returned on this page."""
178193

179194

195+
@docs_group('Data structures')
180196
class ProlongRequestLockResponse(BaseModel):
181197
"""Response to prolong request lock calls."""
182198

@@ -185,6 +201,7 @@ class ProlongRequestLockResponse(BaseModel):
185201
lock_expires_at: Annotated[datetime, Field(alias='lockExpiresAt')]
186202

187203

204+
@docs_group('Data structures')
188205
class ProcessedRequest(BaseModel):
189206
"""Represents a processed request."""
190207

@@ -196,6 +213,7 @@ class ProcessedRequest(BaseModel):
196213
was_already_handled: Annotated[bool, Field(alias='wasAlreadyHandled')]
197214

198215

216+
@docs_group('Data structures')
199217
class UnprocessedRequest(BaseModel):
200218
"""Represents an unprocessed request."""
201219

@@ -206,6 +224,7 @@ class UnprocessedRequest(BaseModel):
206224
method: Annotated[HttpMethod | None, Field()] = None
207225

208226

227+
@docs_group('Data structures')
209228
class BatchRequestsOperationResponse(BaseModel):
210229
"""Response to batch request deletion calls."""
211230

0 commit comments

Comments
 (0)