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

feat: clojure backwards compatibility #620

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 42 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,39 @@ jobs:
- attach_workspace:
at: /home/circleci
- run:
name: Run unittests for hitchhiker-tree index
name: Run unittests with specs activated
command: bb test specs
no_output_timeout: 5m
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
clj-1-10-test:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: Run unittests with clojure 1.10.0
command: bb test clj :1.10
no_output_timeout: 5m
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
clj-1-9-test:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: Run unittests with clojure 1.9.0
command: bb test clj :1.9
no_output_timeout: 5m
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
native-image-test:
executor: tools/clojurecli
steps:
Expand Down Expand Up @@ -243,6 +269,18 @@ workflows:
context: dockerhub-deploy
requires:
- build
- spec-test:
context: dockerhub-deploy
requires:
- build
- clj-1-10-test:
context: dockerhub-deploy
requires:
- build
- clj-1-9-test:
context: dockerhub-deploy
requires:
- build
- native-image-test:
context: dockerhub-deploy
requires:
Expand All @@ -268,6 +306,9 @@ workflows:
- format
- persistent-set-test
- hitchhiker-tree-test
- spec-test
- clj-1-10-test
- clj-1-9-test
- backward-compatibility-test
- native-image-test
- integration-test
Expand Down
21 changes: 17 additions & 4 deletions bb/src/tools/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
(:refer-clojure :exclude [test])
(:require [babashka.fs :as fs]
[babashka.process :as p]
[clojure.string :as str]
[tools.build :as build]))

(defn clj [opts & args] (apply p/shell opts "clojure" args))
(defn git [opts & args] (apply p/shell opts "git" args))

(defn kaocha [& args]
(apply clj {:extra-env {"TIMBRE_LEVEL" ":warn"}}
"-M:test" "-m" "kaocha.runner" args))

(defn back-compat [config]
(println "Testing backwards compatibility")
(let [old-version-dir "datahike-old"
Expand Down Expand Up @@ -49,12 +46,27 @@
(p/shell "./bb/resources/native-image-tests/run-native-image-tests")
(println "Native image cli missing. Please run 'bb ni-cli' and try again.")))

(defn kaocha-with-aliases [aliases & args]
(apply clj {:extra-env {"TIMBRE_LEVEL" ":warn"}}
(str "-M:test" (str/join (map #(str ":" (name %)) aliases)))
"-m" "kaocha.runner" args))

(defn kaocha [& args]
(apply kaocha-with-aliases [] args))

(defn specs []
(kaocha "--focus" "specs" "--plugin" "kaocha.plugin/orchestra"))

(defn clj-back-compat
"version-alias must be defined in deps.edn"
[version-alias & args]
(apply kaocha-with-aliases [version-alias] args))

(defn all [config]
(kaocha "--skip" "specs")
(specs)
(clj-back-compat :1.10)
(clj-back-compat :1.9)
(back-compat config)
(native-image))

Expand All @@ -63,6 +75,7 @@
(case (first args)
"native-image" (native-image)
"back-compat" (back-compat config)
"clj" (apply clj-back-compat (rest args))
"specs" (specs)
(apply kaocha "--focus" args))
(all config)))
6 changes: 6 additions & 0 deletions src/datahike/query_stats.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns datahike.query-stats
(:refer-clojure :exclude [abs])
(:require [clojure.set :as set]
[datahike.tools :as dt]))

Expand All @@ -7,6 +8,11 @@
:cljs (let [y (Math/pow 10 precision)]
(/ (.round js/Math (* y x)) y))))

(defn abs
"Only available since Clojure 1.11 and ClojureScript 1.11.10 in core namespaces."
[x]
(Math/abs x))

(defn get-stats [context]
{:rels (mapv (fn [rel] {:rows (count (:tuples rel))
:bound (set (keys (:attrs rel)))})
Expand Down