My own corner of monopam
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-toml: drop the unix backend

Eio is now the standard I/O story; the unix backend was a parallel
surface (file/channel I/O via stdlib in_channel/out_channel) that
nobody actually uses. Remove the lib/unix/ sublibrary, its dedicated
test suite, and update README, dune-project, doc index, and cookbook
references to point at Toml_eio.

+7 -285
-1
ocaml-toml/README.md
··· 71 71 - `nox-toml` - Core library with value types, codec combinators, and streaming 72 72 parser/encoder (on top of Bytesrw). Modules are exposed as `Toml.*`. 73 73 - `nox-toml.eio` - Eio integration with system clock (`Toml_eio`) 74 - - `nox-toml.unix` - Unix I/O with system clock (`Toml_unix`) 75 74 76 75 ## Licence 77 76
+3 -3
ocaml-toml/doc/cookbook.mld
··· 362 362 (* Force Eastern Time (-05:00 = -18000 seconds) *) 363 363 let eastern_codec = Toml.Codec.ptime ~tz_offset_s:(-18000) () 364 364 365 - (* Use system timezone (requires Toml_unix) *) 365 + (* Use system timezone (requires Toml_eio) *) 366 366 let system_codec = 367 - Toml.Codec.ptime ~get_tz:Toml_unix.current_tz_offset_s () 367 + Toml.Codec.ptime ~get_tz:Toml_eio.current_tz_offset_s () 368 368 ]} 369 369 370 370 {1:arrays Working with Arrays} ··· 745 745 746 746 {[ 747 747 let load_config path = 748 - match Toml_unix.decode_file config_codec path with 748 + match Toml_eio.decode_file config_codec path with 749 749 | Ok config -> config 750 750 | Error e -> 751 751 Printf.eprintf "Configuration error: %s\n"
+1 -1
ocaml-toml/doc/dune
··· 4 4 5 5 (mdx 6 6 (files index.mld cookbook.mld) 7 - (libraries nox-toml nox-toml.unix ptime)) 7 + (libraries nox-toml nox-toml.eio ptime))
-1
ocaml-toml/doc/index.mld
··· 43 43 - {!Toml} - Codec combinators for bidirectional TOML encoding/decoding 44 44 - {!Toml.Parser} - Streaming parser and encoder 45 45 - {!Toml_eio} - Eio-native I/O integration 46 - - {!Toml_unix} - Unix I/O integration 47 46 48 47 {2 Cookbook} 49 48
+1 -1
ocaml-toml/dune
··· 4 4 5 5 (mdx 6 6 (files README.md) 7 - (libraries nox-toml nox-toml.eio nox-toml.unix)) 7 + (libraries nox-toml nox-toml.eio))
+1 -2
ocaml-toml/dune-project
··· 19 19 inspired by Jsont. The core library provides value types, codec 20 20 combinators, and a streaming parser/encoder on top of Bytesrw. 21 21 Subpackages provide optional I/O adapters: 22 - - toml.eio: Eio integration with system clock 23 - - toml.unix: Unix I/O with system clock") 22 + - toml.eio: Eio integration with system clock") 24 23 (depends 25 24 (ocaml (>= 4.14.0)) 26 25 (fmt (>= 0.9.0))
-9
ocaml-toml/lib/unix/dune
··· 1 - (library 2 - (name toml_unix) 3 - (public_name nox-toml.unix) 4 - (optional) 5 - (libraries nox-toml bytesrw ptime.clock.os)) 6 - 7 - (mdx 8 - (files toml_unix.mli) 9 - (libraries nox-toml nox-toml.unix ptime))
-57
ocaml-toml/lib/unix/toml_unix.ml
··· 1 - (*--------------------------------------------------------------------------- 2 - Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 - SPDX-License-Identifier: ISC 4 - ---------------------------------------------------------------------------*) 5 - 6 - module Bytes = Bytesrw.Bytes 7 - 8 - (* Time utilities *) 9 - let current_tz_offset_s = Ptime_clock.current_tz_offset_s 10 - let now = Ptime_clock.now 11 - 12 - let today_date ?tz_offset_s () = 13 - let tz_offset_s = 14 - tz_offset_s 15 - |> Option.fold ~none:(current_tz_offset_s ()) ~some:Option.some 16 - |> Option.value ~default:0 17 - in 18 - Ptime.to_date ~tz_offset_s (now ()) 19 - 20 - (* Channel-based I/O *) 21 - let of_channel ?file ic = 22 - let r = Bytes.Reader.of_in_channel ic in 23 - Toml.Parser.parse_reader ?file r 24 - 25 - let to_channel oc value = 26 - let w = Bytes.Writer.of_out_channel oc in 27 - Toml.Parser.to_writer w value 28 - 29 - (* File-based I/O *) 30 - let of_file path = 31 - let ic = open_in path in 32 - Fun.protect 33 - ~finally:(fun () -> close_in ic) 34 - (fun () -> of_channel ~file:path ic) 35 - 36 - let to_file path value = 37 - let oc = open_out path in 38 - Fun.protect ~finally:(fun () -> close_out oc) (fun () -> to_channel oc value) 39 - 40 - (* Codec-based file operations *) 41 - let decode_file codec path = 42 - let toml = of_file path in 43 - Toml.decode codec toml 44 - 45 - let decode_file_exn codec path = 46 - let toml = of_file path in 47 - Toml.decode_exn codec toml 48 - 49 - let encode_file codec value path = 50 - let toml = Toml.encode codec value in 51 - to_file path toml 52 - 53 - (* Pre-configured ptime codecs with system timezone *) 54 - let ptime ?frac_s () = 55 - Toml.Codec.ptime ?frac_s ~get_tz:current_tz_offset_s ~now () 56 - 57 - let ptime_full () = Toml.Codec.ptime_full ~get_tz:current_tz_offset_s ()
-122
ocaml-toml/lib/unix/toml_unix.mli
··· 1 - (*--------------------------------------------------------------------------- 2 - Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 - SPDX-License-Identifier: ISC 4 - ---------------------------------------------------------------------------*) 5 - 6 - (** Unix integration for Toml. 7 - 8 - This module provides Unix-native functions for parsing and encoding TOML 9 - files using standard channels, with system timezone support via 10 - {{:https://erratique.ch/software/ptime}ptime.clock.os}. 11 - 12 - {2 Quick Start} 13 - 14 - {[ 15 - (* Read and decode a config file *) 16 - type config = { host : string; port : int } 17 - 18 - let config_codec = 19 - let open Toml.Codec.Table in 20 - obj (fun host port -> { host; port }) 21 - |> mem "host" Toml.Codec.string ~enc:(fun c -> c.host) 22 - |> mem "port" Toml.Codec.int ~enc:(fun c -> c.port) 23 - |> finish 24 - 25 - let run_config () = Toml_unix.decode_file_exn config_codec "config.toml" 26 - 27 - (* With datetime using system timezone *) 28 - type event = { name : string; time : Ptime.t } 29 - 30 - let event_codec = 31 - let open Toml.Codec.Table in 32 - obj (fun name time -> { name; time }) 33 - |> mem "name" Toml.Codec.string ~enc:(fun e -> e.name) 34 - |> mem "time" (Toml_unix.ptime ()) ~enc:(fun e -> e.time) 35 - |> finish 36 - ]} *) 37 - 38 - (** {1 File I/O} 39 - 40 - Read and write TOML files directly. *) 41 - 42 - val of_file : string -> Toml.Value.t 43 - (** [of_file path] reads and parses a TOML file. 44 - @raise Toml.Error.Error on parse errors. 45 - @raise Sys_error on file errors. *) 46 - 47 - val to_file : string -> Toml.Value.t -> unit 48 - (** [to_file path value] writes [value] as TOML to a file. 49 - @raise Invalid_argument if [value] is not a table. 50 - @raise Sys_error on file errors. *) 51 - 52 - (** {1 Channel I/O} 53 - 54 - Read and write TOML via standard channels. *) 55 - 56 - val of_channel : ?file:string -> in_channel -> Toml.Value.t 57 - (** [of_channel ic] reads and parses TOML from an input channel. 58 - @param file Optional filename for error messages. 59 - @raise Loc.Error on parse errors. *) 60 - 61 - val to_channel : out_channel -> Toml.Value.t -> unit 62 - (** [to_channel oc value] writes [value] as TOML to an output channel. 63 - @raise Invalid_argument if [value] is not a table. *) 64 - 65 - (** {1 Codec-Based File Operations} 66 - 67 - Decode and encode typed values directly to/from files. *) 68 - 69 - val decode_file : 'a Toml.codec -> string -> ('a, Toml.Error.t) result 70 - (** [decode_file codec path] reads a TOML file and decodes it with [codec]. 71 - @raise Sys_error on file errors. *) 72 - 73 - val decode_file_exn : 'a Toml.codec -> string -> 'a 74 - (** [decode_file_exn codec path] is like {!decode_file} but raises on errors. 75 - @raise Loc.Error on parse or decode errors. 76 - @raise Sys_error on file errors. *) 77 - 78 - val encode_file : 'a Toml.codec -> 'a -> string -> unit 79 - (** [encode_file codec value path] encodes [value] and writes to a file. 80 - @raise Sys_error on file errors. *) 81 - 82 - (** {1 Ptime Codecs with System Timezone} 83 - 84 - Pre-configured datetime codecs that use the system timezone. These are 85 - convenience wrappers around {!Toml.Codec.ptime} and {!Toml.Codec.ptime_full} 86 - with [~get_tz:current_tz_offset_s] and [~now] already applied. *) 87 - 88 - val ptime : ?frac_s:int -> unit -> Ptime.t Toml.codec 89 - (** [ptime ()] is a datetime codec using the system timezone. 90 - 91 - Equivalent to: 92 - {[ 93 - Toml.Codec.ptime ~get_tz:Toml_unix.current_tz_offset_s ~now:Toml_unix.now () 94 - ]} 95 - 96 - @param frac_s Fractional seconds to include when encoding (0-12). *) 97 - 98 - val ptime_full : unit -> Toml.Value.ptime_datetime Toml.codec 99 - (** [ptime_full ()] preserves datetime variant information using system 100 - timezone. 101 - 102 - Equivalent to: 103 - {[ 104 - Toml.Codec.ptime_full ~get_tz:Toml_unix.current_tz_offset_s () 105 - ]} *) 106 - 107 - (** {1 Time Utilities} 108 - 109 - Low-level time functions. Prefer using {!ptime} and {!ptime_full} for 110 - datetime handling. *) 111 - 112 - val current_tz_offset_s : unit -> int option 113 - (** [current_tz_offset_s ()] returns the current system timezone offset in 114 - seconds from UTC. Returns [Some offset] where positive values are east of 115 - UTC (e.g., 3600 for +01:00) and negative values are west. *) 116 - 117 - val now : unit -> Ptime.t 118 - (** [now ()] returns the current time as a [Ptime.t]. *) 119 - 120 - val today_date : ?tz_offset_s:int -> unit -> Ptime.date 121 - (** [today_date ?tz_offset_s ()] returns today's date as [(year, month, day)]. 122 - If [tz_offset_s] is not provided, uses [current_tz_offset_s ()]. *)
+1 -2
ocaml-toml/nox-toml.opam
··· 7 7 inspired by Jsont. The core library provides value types, codec 8 8 combinators, and a streaming parser/encoder on top of Bytesrw. 9 9 Subpackages provide optional I/O adapters: 10 - - toml.eio: Eio integration with system clock 11 - - toml.unix: Unix I/O with system clock""" 10 + - toml.eio: Eio integration with system clock""" 12 11 maintainer: ["Thomas Gazagnaire <thomas@gazagnaire.org>"] 13 12 authors: [ 14 13 "Anil Madhavapeddy <anil@recoil.org>"
-5
ocaml-toml/test/lib_unix/dune
··· 1 - (test 2 - (name test) 3 - (libraries nox-toml.unix alcotest) 4 - (enabled_if 5 - (= %{context_name} "default")))
-1
ocaml-toml/test/lib_unix/test.ml
··· 1 - let () = Alcotest.run "toml-unix" [ Test_toml_unix.suite ]
-78
ocaml-toml/test/lib_unix/test_toml_unix.ml
··· 1 - open Toml.Value 2 - 3 - type config = { host : string; port : int } 4 - 5 - let config_codec = 6 - let open Toml.Codec in 7 - Table.obj (fun host port -> { host; port }) 8 - |> Table.mem "host" string ~enc:(fun c -> c.host) 9 - |> Table.mem "port" int ~enc:(fun c -> c.port) 10 - |> Table.finish 11 - 12 - let sample_toml () = table [ ("name", string "test"); ("count", int_of_int 42) ] 13 - 14 - let with_temp_file f = 15 - let path = Filename.temp_file "toml_test" ".toml" in 16 - Fun.protect 17 - ~finally:(fun () -> try Sys.remove path with Sys_error _ -> ()) 18 - (fun () -> f path) 19 - 20 - let test_current_tz_offset_s () = 21 - match Toml_unix.current_tz_offset_s () with 22 - | None -> () 23 - | Some offset -> 24 - Alcotest.(check bool) 25 - "tz in range" true 26 - (offset >= -14 * 3600 && offset <= 14 * 3600) 27 - 28 - let test_now () = 29 - let t = Toml_unix.now () in 30 - (* Epoch seconds must be after 2024-01-01 = 1704067200 *) 31 - Alcotest.(check bool) "now after 2024" true (Ptime.to_float_s t > 1704067200.0) 32 - 33 - let test_today_date () = 34 - let year, month, day = Toml_unix.today_date () in 35 - Alcotest.(check bool) "year >= 2024" true (year >= 2024); 36 - Alcotest.(check bool) "month in 1-12" true (month >= 1 && month <= 12); 37 - Alcotest.(check bool) "day in 1-31" true (day >= 1 && day <= 31) 38 - 39 - let test_channel_roundtrip () = 40 - with_temp_file (fun path -> 41 - let t = sample_toml () in 42 - let oc = open_out path in 43 - Toml_unix.to_channel oc t; 44 - close_out oc; 45 - let ic = open_in path in 46 - let t2 = Toml_unix.of_channel ic in 47 - close_in ic; 48 - Alcotest.(check string) "name" "test" (to_string (get "name" t2)); 49 - Alcotest.(check int64) "count" 42L (to_int (get "count" t2))) 50 - 51 - let test_file_roundtrip () = 52 - with_temp_file (fun path -> 53 - let t = sample_toml () in 54 - Toml_unix.to_file path t; 55 - let t2 = Toml_unix.of_file path in 56 - Alcotest.(check string) "name" "test" (to_string (get "name" t2)); 57 - Alcotest.(check int64) "count" 42L (to_int (get "count" t2))) 58 - 59 - let test_decode_encode_file () = 60 - with_temp_file (fun path -> 61 - let cfg = { host = "localhost"; port = 8080 } in 62 - Toml_unix.encode_file config_codec cfg path; 63 - match Toml_unix.decode_file config_codec path with 64 - | Error e -> Alcotest.fail (Toml.Error.to_string e) 65 - | Ok cfg2 -> 66 - Alcotest.(check string) "host" cfg.host cfg2.host; 67 - Alcotest.(check int) "port" cfg.port cfg2.port) 68 - 69 - let suite = 70 - ( "toml_unix", 71 - [ 72 - Alcotest.test_case "current_tz_offset_s" `Quick test_current_tz_offset_s; 73 - Alcotest.test_case "now" `Quick test_now; 74 - Alcotest.test_case "today_date" `Quick test_today_date; 75 - Alcotest.test_case "channel_roundtrip" `Quick test_channel_roundtrip; 76 - Alcotest.test_case "file_roundtrip" `Quick test_file_roundtrip; 77 - Alcotest.test_case "decode_encode_file" `Quick test_decode_encode_file; 78 - ] )
-2
ocaml-toml/test/lib_unix/test_toml_unix.mli
··· 1 - val suite : string * unit Alcotest.test_case list 2 - (** [suite] is the Alcotest test suite. *)