-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
irmin: add pretty-printers to high-level Store that work with utop
#1839
Conversation
@zshipko thanks for the feedback to re-evaluate the printer implementations. I'm using the typerepr ones now so should be resilient to future changes. @Ngoguey42 based on the discussion from the previous PR, I decided to reduce scope to only impact |
I tried the following and it didn't work. Did I do something wrong? From your branch I launched
|
@Ngoguey42 I was surprised this didn't work but just confirmed the same behavior. Based on the PR that added support for automatically installing printers, it appears to only work if the sig/attribute is present in a It seems that the core problem may be that stores are created through functors, thus no module signatures are available at load time. I somewhat convinced myself of this by including a pre-built store in I'm not sure how best to handle this, but I'll look into what can be done to make this work better with stores created directly in utop since that would be the best experience for people playing with the library. |
The best I have been able to come up with so far is to make a small package within For example: module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String);;
Irmin_top.install_printers "Store";; Interestingly, subsequent store modules created through similar makers will also pretty-print correctly (I assume because of how OCaml is able to see them as the same types). What do you think of this approach? |
That sounds promising. Could you share the code for this? |
@Ngoguey42 just pushed! |
Thanks. This is all black magic to me. @samoht would that be a problem to have an irmin subpackage that depends on @metanivek It works now. However I'm noticing small inconsistencies in the things printed. The following lines... #require "digestif.ocaml";;
#require "checkseum.ocaml";;
#require "irmin-unix";;
module A = Irmin_unix.Git.FS.KV (Irmin.Contents.String);;
module B = Irmin_unix.Git.FS.KV (Irmin.Contents.String);;
module Maker = Irmin_pack_unix.Maker (Irmin_tezos.Conf);;
module C = Maker.Make (Irmin_tezos.Schema);;
Irmin_top.install_printers "A";;
A.Info.v 0L;;
B.Info.v 1L;;
C.Info.v 2L;; ...procude this output
Namely,
My opinion is that this is an acceptation situation and I think we can merge this patch as is, leaving room for future improvements. |
The code/package is a modified version of core.top; I'm definitely learning more about OCaml through this little patch. 😄 My understanding for why it works for all your store modules is that the printers are matched based on type, and It's surprising at first that it prints Does this patch deserve a mention in |
The logic to autoload printers in utop (added here ocaml-community/utop#269) is a bit too limited to handle functors. I made a proof-of-concept fix here: https://github.com/let-def/autoprinter
This package should work well with Irmin printers, even if they are defined inside functors. |
@let-def thanks for the proof-of-concept and confirmation that the functors are the issue. I've verified it does work in @Ngoguey42 here's what I see outstanding for this PR before it is ready to merge:
Anything missing? |
4ab9171
to
48ff8ea
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more. @@ Coverage Diff @@
## main #1839 +/- ##
==========================================
+ Coverage 68.81% 68.82% +0.01%
==========================================
Files 133 133
Lines 16208 16211 +3
==========================================
+ Hits 11154 11158 +4
+ Misses 5054 5053 -1
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks for your patches! I'm a bit sad to see so much magic in After discussing with @let-def it seems that the best UX for this feature would be to:
What do you think? |
For autoprint, I think that patching utop and ocaml toplevel is a more viable way (@nojb was looking at ways to add the feature upstream). |
I also think that the best path is to patch upstream(s) to handle the printers automatically. It's pretty far out from my current knowledge, but I'd love to see this happen so happy to help however I can. :) I quickly tried a wrapper package locally -- unfortunately, it has the same caveats as So, here is my current list for getting this PR merge-ready:
This patch is (relatively) inconsequential, but I'm excited that it could result in improvements for the broader ecosystem (like this longstanding question about pretty-printing for functors). 🙌 As for the |
Oh, can I? (I've just seen this) How is Btw, TIL about the |
I opened a |
48ff8ea
to
9cedf1e
Compare
utop
As of @samoht I think this small improvement is good to go! |
ec6364e
to
210e615
Compare
210e615
to
8686672
Compare
LGTM, thx a lot for your work |
CHANGES: ### Added - **irmin-server** - Added `irmin-server` package (mirage/irmin#2031, @zshipko) - **irmin-client** - Added `irmin-client` package to connect to `irmin-server` instances (mirage/irmin#2031, @zshipko) - **irmin** - Add pretty printers for `Commit`, `Tree`, `Info`, `Status`, `Branch` when using `utop` (@metanivek, mirage/irmin#1839) ### Fixed - **irmin-pack** - Fix index integrity check for v3 stores (mirage/irmin#2267, @metanivek) ### Removed - **irmin-http** - Removed `irmin-http` since it is not compatible with generic keys. `irmin-grapqhl` or `irmin-server` should be used instead. (mirage/irmin#1902, @zshipko) - **irmin** - Removed stream proofs. We now only have Merkle tree proofs. This simplifies the maintenance of that part of the code, as ensuring the correct order of cached IO operations was tricky for stream proofs (mirage/irmin#2275, @samoht) ### Changed - **irmin-git** - Moved lower bounds to `git.3.14.0` to use new function (mirage/irmin#2277, @metanivek)
CHANGES: ### Added - **irmin-server** - Added `irmin-server` package (mirage/irmin#2031, @zshipko) - **irmin-client** - Added `irmin-client` package to connect to `irmin-server` instances (mirage/irmin#2031, @zshipko) - **irmin** - Add pretty printers for `Commit`, `Tree`, `Info`, `Status`, `Branch` when using `utop` (@metanivek, mirage/irmin#1839) ### Fixed - **irmin-pack** - Fix index integrity check for v3 stores (mirage/irmin#2267, @metanivek) ### Removed - **irmin-http** - Removed `irmin-http` since it is not compatible with generic keys. `irmin-grapqhl` or `irmin-server` should be used instead. (mirage/irmin#1902, @zshipko) - **irmin** - Removed stream proofs. We now only have Merkle tree proofs. This simplifies the maintenance of that part of the code, as ensuring the correct order of cached IO operations was tricky for stream proofs (mirage/irmin#2275, @samoht) ### Changed - **irmin-git** - Moved lower bounds to `git.3.14.0` to use new function (mirage/irmin#2277, @metanivek)
This PR is a follow up to #1836, with reduced scope to focus only on
irmin
and usage of built-in pretty-printing based on typereprs.It adds pretty-printers for:
An example output for a commit:
Closes #408