Skip to content

Commit

Permalink
feat: Reenable asak (using pin-depends for compat patch with OCaml 5)
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Jul 25, 2024
1 parent acbc895 commit 50a979f
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 87 deletions.
5 changes: 5 additions & 0 deletions learn-ocaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ depends: [
"uutf" {>= "1.0" }
"vg"
"yojson" {>= "1.4.0" }
"asak" {= "0.5"}
]
build: [
[make "static"]
Expand All @@ -86,4 +87,8 @@ pin-depends: [
"ocp-indent-nlfork.1.5.5"
"git+https://[email protected]/OCamlPro/ocp-indent.git#nlfork"
]
[
"asak.0.5"
"git+https://github.com/AltGr/asak#ocaml5"
]
]
4 changes: 4 additions & 0 deletions learn-ocaml.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bug-reports: "https://github.com/ocaml-sf/learn-ocaml/issues"
dev-repo: "git+https://github.com/ocaml-sf/learn-ocaml"
depends: [
"angstrom" {= "0.15.0"}
"asak" {= "0.5"}
"asn1-combinators" {= "0.2.6"}
"astring" {= "0.8.5"}
"base" {= "v0.16.3"}
Expand Down Expand Up @@ -173,6 +174,9 @@ the common files. A demo exercise repository is also provided as example.
run-test: [make "test"]
depexts: ["lsof"] {os-distribution = "alpine"}
pin-depends: [
["asak.0.5" "git+https://github.com/AltGr/asak#ocaml5"]
[
"ocp-indent-nlfork.1.5.5"
"git+https://[email protected]/OCamlPro/ocp-indent.git#nlfork"
]
]
3 changes: 1 addition & 2 deletions src/server/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
learnocaml_data
learnocaml_api
learnocaml_store
;; learnocaml_partition_create
)
learnocaml_partition_create)
)
16 changes: 8 additions & 8 deletions src/server/learnocaml_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,14 @@ module Request_handler = struct
status
>>= respond_json cache

