Skip to content

Commit 8fcff20

Browse files
authored
docs: hotfix API reference docs (#282)
Slightly bends the `transformDocs.js` script to accommodate the new structure of the project better. The next Python docs steps are documented in apify/crawlee-python#324 Closes #270
1 parent bb16a42 commit 8fcff20

File tree

8 files changed

+37
-16
lines changed

8 files changed

+37
-16
lines changed

src/apify/_crypto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def private_decrypt(
114114
return decipher_bytes.decode('utf-8')
115115

116116

117+
@ignore_docs
117118
def load_private_key(private_key_file_base64: str, private_key_password: str) -> rsa.RSAPrivateKey:
118119
private_key = serialization.load_pem_private_key(
119120
base64.b64decode(private_key_file_base64.encode('utf-8')),
@@ -133,6 +134,7 @@ def _load_public_key(public_key_file_base64: str) -> rsa.RSAPublicKey:
133134
return public_key
134135

135136

137+
@ignore_docs
136138
def decrypt_input_secrets(private_key: rsa.RSAPrivateKey, input_data: Any) -> Any:
137139
"""Decrypt input secrets."""
138140
if not isinstance(input_data, dict):

src/apify/_platform_event_manager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pydantic import BaseModel, Discriminator, Field, TypeAdapter
99
from typing_extensions import Self, Unpack, override
1010

11-
from apify_shared.utils import ignore_docs
1211
from crawlee.events._event_manager import EventManager, EventManagerOptions
1312
from crawlee.events._local_event_manager import LocalEventManager
1413
from crawlee.events._types import (
@@ -126,7 +125,6 @@ class UnknownEvent(BaseModel):
126125
)
127126

128127

129-
@ignore_docs
130128
class PlatformEventManager(EventManager):
131129
"""A class for managing Actor events.
132130

src/apify/_proxy_configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
SESSION_ID_MAX_LENGTH = 50
2828

2929

30+
@ignore_docs
3031
def is_url(url: str) -> bool:
3132
"""Check if the given string is a valid URL."""
3233
try:

src/apify/log.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
from typing import TYPE_CHECKING
55

6+
from apify_shared.utils import ignore_docs
67
from crawlee._log_config import CrawleeLogFormatter, configure_logger, get_configured_log_level
78

89
if TYPE_CHECKING:
@@ -15,6 +16,7 @@
1516
logger = logging.getLogger(logger_name)
1617

1718

19+
@ignore_docs
1820
class ActorLogFormatter(CrawleeLogFormatter): # noqa: D101 Inherited from parent class
1921
pass
2022

src/apify/scrapy/requests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pickle
55
from typing import Any, cast
66

7+
from apify_shared.utils import ignore_docs
8+
79
try:
810
from scrapy import Request, Spider
911
from scrapy.http.headers import Headers
@@ -28,6 +30,7 @@ def _is_request_produced_by_middleware(scrapy_request: Request) -> bool:
2830
return bool(scrapy_request.meta.get('redirect_times')) or bool(scrapy_request.meta.get('retry_times'))
2931

3032

33+
@ignore_docs
3134
def to_apify_request(scrapy_request: Request, spider: Spider) -> CrawleeRequest | None:
3235
"""Convert a Scrapy request to an Apify request.
3336
@@ -98,6 +101,7 @@ def to_apify_request(scrapy_request: Request, spider: Spider) -> CrawleeRequest
98101
return apify_request
99102

100103

104+
@ignore_docs
101105
def to_scrapy_request(apify_request: CrawleeRequest, spider: Spider) -> Request:
102106
"""Convert an Apify request to a Scrapy request.
103107

src/apify/scrapy/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from base64 import b64encode
55
from urllib.parse import unquote
66

7+
from apify_shared.utils import ignore_docs
8+
79
try:
810
from scrapy.settings import Settings # noqa: TCH002
911
from scrapy.utils.project import get_project_settings
@@ -18,13 +20,15 @@
1820
nested_event_loop: asyncio.AbstractEventLoop = asyncio.new_event_loop()
1921

2022

23+
@ignore_docs
2124
def get_basic_auth_header(username: str, password: str, auth_encoding: str = 'latin-1') -> bytes:
2225
"""Generate a basic authentication header for the given username and password."""
2326
string = f'{unquote(username)}:{unquote(password)}'
2427
user_pass = to_bytes(string, encoding=auth_encoding)
2528
return b'Basic ' + b64encode(user_pass)
2629

2730

31+
@ignore_docs
2832
def get_running_event_loop_id() -> int:
2933
"""Get the ID of the currently running event loop.
3034

website/pydoc-markdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ loaders:
44
processors:
55
- type: filter
66
skip_empty_modules: true
7+
documented_only: false
78
- type: crossref
89
renderer:
910
type: docusaurus

website/transformDocs.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,9 @@ const TYPEDOC_KINDS = {
5757
}
5858

5959
const GROUP_ORDER = [
60-
'Main Classes',
61-
'Main Clients',
62-
'Resource Clients',
63-
'Async Resource Clients',
64-
'Helper Classes',
65-
'Errors',
66-
'Constructors',
67-
'Methods',
68-
'Properties',
60+
'Classes',
61+
'Data structures',
62+
'Scrapy Integration',
6963
'Constants',
7064
'Enumeration Members'
7165
];
@@ -79,22 +73,23 @@ const groupSort = (g1, g2) => {
7973

8074
function getGroupName(object) {
8175
const groupPredicates = {
76+
'Scrapy integration': (x) => ['ApifyScheduler', 'ActorDatasetPushPipeline', 'ApifyHttpProxyMiddleware', 'apply_apify_settings'].includes(x.name),
77+
'Data structures': (x) => ['BaseModel', 'TypedDict'].some(base => x?.bases?.includes(base)) || x?.decorations?.some(d => d.name === 'dataclass'),
8278
'Errors': (x) => x.name.toLowerCase().includes('error'),
83-
'Main Classes': (x) => ['Actor', 'Dataset', 'KeyValueStore', 'RequestQueue'].includes(x.name),
79+
'Classes': (x) => x.kindString === 'Class',
8480
'Main Clients': (x) => ['ApifyClient', 'ApifyClientAsync'].includes(x.name),
8581
'Async Resource Clients': (x) => x.name.toLowerCase().includes('async'),
8682
'Resource Clients': (x) => x.kindString === 'Class' && x.name.toLowerCase().includes('client'),
87-
'Helper Classes': (x) => x.kindString === 'Class',
8883
'Methods': (x) => x.kindString === 'Method',
8984
'Constructors': (x) => x.kindString === 'Constructor',
9085
'Properties': (x) => x.kindString === 'Property',
9186
'Constants': (x) => x.kindString === 'Enumeration',
92-
'Enumeration Members': (x) => x.kindString === 'Enumeration Member',
87+
'Enumeration members': (x) => x.kindString === 'Enumeration Member',
9388
};
9489

9590
const [group] = Object.entries(groupPredicates).find(
9691
([_, predicate]) => predicate(object)
97-
);
92+
) ?? ['Other'];
9893

9994
return group;
10095
}
@@ -162,7 +157,8 @@ function extractArgsAndReturns(docstring) {
162157

163158
// Objects with decorators named 'ignore_docs' or with empty docstrings will be ignored
164159
function isHidden(member) {
165-
return member.decorations?.some(d => d.name === 'ignore_docs') || member.name === 'ignore_docs' || !member.docstring?.content;
160+
return member.decorations?.some(d => d.name === 'ignore_docs')
161+
|| member.name === 'ignore_docs';
166162
}
167163

168164
// Each object in the Typedoc structure has an unique ID,
@@ -207,13 +203,22 @@ function convertObject(obj, parent, module) {
207203
moduleName = moduleShortcuts[fullName].replace(`.${member.name}`, '');
208204
}
209205

206+
if(member.name === 'Actor' || (member.name.endsWith('Client') && !member.name.endsWith('StorageClient')) || member.name === 'ListPage') {
207+
continue;
208+
}
209+
210+
if (member.name === '_ActorType') {
211+
member.name = 'Actor';
212+
}
213+
210214
// Create the Typedoc member object
211215
let typedocMember = {
212216
id: oid++,
213217
name: member.name,
214218
module: moduleName, // This is an extension to the original Typedoc structure, to support showing where the member is exported from
215219
...typedocKind,
216220
flags: {},
221+
bases: member.bases,
217222
comment: member.docstring ? {
218223
summary: [{
219224
kind: 'text',
@@ -231,6 +236,10 @@ function convertObject(obj, parent, module) {
231236
}],
232237
};
233238

239+
if(!GROUP_ORDER.includes(getGroupName(typedocMember)) && parent.kindString === 'Project'){
240+
continue;
241+
}
242+
234243
if(typedocMember.kindString === 'Method') {
235244
const { parameters, returns } = extractArgsAndReturns(member.docstring?.content ?? '');
236245

0 commit comments

Comments
 (0)