text stringlengths 0 601k |
|---|
let issues_uri p = Topkg_care_pkg . opam_field p " dev - repo " >>| function |
let issue_list p = issues_uri p >>= fun issues_uri -> run_delegate p Cmd ( . v " issue " % " list " % issues_uri ) issues_uri |
let issue_show p ~ id = issues_uri p >>= fun issues_uri -> run_delegate p Cmd ( . v " issue " % " show " % issues_uri % " id ) " |
let issue_open p ~ title ~ body = issues_uri p >>= fun issues_uri -> match run_delegate p Cmd ( . v " issue " % " open " % issues_uri % title % body ) body with | Ok _ as v -> v | Error _ as e -> let pp_body ppf = function " " -> ( ) | body -> Fmt . pf ppf " , , @@% s " body in Logs . app ( fun m -> m [ " @< v > Your o... |
let issue_close p ~ id ~ msg = issues_uri p >>= fun issues_uri -> match run_delegate p Cmd ( . v " issue " % " close " % issues_uri % id % msg ) msg with | Ok _ as v -> v | Error _ as e -> Logs . app ( fun m -> m [ " @< v > Your closing message was , , :@---@% s ] " @ msg ) msg ; e |
let ocaml = Cmd . of_list @@ Topkg . Cmd . to_list @@ Topkg . Conf . tool " ocaml " ` Build_os |
let pkg_must_exist pkg_file = match OS . File . must_exist pkg_file with let p = match OS . Dir . current ( ) with | Error _ -> pkg_file | Ok dir -> Fpath ( . dir // pkg_file ) pkg_file in R . error_msgf " Not a package : no file % a " Fpath . pp p |
let ask ~ pkg_file ipc = let codec = Topkg . Private . Ipc . codec ipc in let verbosity = Logs ( . level_to_string ( level ( ) ) ) in let ipc_cmd = Cmd . of_list @@ Topkg . Cmd . to_list @@ Topkg . Private . Ipc . cmd ipc in let cmd = Cmd ( . ocaml % p pkg_file % " ipc " % verbosity %% ipc_cmd ) ipc_cmd in pkg_must_exi... |
let cmd = Cmd . of_list @@ Topkg . Cmd . to_list @@ Topkg . Conf . tool " ocamlbuild " ` Host_os |
let find_packages ~ roots s = let package = String . sub " package ( package " in let not_rpar c = not ( Char . equal ' ) ' ' c ) c in let not_dot c = not ( Char . equal ' . ' c ) c in let is_comma c = Char . equal ' , ' c in let is_sep c = Char . Ascii . is_white c || is_comma c in let rec loop acc s = match String . ... |
let package_tags ( ? roots = false ) false file = OS . File . read file >>= fun contents -> Ok ( find_packages ~ roots contents ) contents |
let cmd = Cmd . of_list @@ Topkg . Cmd . to_list @@ Topkg . Conf . tool " opam " ` Host_os |
let publish = let absent = Cmd ( . v " opam - publish ) " in OS . Env ( . value " TOPKG_OPAM_PUBLISH " cmd ~ absent ) absent |
let ensure_publish ( ) = OS . Cmd . must_exist publish >>= fun cmd -> OS . Cmd . run_out Cmd ( . publish % " -- version ) " |> OS . Cmd . out_string >>= fun ( version , _ ) _ -> match Topkg . String . parse_version version with | None -> R . error_msgf " Could not determine the version of opam - publish " | Some ( m , ... |
let submit ? msg ~ opam_file = let msg = match msg with | None -> Ok ( Cmd . empty ) empty | Some msg -> OS . File . tmp " topkg - opam - submit - msg -% s " >>= fun m -> OS . File . write m msg >>= fun ( ) -> Ok Cmd ( . v " -- msg - file " % p m ) m in msg >>= fun msg -> OS . Cmd . run Cmd ( . publish %% msg % p opam_... |
let ocaml_base_packages = String . Set . of_list [ " base - bigarray " ; " base - bytes " ; " base - threads " ; " base - unix " ; ] |
module File = struct let id x = x let list f = fun v -> [ f v ] v let field name field conv = name , fun acc o -> String . Map . add name ( conv ( field o ) o ) o acc let opt_field name field conv = name , fun acc o -> match field o with | None -> acc | Some v -> String . Map . add name ( conv v ) v acc let deps_conv d... |
module Descr = struct type t = string * string let of_string s = match String . cuts ~ sep " :\ n " s with | [ ] -> R . error_msgf " Cannot extract opam descr . " | synopsis :: descr -> Ok ( synopsis , String . concat ~ sep " :\ n " descr ) descr let to_string ( synopsis , descr ) descr = strf " % s \ n % s " synopsis ... |
module Url = struct type t = string let v ~ uri ~ checksum = strf " archive : " \% s " \\ nchecksum : " \% s " " \ uri checksum let with_distrib_file ~ uri distrib_file = try let checksum = Digest ( . to_hex @@ file ( Fpath . to_string distrib_file ) distrib_file ) distrib_file in Ok ( v ~ uri ~ checksum ) checksum wit... |
let path_set_of_strings ps = try let add_excl acc p = match Fpath . of_string p with | Error ( ` Msg msg ) msg -> failwith msg | Ok p -> Fpath . Set . add p acc in Ok ( List . fold_left add_excl Fpath . Set . empty ps ) ps with Failure msg -> R . error_msg msg |
let rec path_list_of_strings ps = let rec loop acc = function | [ ] -> Ok ( List . rev acc ) acc | p :: ps -> match Fpath . of_string p with | Error _ as e -> e | Ok p -> loop ( p :: acc ) acc ps in loop [ ] ps |
let uri_sld uri = match Topkg_care_text . split_uri uri with match List . rev ( String . cuts ~ sep " . " : host ) host with | fst :: snd :: _ -> Some snd | _ -> None |
let uri_append u s = match String . head ~ rev : true u with |
let chop_ext u = match String . cut ~ rev : true ~ sep " . " : u with |
let chop_git_prefix u = match String . cut ~ sep " : git " + u with |
type t = { name : string option ; version : string option ; delegate : Cmd . t option ; build_dir : Fpath . t option ; opam : Fpath . t option ; opam_descr : Fpath . t option ; opam_fields : ( string list String . map , R . msg ) msg result Lazy . t ; readmes : Fpath . t list option ; change_logs : Fpath . t list optio... |
let empty p = { p with pkg = lazy ( Ok ( Topkg . Private . Pkg . empty ) empty ) empty } |
let pkg p = Lazy . force p . pkg |
let opam_fields p = Lazy . force p . opam_fields |
let opam_field p f = opam_fields p >>| fun fields -> String . Map . find f fields |
let opam_field_hd p f = opam_field p f >>| function |
let opam_homepage_sld p = opam_field_hd p " homepage " >>| function |
let pkg_file p = p . pkg_file |
let name p = match p . name with |
let version p = match p . version with |
let delegate p = let not_found ( ) = R . error_msg " No package delegate found . \ Try ` topkg help delegate ` for more information . " in match p . delegate with | Some cmd -> Ok cmd | None -> pkg p >>| Topkg . Private . Pkg . delegate >>= function | Some cmd -> Ok ( Cmd . of_list @@ Topkg . Cmd . to_list cmd ) cmd | ... |
let build_dir p = match p . build_dir with |
let readmes p = match p . readmes with |
let readme p = readmes p >>= function |
let opam p = match p . opam with name p >>= fun name -> pkg p >>| Topkg . Private . Pkg . opam ~ name >>= Fpath . of_string |
let opam_field_descr p = opam_field p " synopsis " >>= function | None -> Ok None | Some syn -> opam_field p " description " >>= function | None -> Ok None | Some descr -> Ok ( Some ( List . hd syn , List . hd descr ) descr ) descr |
let opam_descr p = let descr_file_for_opam opam = if Fpath . has_ext " . opam " opam then Fpath ( . rem_ext opam + " . descr ) " else Fpath ( . parent opam / " descr ) " in let read f = OS . File . read f >>= fun c -> Topkg_care_opam . Descr . of_string c >>| fun d -> d , false in match p . opam_descr with | Some f -> ... |
let change_logs p = match p . change_logs with |
let change_log p = change_logs p >>= function |
let licenses p = match p . licenses with |
let distrib_uri ( ? raw = false ) false p = let subst_uri p uri = uri >>= fun uri -> name p >>= fun name -> version p >>= fun version -> Ok ( Topkg . String . drop_initial_v version ) version >>= fun version_num -> let defs = String . Map ( . empty |> add " NAME " name |> add " VERSION " version |> add " VERSION_NUM " ... |
let distrib_filename ( ? opam = false ) false p = let sep = if opam then ' . ' else ' - ' in name p >>= fun name -> version p >>= fun version -> Ok ( Topkg . String . drop_initial_v version ) version >>= fun version_num -> Fpath . of_string ( strf " % s % c % s " name sep version_num ) version_num |
let distrib_archive_path p = build_dir p >>= fun build_dir -> distrib_filename ~ opam : false p >>| fun b -> Fpath ( . build_dir // b + " . tbz ) " |
let distrib_file p = match p . distrib_file with ( distrib_archive_path p >>= fun f -> OS . File . must_exist f ) f |> R . reword_error_msg ( fun _ -> R . msgf " Did you forget to call ' topkg distrib ' ) " ? |
let publish_msg p = match p . publish_msg with change_log p >>= fun change_log -> Topkg_care_text . change_log_file_last_entry change_log >>= fun ( _ , ( h , txt ) txt ) txt -> Ok ( strf " % s \ n % s " h txt ) txt |
let publish_artefacts p = match p . publish_artefacts with |
let v ? name ? version ? delegate ? build_dir ? opam : opam_file ? opam_descr ? readme ? change_log ? license ? distrib_uri ? distrib_file ? publish_msg ? publish_artefacts pkg_file = let readmes = match readme with Some r -> Some [ r ] r | None -> None in let change_logs = match change_log with Some c -> Some [ c ] c ... |
let distrib_prepare_ipc p ~ dist_build_dir ~ name ~ version ~ opam ~ opam_adds = let dist_build_dir = Fpath . to_string dist_build_dir in let opam = Fpath . to_string opam in R . join @@ Topkg_care_ipc . ask ~ pkg_file : p . pkg_file ( Topkg . Private . Ipc . distrib_prepare ~ dist_build_dir ~ name ~ version ~ opam ~ o... |
let distrib_archive p ~ keep_dir = Topkg_care_archive . ensure_bzip2 ( ) >>= fun ( ) -> name p >>= fun name -> build_dir p >>= fun build_dir -> version p >>= fun version -> opam p >>= fun opam -> distrib_filename p >>= fun root -> Ok Fpath ( . build_dir // root + " . build ) " >>= fun dist_build_dir -> OS . Dir . delet... |
let run p ~ dir cmd ~ args ~ out = let pkg_file = p . pkg_file in let cmd = Cmd ( . v " ocaml " % p pkg_file % cmd %% args ) args in let run ( ) = OS . Cmd . run_out cmd |> out in R . join @@ OS . Dir . with_current dir run ( ) |
let test p ~ dir ~ args ~ out = run p ~ dir " test " ~ args ~ out |
let build p ~ dir ~ args ~ out = run p ~ dir " build " ~ args ~ out |
let clean p ~ dir ~ args ~ out = run p ~ dir " clean " ~ args ~ out |
let lint_log msg = Logs . info ( fun m -> m ~ header " : LINT " " % a " Fmt . text msg ) msg ; 0 |
let lint_disabled test = Logs . info ( fun m -> m ~ header " : LINT " " Package @ disabled @ % a . " Fmt . text test ) test ; 0 |
let lint_custom p = let report errs res = let status , msg , errs = match res with | Ok ( ` Msg msg ) msg -> ` Ok , msg , errs | Error ( ` Msg msg ) msg -> ` Fail , msg , errs + 1 in Logs . app ( fun m -> m " % a [ @% a ] " @ pp_status status Fmt . text msg ) msg ; errs in begin let pkg_file = p . pkg_file in pkg p >>=... |
let lint_std_files p = let lint_exists file errs = let report exists = let status , errs = if exists then ` Ok , errs else ` Fail , errs + 1 in Logs . app ( fun m -> m " % a [ @ File % a @ is @ present ] . " @ pp_status status pp_path file ) file ; errs in ( OS . File . exists file >>= fun exists -> Ok ( report exists ... |
let lint_file_with_cmd file_kind ~ cmd file errs handle_exit = let run_linter cmd file ~ exists = if not exists then Ok ( ` Fail ( strf " % a : No such file " Fpath . pp file ) file ) file else OS . Cmd ( . run_out ~ err : err_run_out Cmd ( . cmd % p file ) file |> out_string ) out_string >>| fun ( out , status ) statu... |
let lint_metas p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_metas p with | [ ] -> Ok ( lint_log " No ocamlfind META file to lint ) " | metas -> let cmd = Cmd ( . Topkg_care_ocamlfind . cmd % " lint ) " in let handle_exit status out = match status with | ` Exited 0 -> ` Ok | _ -> ` Fail out in let lin... |
let lint_opams p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_opams p with | [ ] -> Ok ( lint_log " No opam file to lint ) " | opams -> let cmd = Cmd ( . Topkg_care_opam . cmd % " lint ) " in let handle_exit file status out = match status , out with | ` Exited 0 , ( " " | " 5 " ) -> ` Ok | _ -> let err... |
let lint_deps_default_excludes = let exclude = [ " ocamlfind " ; " ocamlbuild " ; " topkg " ; " ocaml ] " in Topkg_care_ocamlfind . base_packages |> String . Set . union Topkg_care_opam . ocaml_base_packages |> String . Set . union ( String . Set . of_list exclude ) exclude |
let lint_opam_deps errs ( opam , _ , exclude ) exclude = let pp_deps_mismatches ppf ( opam_only , tags_only ) tags_only = let pp_miss present absent ppf id = Fmt . pf ppf [ " @% a : % a present but % a absent ] " @ Fmt ( . styled ` Underline string ) string id Fmt ( . styled ` Green string ) string present Fmt ( . styl... |
let lint_deps p = begin pkg p >>= fun p -> match Topkg . Private . Pkg . lint_opams p with | [ ] -> Ok ( lint_log " No opam file to dependency lint ) " | opams -> Ok ( List . fold_left lint_opam_deps 0 opams ) opams end |> Logs . on_error_msg ~ use ( : fun ( ) -> 1 ) 1 |
type lint = [ ` Custom | ` Std_files | ` Meta | ` Opam | ` Deps ] |
let lints = [ ` Custom , lint_custom ; ` Std_files , lint_std_files ; ` Meta , lint_metas ; ` Opam , lint_opams ; ` Deps , lint_deps ] |
let lint_all = List . map fst lints |
let lint ( ? ignore_pkg = false ) false p ~ dir todo = let lint pkg = let do_lint acc ( l , f ) f = acc + if List . mem l todo then f pkg else 0 in match List . fold_left do_lint 0 lints with | 0 -> Logs . app ( fun m -> m " % a lint @ % a % a " pp_status ` Ok pp_path dir ( Fmt . styled_unit ` Green " success ) " ( ) )... |
type flavour = [ ` Markdown | ` Asciidoc ] |
let flavour_of_fpath f = match String . Ascii . lowercase ( Fpath . get_ext f ) f with |
let rec drop_blanks = function " " :: ls -> drop_blanks ls | ls -> ls |
let last_line = function [ ] -> None | l :: rev_ls -> Some l |
let simple_header hchar l before rest = match String ( . length @@ take ~ sat ( : Char . equal hchar ) hchar l ) l with | 0 -> None | n -> Some ( n , l , before , rest ) rest |
let underline_header n uchar l before rest = let is_underline_header uchar l = String ( . length @@ take ~ sat ( : Char . equal uchar ) uchar l ) l >= 2 in if not ( is_underline_header uchar l ) l then None else match last_line before with | None -> None | Some t -> Some ( n , strf " % s \ n % s " t l , List . tl befor... |
let rec find_markdown_header before = function match simple_header ' # ' l before ls with | Some _ as h -> h | None -> match underline_header 1 ' = ' l before ls with | Some _ as h -> h | None -> match underline_header 2 ' - ' l before ls with | Some _ as h -> h | None -> find_markdown_header ( l :: before ) before ls |
let rec find_asciidoc_header before = function match simple_header ' = ' l before ls with | Some _ as h -> h | None -> match underline_header 1 ' - ' l before ls with | Some _ as h -> h | None -> match underline_header 2 ' ~ ' l before ls with | Some _ as h -> h | None -> match underline_header 3 ' ^ ' l before ls with... |
let head find_header text = let lines = String . cuts ~ sep " :\ n " text in let ret h acc = let contents = String . concat ~ sep " :\ n " ( List . rev @@ drop_blanks acc ) acc in Some ( h , contents ) contents in match find_header [ ] lines with | None -> None | Some ( n , first , _ , rest ) rest -> let rec loop acc r... |
let head ( ? flavour = ` Markdown ) Markdown text = match flavour with |
let header_title ( ? flavour = ` Markdown ) Markdown h = match String . cuts ~ sep " :\ n " h with begin match flavour with | ` Markdown -> String ( . trim @@ drop ~ sat ( : Char . equal ' # ' ) ' h ) h | ` Asciidoc -> String ( . trim @@ drop ~ sat ( : Char . equal ' = ' ) ' h ) h end |
let change_log_last_entry ? flavour text = match head ? flavour text with let title = header_title ? flavour h in match String . take ~ sat : Char . Ascii . is_graphic title with | " " -> Logs . app ( fun m -> m " % S % S " h changes ) changes ; None | version -> Some ( version , ( h , changes ) changes ) changes |
let change_log_file_last_entry file = let flavour = flavour_of_fpath file in OS . File . read file >>= fun text -> match change_log_last_entry ? flavour text with | None -> R . error_msgf " % a : Could not parse change log . " Fpath . pp file | Some ( version , ( header , changes ) changes ) changes -> Ok ( version , (... |
let split_uri ( ? rel = false ) false uri = match String ( . cut ~ sep " " :// ( trim uri ) uri ) uri with match String . cut ~ sep " " :/ rest with | None -> Some ( scheme , rest , ) " " | Some ( host , path ) path -> let path = if rel then path else " " / ^ path in Some ( scheme , host , path ) path |
let find_pager ~ don ' t = if don ' t then Ok None else match OS . Env . var " TERM " with | Some " dumb " | None -> Ok None | _ -> let add_env v cmds = match OS . Env ( . value v ( some cmd ) cmd ~ absent : None ) None with | None -> cmds | Some cmd -> cmd :: cmds in let cmds = [ Cmd . v " less " ; Cmd . v " more " ] ... |
let edit_file f = match OS . Env ( . value " EDITOR " ( some cmd ) cmd ~ absent : None ) None with OS . Cmd . exists editor >>= function | false -> R . error_msgf " Editor % a not in search path " Cmd . pp editor | true -> OS . Cmd ( . run_status Cmd ( . editor % p f ) f ) f >>= function | ` Exited n | ` Signaled n -> ... |
module Pp = struct let name = Fmt ( . styled ` Bold string ) string let version = Fmt ( . styled ` Cyan string ) string let commit = Fmt ( . styled ` Yellow string ) string let dirty = Fmt ( . styled_unit ` Red " dirty ) " let path = Fmt ( . styled ` Bold Fpath . pp ) pp let status ppf = function | ` Ok -> Fmt ( . brac... |
type t = string list |
let is_empty = function [ ] -> true | _ -> false |
let v a = [ a ] a |
let ( % ) l a = a :: l |
let ( %% ) l0 l1 = List . rev_append ( List . rev l1 ) l1 l0 |
let add_arg l a = l % a |
let add_args l a = l %% a |
let on bool l = if bool then l else [ ] |
let p f = f |
let equal l l ' = l = l ' |
let compare l l ' = compare l l ' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.