Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2de01d8
Diff old read+eval and read-kinds read+eval
onbreath Nov 27, 2025
b3d462b
Add one difference example
onbreath Nov 27, 2025
bfc0f8b
Moved to scicloj.clay.v2.util.diff, refactored, fixed
onbreath Nov 28, 2025
4c7092b
Add pre read-kinds notebook.clj as notebook_old.clj
onbreath Nov 28, 2025
d09dc8b
Revert read_old.clj
onbreath Nov 28, 2025
44f7813
Diff on old and new notebooks
onbreath Nov 28, 2025
c322416
Print with Clay:
onbreath Nov 28, 2025
b3428a3
Take out some keys unique to new/old notes
onbreath Nov 28, 2025
442c970
Tricked by seqs
onbreath Nov 28, 2025
a3dfe9e
Copy current diff to diffs-folder toplevel
onbreath Nov 28, 2025
ea1003d
Print convenience
onbreath Nov 28, 2025
b83eaad
Include notebook path in diff folder name
onbreath Nov 28, 2025
a1710f3
complete not needed for read-kinds
onbreath Nov 28, 2025
8c481f0
out and err captured by read-kinds
onbreath Nov 28, 2025
5682928
Collapse comments and whitespace notes from read-kinds
onbreath Nov 28, 2025
14e0d28
read missing require
onbreath Nov 29, 2025
5a399ef
Improve comment/whitespace collapse a bit
onbreath Nov 29, 2025
ef4f35a
Simplified, added no-diff case, informative printing
onbreath Nov 29, 2025
7c4c390
Attempt to dodge some datasets before they blow up diffing
onbreath Nov 29, 2025
0bc482a
Diff only clojure- and java-datastructures for now
onbreath Nov 30, 2025
16a65eb
vector is list
onbreath Nov 30, 2025
a7a0274
Added ReplacedValue type for diffing, wraps replaced value
onbreath Nov 30, 2025
008e89a
Just replace unsupported collections for now
onbreath Dec 1, 2025
24fcbad
Fix folder to delete in should exist first
onbreath Dec 1, 2025
5108531
Fixed future handler in deep-diff2 printer
onbreath Dec 1, 2025
a88d93c
Make old and new comments equal for diff
onbreath Dec 2, 2025
41c81f2
read/eval split in read-kinds
onbreath Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
docs/*qmd
_quarto.yml
book
/read-kinds-diffs
3 changes: 3 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
nrepl/nrepl {:mvn/version "1.3.1"}
com.cnuernber/charred {:mvn/version "1.037"}
read-kinds/read-kinds {:local/root "../read-kinds"}
;; TODO back to lambdaisland/deep-diff2 once fix merged
io.github.onbreath/deep-diff2 {:git/sha "1f969521b68ce9dd9feed9b51a99a4569482b6ad"}
carocad/parcera {:mvn/version "0.11.6"}
org.antlr/antlr4-runtime {:mvn/version "4.7.1"}
http-kit/http-kit {:mvn/version "2.8.0"}
ring/ring-core {:mvn/version "1.14.1"}
Expand Down
10 changes: 8 additions & 2 deletions src/scicloj/clay/v2/make.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
[clojure.pprint :as pp]
[scicloj.kindly-render.notes.to-html-page :as to-html-page]
;; [hashp.preload]
[scicloj.kindly.v4.api :as kindly]))
[scicloj.kindly.v4.api :as kindly])
(:import java.time.LocalDateTime
java.time.format.DateTimeFormatter))

(defn spec->source-type [{:keys [source-path]}]
(some-> source-path (fs/extension)))
Expand Down Expand Up @@ -471,8 +473,12 @@
(fs/delete-tree target))
(util.fs/copy-tree-no-clj subdir target)))))))

(defn ts []
(.format (LocalDateTime/now)
(DateTimeFormatter/ofPattern "yyyy-MM-dd-HH-mm-ss~N")))

(defn make! [spec]
(let [config (config/config spec)
(let [config (config/config (assoc spec :diff/timestamp (ts)))
{:keys [single-form single-value]} spec
{:keys [main-spec single-ns-specs]} (extract-specs config spec)
{:keys [ide browse show book base-target-path clean-up-target-dir live-reload]} main-spec
Expand Down
111 changes: 88 additions & 23 deletions src/scicloj/clay/v2/notebook.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
[scicloj.clay.v2.util.path :as path]
[scicloj.clay.v2.item :as item]
[scicloj.clay.v2.prepare :as prepare]
[scicloj.clay.v2.notebook-old :as notebook-old]
[scicloj.clay.v2.read :as read]
[scicloj.kindly.v4.api :as kindly]
[scicloj.kindly-advice.v1.api :as kindly-advice])
[scicloj.kindly-advice.v1.api :as kindly-advice]
[scicloj.clay.v2.util.diff :as diff])
(:import (java.io StringWriter)))

(set! *warn-on-reflection* true)
Expand Down Expand Up @@ -99,8 +101,7 @@
[{:as note
:keys [code form]}]
note
#_
(let [out (StringWriter.)
#_(let [out (StringWriter.)
err (StringWriter.)
note (try
(let [x (binding [*out* out
Expand Down Expand Up @@ -409,22 +410,18 @@
:format])]
(doall
(for [note notes]
(complete (kindly/deep-merge opts note))))))
(kindly/deep-merge opts note)))))

(defn relevant-notes [{:keys [full-source-path
single-form
single-value
smart-sync
pprint-margin]
:or {pprint-margin pp/*print-right-margin*}}]
(let [{:keys [code first-line-of-change]} (some-> full-source-path slurp-and-compare)
notes (->> (cond single-value (conj (when code
[{:form (read/read-ns-form code)}])
{:value single-value})
single-form (conj (when code
[{:form (read/read-ns-form code)}])
{:form single-form})
:else (read/->notes code))
single-form
single-value
smart-sync
pprint-margin]
:or {pprint-margin pp/*print-right-margin*}
:as spec}]
(let [{:keys [code first-line-of-change]} (some-> full-source-path
slurp-and-compare)
notes (->> (read/->notes (assoc spec :code code))
(map-indexed (fn [i {:as note
:keys [code]}]
(merge note
Expand Down Expand Up @@ -464,19 +461,87 @@
"seconds")
result#))

(defn ->old-comment [note]
(let [comment-item (-> note :code notebook-old/comment->item)]
(-> note
(assoc :value (str/replace (:md comment-item)
;; TODO stripping extra space added
;; in front of headline Do we want
;; to add this for read-kinds?
#"\n#" "#")
:kind :kind/md)
(dissoc :code :comment? :region))))

(defn ->old-notes-approx [notes]
(->> notes
(into []
(map #(-> %
(cond-> (and (:comment? %)
(:code %))
->old-comment)
(dissoc :gen))))))

(defn ->new-notes-approx [notes]
(->> notes
(into []
(map #(-> %
(dissoc :line :column)
(cond-> (-> % :narrowed nil?)
(dissoc :narrowed)
(-> % :narrower nil?)
(dissoc :narrower)))))))

(defn spec-notes [{:as spec
:keys [pprint-margin ns-form full-source-path]
:or {pprint-margin pp/*print-right-margin*}}]
(binding [*ns* *ns*
*warn-on-reflection* *warn-on-reflection*
*unchecked-math* *unchecked-math*
pp/*print-right-margin* pprint-margin]
(-> (relevant-notes spec)
(complete-notes spec)
(with-out-err-captured)
(log-time (str "Evaluated "
(or (some-> ns-form second name)
(some-> full-source-path fs/file-name)))))))
(let [old (-> (notebook-old/spec-notes spec)
(->old-notes-approx))
;; TODO Comment blocks equal to old ones
new (-> (assoc spec :collapse-comments-ws? true)
(relevant-notes)
(complete-notes spec)
(->new-notes-approx)
;; TODO Read kinds should be doing this
#_(with-out-err-captured)
(log-time (str "Evaluated notebook with read-kinds "
(or (some-> ns-form second name)
(some-> full-source-path fs/file-name)))))]
;; We can print the plain new and old notes..
#_(diff/notes old new
:diff/to-repl :clojure/pprint
spec)
;; ..or only differences
(diff/notes old new
:diff/to-repl :deep-diff2/minimal
spec)
;; ..or only one difference
#_(diff/notes (take 1 old) (take 1 new)
:diff/to-repl :deep-diff2/minimal
spec)
;; ..or write old and new files
#_(diff/notes old new
:diff/to-files :clojure/pprint
spec)
;; ..or old, new and full diff files
#_(diff/notes old new
:diff/to-files :deep-diff2/full
spec)
;; ..or old, new and minimal diffs, keeping only the last three runs
#_(diff/notes old new
:diff/to-files :deep-diff2/minimal
:diff/keep-dirs 3
spec)
;; ..or any combination of the above
#_(diff/notes old new
:diff/to-repl :deep-diff2/minimal
:diff/to-files :deep-diff2/full
:diff/keep-dirs 3
spec)
new)))

(defn items-and-test-forms
[notes spec]
Expand Down
Loading