Skip to content

Commit

Permalink
Fix #159: fix pmap + requiring-resolve issue (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Feb 4, 2023
1 parent 832f3a9 commit 539fb4e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

See the [New Clojure project quickstart](https://blog.michielborkent.nl/new-clojure-project-quickstart.html) blog post for a gentle introduction into `neil`.

## 0.1.54 (2023-02-04)

- [#159](https://github.com/babashka/neil/issues/159): fix `pmap` + `requiring-resolve` issue

## 0.1.53 (2023-01-31)

- Clojars search improvements ([@tobias](https://github.com/tobias))
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:deps {org.babashka/http-client {:mvn/version "0.0.2"}
{:deps {org.babashka/http-client {:mvn/version "0.0.3"}
babashka/fs {:mvn/version "0.1.6"}
babashka/process {:mvn/version "0.1.7"}
rewrite-clj/rewrite-clj {:mvn/version "1.0.699-alpha"}
rewrite-clj/rewrite-clj {:mvn/version "1.1.46"}
borkdude/rewrite-edn {:mvn/version "0.2.0"}
org.babashka/cli {:mvn/version "0.6.45"}
cheshire/cheshire {:mvn/version "5.11.0"}
Expand Down
3 changes: 2 additions & 1 deletion dev/babashka/neil/gen_script.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
project (slurp "src/babashka/neil/project.clj")
rewrite (slurp "src/babashka/neil/rewrite.clj")
version (slurp "src/babashka/neil/version.clj")
utils (slurp "src/babashka/neil/utils.clj")
neil (slurp "src/babashka/neil.clj")]
(spit "neil" (str/join "\n" [prelude meta-str
curl git rewrite project new test version
utils curl git rewrite project new test version
neil]))))
37 changes: 31 additions & 6 deletions neil
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,31 @@
#_{:local/root "/Users/borkdude/dev/cli"}
{:mvn/version "0.6.45"}
version-clj/version-clj {:mvn/version "2.0.2"}
org.babashka/http-client {:mvn/version "0.0.2"}}})
org.babashka/http-client {:mvn/version "0.0.3"}}})

(ns babashka.neil.meta)
(def version "This def was generated by the neil build script." "0.1.53")
(ns babashka.neil.utils)

;; Workaround for pmap + require which doesn't work well in bb - 2023-02-04

(def ^:private lock (Object.))

(defn- serialized-require
[& args]
(locking lock
(apply require args)))

(defn req-resolve
[sym]
(if (qualified-symbol? sym)
(or (resolve sym)
(do (-> sym namespace symbol serialized-require)
(resolve sym)))
(throw (IllegalArgumentException. (str "Not a qualified symbol: " sym)))))

;; End workaround

(ns babashka.neil.curl
{:no-doc true}
(:require
Expand Down Expand Up @@ -240,6 +261,7 @@
(:require
[babashka.neil.git :as git]
[babashka.neil.project :as proj]
[babashka.neil.utils :refer [req-resolve]]
[clojure.edn :as edn]
[clojure.set :as set]
[clojure.string :as str]))
Expand Down Expand Up @@ -374,7 +396,7 @@
{:create-opts create-opts})))