(* | Api.Partition (token, eid, fid, prof) ->
* lwt_catch_fail (fun () ->
* verify_teacher_token token
* >?= fun () ->
* Learnocaml_partition_create.partition eid fid prof
* >>= respond_json cache
* )
* (fun exn -> (`Not_found, Printexc.to_string exn)) *)
| Api.Partition (token, eid, fid, prof) ->
lwt_catch_fail (fun () ->
verify_teacher_token token
>?= fun () ->
Learnocaml_partition_create.partition eid fid prof
>>= respond_json cache
)
(fun exn -> (`Not_found, Printexc.to_string exn))

| Api.Invalid_request body ->
lwt_fail (`Bad_request, body)
Expand Down
3 changes: 2 additions & 1 deletion src/state/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
(name learnocaml_data)
(wrapped false)
(modules Learnocaml_data)
(libraries sha
(libraries asak
sha
unix
learnocaml_toplevel_history
learnocaml_report
Expand Down
22 changes: 11 additions & 11 deletions src/state/learnocaml_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ type _ request =
| Set_exercise_status:
teacher token * (Exercise.Status.t * Exercise.Status.t) list -> unit request

(* | Partition:
* teacher token * Exercise.id * string * int -> Partition.t request *)
| Partition:
teacher token * Exercise.id * string * int -> Partition.t request

| Invalid_request:
string -> string request
Expand Down Expand Up @@ -177,7 +177,7 @@ let supported_versions
| Exercise_status_index _
| Exercise_status (_, _)
| Set_exercise_status (_, _)
(* | Partition (_, _, _, _) *)
| Partition (_, _, _, _)
| Invalid_request _ -> Compat.(Since (v "0.12"))

let is_supported
Expand Down Expand Up @@ -266,8 +266,8 @@ module Conversions (Json: JSON_CODEC) = struct
| Set_exercise_status _ ->
json J.unit

(* | Partition _ ->
* json Partition.enc *)
| Partition _ ->
json Partition.enc

| Invalid_request _ ->
str
Expand Down Expand Up @@ -372,9 +372,9 @@ module Conversions (Json: JSON_CODEC) = struct
(J.list (J.tup2 Exercise.Status.enc Exercise.Status.enc))
status)

(* | Partition (token, eid, fid, prof) ->
* get ~token
* ["partition"; eid; fid; string_of_int prof] *)
| Partition (token, eid, fid, prof) ->
get ~token
["partition"; eid; fid; string_of_int prof]

| Invalid_request s ->
failwith ("Error request "^s)
Expand Down Expand Up @@ -504,9 +504,9 @@ module Server (Json: JSON_CODEC) (Rh: REQUEST_HANDLER) = struct
| `GET, ["playgrounds"; f], _ when Filename.check_suffix f ".json" ->
Playground (Filename.chop_suffix f ".json") |> k

(* | `GET, ["partition"; eid; fid; prof], Some token
* when Token.is_teacher token ->
* Partition (token, eid, fid, int_of_string prof) |> k *)
| `GET, ["partition"; eid; fid; prof], Some token
when Token.is_teacher token ->
Partition (token, eid, fid, int_of_string prof) |> k

| `GET, ["teacher"; "exercise-status.json"], Some token
when Token.is_teacher token ->
Expand Down
4 changes: 2 additions & 2 deletions src/state/learnocaml_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ type _ request =
(** The two Status.t correspond to the states before and after changes, used
for three-way merge *)

(* | Partition:
* teacher token * Exercise.id * string * int -> Partition.t request *)
| Partition:
teacher token * Exercise.id * string * int -> Partition.t request

| Invalid_request:
string -> string request
Expand Down
86 changes: 43 additions & 43 deletions src/state/learnocaml_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1403,49 +1403,49 @@ module Tutorial = struct
end
end

(* module Partition = struct
* type t =
* {
* not_graded : Token.t list;
* bad_type : Token.t list;
* partition_by_grade :
* (int *
* (((Token.t * string) list) Asak.Wtree.wtree list))
* list;
* }
*
* let token_list = J.list Token.enc
*
* let tree_enc leaf_enc =
* let open Asak.Wtree in
* J.mu "tree" @@ fun self ->
* J.union
* [ J.case (J.obj1 (J.req "leaf" leaf_enc))
* (function Leaf x -> Some x | Node _ -> None)
* (fun x -> Leaf x) ;
* J.case (J.obj3 (J.req "coef" J.int) (J.req "left" self) (J.req "right" self))
* (function Node (t,l,r) -> Some (t,l,r) | Leaf _ -> None)
* (fun (t,l,r) -> Node (t,l,r)) ]
*
* let leaf_enc =
* J.list (J.tup2 Token.enc J.string)
*
* let innerlist = J.list (tree_enc leaf_enc)
*
* let int_assoc =
* J.tup2 J.int innerlist
*
* let enc =
* J.conv
* (fun t ->
* (t.not_graded, t.bad_type, t.partition_by_grade))
* (fun (not_graded, bad_type, partition_by_grade) ->
* {not_graded; bad_type; partition_by_grade}) @@
* J.obj3
* J.(req "not_graded" token_list)
* J.(req "bad_type" token_list)
* J.(req "patition_by_grade" (J.list int_assoc))
* end *)
module Partition = struct
type t =
{
not_graded : Token.t list;
bad_type : Token.t list;
partition_by_grade :
(int *
(((Token.t * string) list) Asak.Wtree.wtree list))
list;
}

let token_list = J.list Token.enc

let tree_enc leaf_enc =
let open Asak.Wtree in
J.mu "tree" @@ fun self ->
J.union
[ J.case (J.obj1 (J.req "leaf" leaf_enc))
(function Leaf x -> Some x | Node _ -> None)
(fun x -> Leaf x) ;
J.case (J.obj3 (J.req "coef" J.int) (J.req "left" self) (J.req "right" self))
(function Node (t,l,r) -> Some (t,l,r) | Leaf _ -> None)
(fun (t,l,r) -> Node (t,l,r)) ]

let leaf_enc =
J.list (J.tup2 Token.enc J.string)

let innerlist = J.list (tree_enc leaf_enc)

let int_assoc =
J.tup2 J.int innerlist

let enc =
J.conv
(fun t ->
(t.not_graded, t.bad_type, t.partition_by_grade))
(fun (not_graded, bad_type, partition_by_grade) ->
{not_graded; bad_type; partition_by_grade}) @@
J.obj3
J.(req "not_graded" token_list)
J.(req "bad_type" token_list)
J.(req "patition_by_grade" (J.list int_assoc))
end

module Playground = struct
type id = string
Expand Down
26 changes: 13 additions & 13 deletions src/state/learnocaml_data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,19 @@ module Tutorial: sig

end

(* module Partition : sig
* type t =
* {
* not_graded : Token.t list;
* bad_type : Token.t list;
* partition_by_grade :
* (int *
* (((Token.t * string) list) Asak.Wtree.wtree list))
* list;
* }
*
* val enc: t Json_encoding.encoding
* end *)
module Partition : sig
type t =
{
not_graded : Token.t list;
bad_type : Token.t list;
partition_by_grade :
(int *
(((Token.t * string) list) Asak.Wtree.wtree list))
list;
}

val enc: t Json_encoding.encoding
end

module Playground : sig
type id = string
Expand Down
14 changes: 7 additions & 7 deletions src/utils/dune
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
(modules sha)
)

;; (library
;; (name learnocaml_partition_create)
;; (wrapped false)
;; (flags :standard -warn-error A-4-42-44-45-48)
;; (libraries lwt learnocaml_store learnocaml_data)
;; (modules learnocaml_partition_create)
;; )
(library
(name learnocaml_partition_create)
(wrapped false)
(flags :standard -warn-error A-4-42-44-45-48)
(libraries asak lwt learnocaml_store learnocaml_data)
(modules learnocaml_partition_create)
)

0 comments on commit 50a979f

Please sign in to comment.