Skip to content
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

Add tap> support; add Babashka compatibility and remove ClojureScript dependency in Clojure #31

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ci
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Install clojure tools
uses: DeLaGuardo/[email protected]
with:
lein: 2.9.10
bb: latest

- name: Execute lein tests
run: lein test

- name: Execute babashka tests
run: bb test:bb
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
/examples/.rebel_readline_history
/examples/.lein-repl-history

/.idea/
/*.iml

/resources/public/js/

*~
*#
.#*

.cache
.lein-failures
/.cpcache/
16 changes: 16 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{:deps {philoskim/debux {:local/root "."}}
:tasks

{test:bb
{:doc "Run babashka tests"
:extra-deps {eftest/eftest {:mvn/version "0.6.0"}}
:extra-paths ["test"]
:requires ([eftest.runner :refer [find-tests run-tests]])
:task (let [{:keys [fail error]} (run-tests
(find-tests "test")
(when-not (System/console)
;; better output in github actions
{:report clojure.test/report}))]
(when (or (pos? fail)
(pos? error))
(throw (ex-info "Tests failed" {:babashka/exit 1}))))}}}
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["src"]}
1 change: 0 additions & 1 deletion examples/src/cljs/examples/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
))

(defn init [])

7 changes: 3 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(defproject philoskim/debux "0.8.3"
(defproject com.github.gnl/debux "0.8.4-1"
:description "A trace-based debugging library for Clojure and ClojureScript"
:url "https://github.com/philoskim/debux"
:license {:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.10.238"]
[clojure-future-spec "1.9.0"]]
:dependencies [[org.clojure/clojure "1.10.0" :scope "provided"]
[org.clojure/clojurescript "1.10.238" :scope "provided"]]
:source-paths ["src"])
3 changes: 1 addition & 2 deletions src/debux/common/macro_specs.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns debux.common.macro-specs
"clojure.core macro specs which are minified, simplified and modified."
(:require [clojure.spec.alpha :as s]
[clojure.future :refer :all] ))
(:require [clojure.spec.alpha :as s]))

(declare skip o-skip a-skip)
; skip => full skip
Expand Down
66 changes: 56 additions & 10 deletions src/debux/common/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
(:require [clojure.string :as str]
[clojure.pprint :as pp]
[clojure.zip :as z]
[clojure.walk :as walk]
[cljs.analyzer.api :as ana] ))
[clojure.walk :as walk]))

;;; For internal debugging
(defmacro d
Expand Down Expand Up @@ -37,9 +36,14 @@
(cond-> {:ns (symbol ns)}
line (merge {:line line})))

(comment
(defn src-info+tap-data [tap-data opts]
(merge (select-keys [:ns :line :msg] opts)
tap-data)))


;;; dynamic vars
(def ^:dynamic *indent-level* 0)
(def ^:dynamic *indent-level* 1)
(def ^:dynamic *debug-level* 0)


Expand All @@ -51,7 +55,8 @@
:ns-blacklist nil
:ns-whitelist nil
:line-bullet "|"
:cljs-devtools nil} ))
:cljs-devtools nil
:tap-output false}))

(defn set-debug-mode! [val]
(swap! config* assoc :debug-mode val)
Expand Down Expand Up @@ -81,6 +86,10 @@
(swap! config* assoc :cljs-devtools bool)
nil)

(defn set-tap-output! [bool]
(swap! config* assoc :tap-output bool)
nil)


(defn ns-match? [current-ns target-ns]
(-> (re-pattern (str/escape target-ns {\. "\\." \* ".*"}))
Expand Down Expand Up @@ -165,7 +174,7 @@

#?(:clj
(defn- ns-symbol-for-cljs [sym env]
(if-let [meta (ana/resolve env sym)]
(if-let [meta ((requiring-resolve 'cljs.analyzer.api/resolve) env sym)]
;; normal symbol
(if (:local meta)
sym
Expand Down Expand Up @@ -242,11 +251,31 @@
[line indent-level]
(str (make-bullets indent-level) line))

(defn tap-data
([tap-map]
(->> tap-map
(merge {:form nil
:result nil
:indent-level 0
:info nil})
tap>))
([form result]
(tap-data form result *indent-level* nil))
([form result indent-level]
(tap-data form result indent-level nil))
([form result indent-level info]
(tap> {:form form
:result result
:indent-level indent-level
:info info})))

(defn print-title-with-indent
[src-info title]
(when (:source-info-mode @config*)
(println (prepend-bullets-in-line src-info (dec *indent-level*))))
(println (prepend-bullets-in-line title (dec *indent-level*)))
(when (:tap-output @config*)
(tap-data nil nil (dec *indent-level*) title))
(flush))

(defn print-form-with-indent
Expand All @@ -268,7 +297,9 @@
(println (->> (str/split pprint #"\n")
(mapv #(str prefix %))
(str/join "\n")))
(flush) ))
(when (:tap-output @config*)
(tap-data nil result *indent-level* ":locals"))
(flush)))

(defn pprint-result-with-indent
[result]
Expand Down Expand Up @@ -340,6 +371,9 @@
(= :level fst)
(recur (nnext opts) (assoc acc :level snd))

(= :simple fst)
(recur (next opts) (assoc acc :simple true))


;;; for clojureScript only
(= :js fst)
Expand Down Expand Up @@ -391,12 +425,16 @@
[pre-result quoted-form & [opts]]
(print-form-with-indent (form-header quoted-form))
(pprint-result-with-indent pre-result)
(when (:tap-output @config*)
(tap-data quoted-form pre-result))
pre-result)

(defn spy-last
[quoted-form pre-result & [opts]]
(print-form-with-indent (form-header quoted-form))
(pprint-result-with-indent pre-result)
(when (:tap-output @config*)
(tap-data quoted-form pre-result))
pre-result)

(defn spy-comp
Expand All @@ -406,29 +444,37 @@
(let [result (apply form arg)]
(print-form-with-indent (form-header quoted-form))
(pprint-result-with-indent result)
result) )))
(when (:tap-output @config*)
(tap-data quoted-form result))
result))))


;;; spy macros
(defmacro spy
[form]
`(let [result# ~form]
(print-form-with-indent (form-header '~form))
(pprint-result-with-indent result#)
result#))
(print-form-with-indent (form-header '~form))
(pprint-result-with-indent result#)
(when (:tap-output @config*)
(tap-data '~form result#))
result#))

(defmacro spy-first2
[pre-result form]
`(let [result# (-> ~pre-result ~form)]
(print-form-with-indent (form-header '~form))
(pprint-result-with-indent result#)
(when (:tap-output @config*)
(tap-data '~form result#))
result#))

(defmacro spy-last2
[form pre-result]
`(let [result# (->> ~pre-result ~form)]
(print-form-with-indent (form-header '~form))
(pprint-result-with-indent result#)
(when (:tap-output @config*)
(tap-data '~form result#))
result#))

(defn print-xform [quoted-xform indent-level]
Expand Down
2 changes: 2 additions & 0 deletions src/debux/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
(defmacro set-ns-whitelist! [whitelist]
`(ut/set-ns-whitelist! ~whitelist))

(defmacro set-tap-output! [bool]
`(ut/set-tap-output! ~bool))

;;; debugging APIs
(def locking* (Object.))
Expand Down
3 changes: 3 additions & 0 deletions src/debux/cs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
(defmacro set-cljs-devtools! [bool]
`(ut/set-cljs-devtools! ~bool))

(defmacro set-tap-output! [bool]
`(ut/set-tap-output! ~bool))


;;; debugging APIs
(defmacro dbg [form & opts]
Expand Down
10 changes: 8 additions & 2 deletions src/debux/cs/macro_types.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns debux.cs.macro-types
(:require [clojure.set :as set]
[debux.common.util :as ut] ))
[debux.common.util :as ut]
[debux.dbg :as d]))

(def macro-types*
(atom {:def-type '#{def cljs.core/defonce}
Expand Down Expand Up @@ -59,7 +60,12 @@
(defmacro register-macros! [macro-type new-symbols]
(-> (swap! macro-types* update macro-type
#(merge-symbols % new-symbols &env))
ut/quote-vals))
ut/quote-vals)
(when (= macro-type :let-type)
(-> (swap! d/dbg-macro-types* update :let
#(merge-symbols % new-symbols &env))
ut/quote-vals)))


(defmacro show-macros
([] (ut/quote-vals @macro-types*))
Expand Down
1 change: 0 additions & 1 deletion src/debux/cs/util.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns debux.cs.util
"Utilities for clojurescript only"
(:require [clojure.string :as str]
[cljs.analyzer.api :as ana]
#?(:cljs [cljs.pprint :as pp])
[debux.common.util :as ut] ))

Expand Down
Loading