Skip to content

Commit 21ce626

Browse files
committed
Fix EDoc documentation syntax errors
- Remove deprecated @type tags (use -type attributes instead) - Replace Markdown backticks with plain text - Convert Markdown lists to EDoc HTML lists - Simplify code examples in module docs
1 parent 7599a63 commit 21ce626

3 files changed

Lines changed: 61 additions & 111 deletions

File tree

src/py_asgi.erl

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,35 @@
1717
%%% This module provides high-performance ASGI request handling by using
1818
%%% optimized C-level marshalling between Erlang and Python:
1919
%%%
20-
%%% - **Interned keys**: ASGI scope keys are pre-interned Python strings,
21-
%%% eliminating per-request string allocation and hashing overhead.
22-
%%%
23-
%%% - **Cached constants**: Common values like `"http"`, `"1.1"`, `"GET"`,
24-
%%% etc. are reused across requests.
25-
%%%
26-
%%% - **Response pooling**: Pre-allocated response structures reduce
27-
%%% memory allocation during request processing.
28-
%%%
29-
%%% - **Direct NIF path**: Bypasses generic py:call() for ASGI-specific
30-
%%% optimizations.
20+
%%% <ul>
21+
%%% <li>Interned keys: ASGI scope keys are pre-interned Python strings,
22+
%%% eliminating per-request string allocation and hashing overhead.</li>
23+
%%% <li>Cached constants: Common values like "http", "1.1", "GET",
24+
%%% etc. are reused across requests.</li>
25+
%%% <li>Response pooling: Pre-allocated response structures reduce
26+
%%% memory allocation during request processing.</li>
27+
%%% <li>Direct NIF path: Bypasses generic py:call() for ASGI-specific
28+
%%% optimizations.</li>
29+
%%% </ul>
3130
%%%
3231
%%% == Performance ==
3332
%%%
34-
%%% Compared to generic py:call()-based ASGI handling:
35-
%%%
36-
%%% | Optimization | Improvement |
37-
%%% |--------------|-------------|
38-
%%% | Interned keys | +15-20% throughput |
39-
%%% | Response pooling | +20-25% throughput |
40-
%%% | Direct NIF | +25-30% throughput |
41-
%%% | **Total** | ~60-80% improvement |
33+
%%% Compared to generic py:call()-based ASGI handling, this module
34+
%%% provides approximately 60-80% throughput improvement through
35+
%%% interned keys (+15-20%), response pooling (+20-25%), and
36+
%%% direct NIF path (+25-30%).
4237
%%%
4338
%%% == Usage ==
4439
%%%
45-
%%% ```erlang
46-
%%% %% Build ASGI scope from Cowboy request
40+
%%% ```
4741
%%% Scope = #{
4842
%%% type => <<"http">>,
49-
%%% http_version => <<"1.1">>,
5043
%%% method => <<"GET">>,
51-
%%% scheme => <<"http">>,
52-
%%% path => <<"/api/users">>,
53-
%%% query_string => <<"id=123">>,
54-
%%% headers => [[<<"host">>, <<"localhost:8080">>]],
55-
%%% server => {<<"localhost">>, 8080},
56-
%%% client => {<<"127.0.0.1">>, 54321}
44+
%%% path => <<"/api/users">>
5745
%%% },
58-
%%%
59-
%%% %% Execute ASGI application
6046
%%% case py_asgi:run(<<"myapp">>, <<"application">>, Scope, Body) of
61-
%%% {ok, {Status, Headers, ResponseBody}} ->
62-
%%% %% Send response
63-
%%% cowboy_req:reply(Status, Headers, ResponseBody, Req);
64-
%%% {error, Reason} ->
65-
%%% %% Handle error
66-
%%% cowboy_req:reply(500, #{}, <<"Internal Server Error">>, Req)
47+
%%% {ok, {Status, Headers, ResponseBody}} -> ok;
48+
%%% {error, Reason} -> error
6749
%%% end.
6850
%%% '''
6951
%%%
@@ -82,21 +64,6 @@
8264
scope_opts/0
8365
]).
8466

85-
%% @type scope() = #{
86-
%% type := binary(),
87-
%% asgi => #{version => binary(), spec_version => binary()},
88-
%% http_version => binary(),
89-
%% method => binary(),
90-
%% scheme => binary(),
91-
%% path := binary(),
92-
%% raw_path => binary(),
93-
%% query_string => binary(),
94-
%% root_path => binary(),
95-
%% headers => [[binary()]],
96-
%% server => {binary(), integer()},
97-
%% client => {binary(), integer()},
98-
%% state => map()
99-
%% }.
10067
%% ASGI scope dictionary.
10168
-type scope() :: #{
10269
type := binary(),
@@ -115,10 +82,6 @@
11582
extensions => map()
11683
}.
11784

118-
%% @type scope_opts() = #{
119-
%% state => map(),
120-
%% extensions => map()
121-
%% }.
12285
%% Options for scope building.
12386
-type scope_opts() :: #{
12487
state => map(),
@@ -143,7 +106,9 @@ run(Module, Callable, Scope, Body) ->
143106
%% @doc Execute an ASGI application with options.
144107
%%
145108
%% Additional options:
146-
%% - `timeout` - Request timeout in milliseconds (default: 30000)
109+
%% <ul>
110+
%% <li>runner - Custom Python runner module name</li>
111+
%% </ul>
147112
%%
148113
%% @param Module Python module containing the ASGI application
149114
%% @param Callable Name of the ASGI callable

src/py_nif.erl

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -756,21 +756,22 @@ asgi_build_scope(_ScopeMap) ->
756756
%% @doc Execute an ASGI application with optimized marshalling.
757757
%%
758758
%% This is a direct NIF that bypasses the generic py:call() path:
759-
%% - Builds scope dict using interned keys
760-
%% - Uses response pooling
761-
%% - Runs the ASGI app coroutine synchronously
759+
%% <ul>
760+
%% <li>Builds scope dict using interned keys</li>
761+
%% <li>Uses response pooling</li>
762+
%% <li>Runs the ASGI app coroutine synchronously</li>
763+
%% </ul>
762764
%%
763-
%% Requires the `hornbeam_asgi_runner` Python module to be available,
764-
%% which provides the `_run_asgi_sync` function that handles the
765+
%% Requires the hornbeam_asgi_runner Python module to be available,
766+
%% which provides the _run_asgi_sync function that handles the
765767
%% ASGI receive/send protocol.
766768
%%
767-
%% @param Runner Python runner module name (e.g., <<"hornbeam_asgi_runner">>)
768-
%% @param Module Application module name (e.g., <<"myapp.asgi">>)
769-
%% @param Callable ASGI callable name (e.g., <<"application">>)
769+
%% @param Runner Python runner module name
770+
%% @param Module Application module name
771+
%% @param Callable ASGI callable name
770772
%% @param ScopeMap Erlang map containing ASGI scope (see asgi_build_scope/1)
771773
%% @param Body Request body as binary
772-
%% @returns {ok, {Status, Headers, Body}} on success,
773-
%% or {error, Reason}
774+
%% @returns {ok, {Status, Headers, Body}} on success, or {error, Reason}
774775
-spec asgi_run(binary(), binary(), binary(), map(), binary()) ->
775776
{ok, {integer(), [{binary(), binary()}], binary()}} | {error, term()}.
776777
asgi_run(_Runner, _Module, _Callable, _ScopeMap, _Body) ->
@@ -783,20 +784,21 @@ asgi_run(_Runner, _Module, _Callable, _ScopeMap, _Body) ->
783784
%% @doc Execute a WSGI application with optimized marshalling.
784785
%%
785786
%% This is a direct NIF that bypasses the generic py:call() path:
786-
%% - Builds environ dict using interned keys
787-
%% - Uses cached constant values
788-
%% - Runs the WSGI app synchronously
787+
%% <ul>
788+
%% <li>Builds environ dict using interned keys</li>
789+
%% <li>Uses cached constant values</li>
790+
%% <li>Runs the WSGI app synchronously</li>
791+
%% </ul>
789792
%%
790-
%% Requires the `hornbeam_wsgi_runner` Python module to be available,
791-
%% which provides the `_run_wsgi_sync` function that handles the
793+
%% Requires the hornbeam_wsgi_runner Python module to be available,
794+
%% which provides the _run_wsgi_sync function that handles the
792795
%% WSGI start_response protocol.
793796
%%
794-
%% @param Runner Python runner module name (e.g., <<"hornbeam_wsgi_runner">>)
795-
%% @param Module Application module name (e.g., <<"myapp.wsgi">>)
796-
%% @param Callable WSGI callable name (e.g., <<"application">>)
797+
%% @param Runner Python runner module name
798+
%% @param Module Application module name
799+
%% @param Callable WSGI callable name
797800
%% @param EnvironMap Erlang map containing WSGI environ
798-
%% @returns {ok, {Status, Headers, Body}} on success,
799-
%% or {error, Reason}
801+
%% @returns {ok, {Status, Headers, Body}} on success, or {error, Reason}
800802
-spec wsgi_run(binary(), binary(), binary(), map()) ->
801803
{ok, {binary(), [{binary(), binary()}], binary()}} | {error, term()}.
802804
wsgi_run(_Runner, _Module, _Callable, _EnvironMap) ->

src/py_wsgi.erl

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,31 @@
1717
%%% This module provides high-performance WSGI request handling by using
1818
%%% optimized C-level marshalling between Erlang and Python:
1919
%%%
20-
%%% - **Interned keys**: WSGI environ keys are pre-interned Python strings,
21-
%%% eliminating per-request string allocation and hashing overhead.
22-
%%%
23-
%%% - **Cached constants**: Common values like `"GET"`, `"HTTP/1.1"`,
24-
%%% etc. are reused across requests.
25-
%%%
26-
%%% - **Direct NIF path**: Bypasses generic py:call() for WSGI-specific
27-
%%% optimizations.
20+
%%% <ul>
21+
%%% <li>Interned keys: WSGI environ keys are pre-interned Python strings,
22+
%%% eliminating per-request string allocation and hashing overhead.</li>
23+
%%% <li>Cached constants: Common values like "GET", "HTTP/1.1",
24+
%%% etc. are reused across requests.</li>
25+
%%% <li>Direct NIF path: Bypasses generic py:call() for WSGI-specific
26+
%%% optimizations.</li>
27+
%%% </ul>
2828
%%%
2929
%%% == Performance ==
3030
%%%
31-
%%% Compared to generic py:call()-based WSGI handling:
32-
%%%
33-
%%% | Optimization | Improvement |
34-
%%% |--------------|-------------|
35-
%%% | Interned keys | +15-20% throughput |
36-
%%% | Direct NIF | +25-30% throughput |
37-
%%% | **Total** | ~60-80% improvement |
31+
%%% Compared to generic py:call()-based WSGI handling, this module
32+
%%% provides approximately 60-80% throughput improvement through
33+
%%% interned keys (+15-20%) and direct NIF path (+25-30%).
3834
%%%
3935
%%% == Usage ==
4036
%%%
41-
%%% ```erlang
42-
%%% %% Build WSGI environ from Cowboy request
37+
%%% ```
4338
%%% Environ = #{
4439
%%% <<"REQUEST_METHOD">> => <<"GET">>,
45-
%%% <<"SCRIPT_NAME">> => <<>>,
46-
%%% <<"PATH_INFO">> => <<"/api/users">>,
47-
%%% <<"QUERY_STRING">> => <<"id=123">>,
48-
%%% <<"SERVER_NAME">> => <<"localhost">>,
49-
%%% <<"SERVER_PORT">> => <<"8080">>,
50-
%%% <<"SERVER_PROTOCOL">> => <<"HTTP/1.1">>,
51-
%%% <<"wsgi.url_scheme">> => <<"http">>,
52-
%%% <<"wsgi.input">> => Body
40+
%%% <<"PATH_INFO">> => <<"/api/users">>
5341
%%% },
54-
%%%
55-
%%% %% Execute WSGI application
5642
%%% case py_wsgi:run(<<"myapp">>, <<"application">>, Environ) of
57-
%%% {ok, {Status, Headers, ResponseBody}} ->
58-
%%% %% Send response
59-
%%% StatusCode = parse_status(Status),
60-
%%% cowboy_req:reply(StatusCode, Headers, ResponseBody, Req);
61-
%%% {error, Reason} ->
62-
%%% cowboy_req:reply(500, #{}, <<"Internal Server Error">>, Req)
43+
%%% {ok, {Status, Headers, ResponseBody}} -> ok;
44+
%%% {error, Reason} -> error
6345
%%% end.
6446
%%% '''
6547
%%%
@@ -75,7 +57,6 @@
7557
environ/0
7658
]).
7759

78-
%% @type environ() = #{binary() => binary() | integer() | atom()}.
7960
%% WSGI environ dictionary.
8061
-type environ() :: #{
8162
binary() => binary() | integer() | atom()
@@ -98,7 +79,9 @@ run(Module, Callable, Environ) ->
9879
%% @doc Execute a WSGI application with options.
9980
%%
10081
%% Additional options:
101-
%% - `runner` - Python runner module name (default: <<"hornbeam_wsgi_runner">>)
82+
%% <ul>
83+
%% <li>runner - Python runner module name (default: hornbeam_wsgi_runner)</li>
84+
%% </ul>
10285
%%
10386
%% @param Module Python module containing the WSGI application
10487
%% @param Callable Name of the WSGI callable

0 commit comments

Comments
 (0)