Fix: sphinx warning about bad reference

This commit is contained in:
Vincent Botbol 2018-03-14 11:21:34 +01:00 committed by Benjamin Canou
parent 8441e0c7a0
commit 369b6d7988
3 changed files with 39 additions and 95 deletions

View File

@ -70,7 +70,7 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path # This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'usage.rst'] exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'doc_gen']
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'

View File

@ -7,12 +7,6 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
(* let example_args_completions =
* [ ("<block_id>", [ ("head", 0.8) ; ("head~1", 0.1) ; ("genesis", 0.1) ]) ;
* ("<point>", [ ("127.0.0.1:18731", 1.) ]) ;
* ("<hash.Crypto_box.Public_key_hash>", [ ]);
* ] *)
(* Utility functions *) (* Utility functions *)
exception Unsupported_construct exception Unsupported_construct
@ -146,43 +140,42 @@ let make_descr = function
let repr_of_service path let repr_of_service path
RPC_description.{ description ; error ; RPC_description.{ description ; error ;
meth ; input ; output ; _ } : service_repr= meth ; input ; output ; _ } : service_repr=
(* TODO? : check that json schema are not empty *)
(* let escape_html_string str = (* let escape_html_string str =
* let open Stringext in * let open Stringext in
* let str = replace_all str "<" "&lt;" in * let str = replace_all str ~pattern:"<" ~with_:"&lt;" in
* replace_all str ">" "&gt;" * replace_all str ~pattern:">" ~with_:"&gt;"
* in * in
* *
* let example = begin * let example = begin
* try
* match input with * match input with
* | None -> None * | None -> None
* | Some input when input = Json_schema.any -> None
* | Some input -> begin * | Some input -> begin
* let path = List.map escape_html_string path |> String.concat "/" in
* Printf.eprintf "%s\n%!" path;
* let json = random_fill_in ~show_optionals:true input in * let json = random_fill_in ~show_optionals:true input in
* (\* curl -X METH -H "Content-type: application/json" http://<address>:<port><path> -d '<schema>' *\)
*
* let tezos_client_cmd_example = * let tezos_client_cmd_example =
* Format.asprintf "tezos-client rpc call /%s with '%s'" * Format.sprintf "tezos-client rpc call /%s with '%s'"
* (String.concat "/" path |> escape_html_string) * path
* (Data_encoding.Json.to_string ~minify:true json) * (Data_encoding.Json.to_string ~minify:true json)
* in * in
* let curl_cmd_example = * let curl_cmd_example =
* Format.asprintf "curl -X %s -H \"Content-type: application/json\" http://&lt;address&gt;:&lt;port&gt;/%s -d '%s'" * Format.sprintf "curl -X %s -H \"Content-type: application/json\" http://%s/%s -d '%s'"
* (RPC_service.string_of_meth meth) * (RPC_service.string_of_meth meth)
* (String.concat "/" path |> escape_html_string) * "127.0.0.1:18731"
* path
* (Data_encoding.Json.to_string ~minify:true json) * (Data_encoding.Json.to_string ~minify:true json)
* in * in
* let open Format in * let open Format in
*
* Some ( * Some (
* List.fold_left (fun acc s -> * List.fold_left (fun acc s ->
* (Format.sprintf "<div class=\"cmdline\">%s</div>" s) :: acc) * (Format.sprintf "<div class=\"cmdline\">%s</div>" s) :: acc)
* [] [tezos_client_cmd_example ; curl_cmd_example] * [] [ curl_cmd_example ; tezos_client_cmd_example ]
* |> List.rev |> String.concat "or" * |> String.concat "or"
* ) * )
* *
* end * end
* with | Unsupported_construct -> None
* end in *) * end in *)
{ path ; meth ; { path ; meth ;
@ -232,15 +225,16 @@ let pp_print_collected_args ppf () =
(function (function
| { name ; descr=Some d } -> | { name ; descr=Some d } ->
fprintf ppf "@[<v 2>**<%s>** : @[%s@]@]@ @ " name d; fprintf ppf "@[<v 2>**<%s>** : @[%s@]@]@ @ " name d;
| { name=_ ; _ } -> () (* Should we print it anyway ? *) | { descr=None ; _ } -> assert false
) )
(List.rev !collected_args); (List.rev !collected_args);
fprintf ppf "@]" fprintf ppf "@]"
let make_tree cctxt path = let make_tree cctxt path =
(* TODO : discuss about automatic example generation *)
let collect arg = let collect arg =
if not (arg.RPC_arg.descr <> None && List.mem arg !collected_args) then if not (arg.RPC_arg.descr = None ||
(List.exists (fun { Resto.Arg.name } -> name = arg.name)
!collected_args)) then
collected_args := arg :: !collected_args collected_args := arg :: !collected_args
in in
let open RPC_description in let open RPC_description in
@ -593,18 +587,16 @@ let run ?(rpc_port=18731) () =
(* Page title *) (* Page title *)
fprintf ppf "%a" pp_print_rst_h1 "Tezos RPCs"; fprintf ppf "%a" pp_print_rst_h1 "Tezos RPCs";
(* include/copy usage.rst from input *) (* include/copy usage.rst from input *)
let rec loop () = Lwt_io.(read stdin) >>= fun s ->
let s = read_line () in
fprintf ppf "%s@\n" s; fprintf ppf "%s@\n" s;
loop () Lwt.return ()
in begin try loop () with End_of_file -> () end
in in
(make_tree cctxt [] >>= function (make_tree cctxt [] >>= function
| Ok service_tree -> | Ok service_tree ->
(* Print header!! *) (* Print header!! *)
fprintf ppf "@\n"; fprintf ppf "@\n";
print_header (); print_header () >>= fun () ->
fprintf ppf "@\n"; fprintf ppf "@\n";
(* Shell RPCs tree *) (* Shell RPCs tree *)
@ -623,7 +615,6 @@ let run ?(rpc_port=18731) () =
begin begin
make_tree cctxt path_proto_alpha >>= function make_tree cctxt path_proto_alpha >>= function
| Ok service_tree -> | Ok service_tree ->
(* TODO : replace head by <block_id> ? *)
(* Proto alpha RPCs tree *) (* Proto alpha RPCs tree *)
fprintf ppf "%a@." (pp_print_rst_hierarchy ~title:"Protocol Alpha RPCs - Index") service_tree; fprintf ppf "%a@." (pp_print_rst_hierarchy ~title:"Protocol Alpha RPCs - Index") service_tree;
fprintf ppf "%a" pp_print_rst_h2 "Protocol Alpha RPCs - Full description"; fprintf ppf "%a" pp_print_rst_h2 "Protocol Alpha RPCs - Full description";
@ -637,7 +628,6 @@ let run ?(rpc_port=18731) () =
end; end;
Lwt.return 0 Lwt.return 0
(* TODO : add dynamic parameter description *)
| Error _ -> | Error _ ->
Format.fprintf err_ppf "[RPC Doc Generation] Proto alpha : Couldn't reach node\n"; Format.fprintf err_ppf "[RPC Doc Generation] Proto alpha : Couldn't reach node\n";

View File

@ -538,52 +538,6 @@ module Make(Prefix : sig val id : string end) = struct
(Format.pp_print_list pp) (Format.pp_print_list pp)
(List.rev errors) (List.rev errors)
(** Catch all error when 'serializing' an error. *)
type error += Unclassified of string
let () =
let id = "" in
let category = `Temporary in
let to_error msg = Unclassified msg in
let from_error = function
| Unclassified msg -> Some msg
| error ->
let msg = Obj.(extension_name @@ extension_constructor error) in
Some ("Unclassified error: " ^ msg ^ ". Was the error registered?") in
let title = "Generic error" in
let description = "An unclassified error" in
let encoding_case =
let open Data_encoding in
case Json_only
(describe ~title ~description @@
conv (fun x -> ((), x)) (fun ((), x) -> x) @@
(obj2
(req "kind" (constant "generic"))
(req "error" string)))
from_error to_error in
let pp = Format.pp_print_string in
error_kinds :=
Error_kind { id ; from_error ; category ; encoding_case ; pp } :: !error_kinds
(** Catch all error when 'deserializing' an error. *)
type error += Unregistered_error of Data_encoding.json
let () =
let id = "" in
let category = `Temporary in
let to_error msg = Unregistered_error msg in
let from_error = function
| Unregistered_error json -> Some json
| _ -> None in
let encoding_case =
let open Data_encoding in
case Json_only json from_error to_error in
let pp ppf json =
Format.fprintf ppf "@[<v 2>Unregistered error:@ %a@]"
Data_encoding.Json.pp json in
error_kinds :=
Error_kind { id ; from_error ; category ; encoding_case ; pp } :: !error_kinds
type error += Assert_error of string * string type error += Assert_error of string * string
let () = let () =