(defn- deps-new-create [create-opts]
((requiring-resolve 'org.corfield.new/create) create-opts))
((req-resolve 'org.corfield.new/create) create-opts))

(defn print-new-help []
(println (str/trim "
Expand Down Expand Up @@ -426,13 +448,13 @@ Examples:
This is required by org.corfield.new/create. In Clojure it's set by default,
but in Babashka it must be set explicitly."
[]
(let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))]
(let [classpath ((req-resolve 'babashka.classpath/get-classpath))]
(System/setProperty "java.class.path" classpath)))

(defn- deps-new-add-template-deps
"Adds template deps at runtime."
[template-deps]
((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}))
((req-resolve 'babashka.deps/add-deps) {:deps template-deps}))

(defn run-deps-new
"Runs org.corfield.new/create using the provided CLI options.
Expand Down Expand Up @@ -810,6 +832,7 @@ using the [major|minor|patch] subcommands.
[babashka.neil.git :as git]
[babashka.neil.new :as new]
[babashka.neil.project :as proj]
[babashka.neil.utils :refer [req-resolve]]
[babashka.neil.rewrite :as rw]
[babashka.neil.test :as neil-test]
[babashka.neil.version :as neil-version]
Expand Down Expand Up @@ -847,8 +870,9 @@ using the [major|minor|patch] subcommands.
(format "https://clojars.org/api/artifacts/%s"
qlib)))


(defn first-stable-version [versions]
(let [vparse (requiring-resolve 'version-clj.core/parse)]
(let [vparse (req-resolve 'version-clj.core/parse)]
(some (fn [version]
(let [{:keys [qualifiers]} (vparse version)]
(when-not
Expand Down Expand Up @@ -1308,7 +1332,7 @@ details on the search syntax.")))
Note that this is not a full dep coordinate - we rely on `dep-add` later to include
`:git/url`, for example."
[{:keys [current lib] :as _dep-update}]
(let [v-older? (requiring-resolve 'version-clj.core/older?)]
(let [v-older? (req-resolve 'version-clj.core/older?)]
(cond
(or (:git/tag current) (:tag current))
(when-let [tag (git/latest-github-tag lib)]
Expand Down Expand Up @@ -1586,6 +1610,7 @@ test
*command-line-args*
{:spec spec
:exec-args {:deps-file "deps.edn"}})
(shutdown-agents)
nil)

(when (= *file* (System/getProperty "babashka.file"))
Expand Down
2 changes: 1 addition & 1 deletion prelude
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
#_{:local/root "/Users/borkdude/dev/cli"}
{:mvn/version "0.6.45"}
version-clj/version-clj {:mvn/version "2.0.2"}
org.babashka/http-client {:mvn/version "0.0.2"}}})
org.babashka/http-client {:mvn/version "0.0.3"}}})
6 changes: 4 additions & 2 deletions src/babashka/neil.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[babashka.neil.git :as git]
[babashka.neil.new :as new]
[babashka.neil.project :as proj]
[babashka.neil.utils :refer [req-resolve]]
[babashka.neil.rewrite :as rw]
[babashka.neil.test :as neil-test]
[babashka.neil.version :as neil-version]
Expand Down Expand Up @@ -44,8 +45,9 @@
(format "https://clojars.org/api/artifacts/%s"
qlib)))


(defn first-stable-version [versions]
(let [vparse (requiring-resolve 'version-clj.core/parse)]
(let [vparse (req-resolve 'version-clj.core/parse)]
(some (fn [version]
(let [{:keys [qualifiers]} (vparse version)]
(when-not
Expand Down Expand Up @@ -505,7 +507,7 @@ details on the search syntax.")))
Note that this is not a full dep coordinate - we rely on `dep-add` later to include
`:git/url`, for example."
[{:keys [current lib] :as _dep-update}]
(let [v-older? (requiring-resolve 'version-clj.core/older?)]
(let [v-older? (req-resolve 'version-clj.core/older?)]
(cond
(or (:git/tag current) (:tag current))
(when-let [tag (git/latest-github-tag lib)]
Expand Down
7 changes: 4 additions & 3 deletions src/babashka/neil/new.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require
[babashka.neil.git :as git]
[babashka.neil.project :as proj]
[babashka.neil.utils :refer [req-resolve]]
[clojure.edn :as edn]
[clojure.set :as set]
[clojure.string :as str]))
Expand Down Expand Up @@ -137,7 +138,7 @@
{:create-opts create-opts})))

(defn- deps-new-create [create-opts]
((requiring-resolve 'org.corfield.new/create) create-opts))
((req-resolve 'org.corfield.new/create) create-opts))

(defn print-new-help []
(println (str/trim "
Expand Down Expand Up @@ -189,13 +190,13 @@ Examples:
This is required by org.corfield.new/create. In Clojure it's set by default,
but in Babashka it must be set explicitly."
[]
(let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))]
(let [classpath ((req-resolve 'babashka.classpath/get-classpath))]
(System/setProperty "java.class.path" classpath)))

(defn- deps-new-add-template-deps
"Adds template deps at runtime."
[template-deps]
((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}))
((req-resolve 'babashka.deps/add-deps) {:deps template-deps}))

(defn run-deps-new
"Runs org.corfield.new/create using the provided CLI options.
Expand Down
20 changes: 20 additions & 0 deletions src/babashka/neil/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns babashka.neil.utils)

;; Workaround for pmap + require which doesn't work well in bb - 2023-02-04

(def ^:private lock (Object.))

(defn- serialized-require
[& args]
(locking lock
(apply require args)))

(defn req-resolve
[sym]
(if (qualified-symbol? sym)
(or (resolve sym)
(do (-> sym namespace symbol serialized-require)
(resolve sym)))
(throw (IllegalArgumentException. (str "Not a qualified symbol: " sym)))))

;; End workaround

0 comments on commit 539fb4e

Please sign in to comment.