babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2020-09-20T07:30:25.023100Z

@rickmoynihan Awesome. PRs welcome

šŸ‘Œ 1
borkdude 2020-09-20T09:45:33.024300Z

@rickmoynihan I made the following issue related to your attempt to make these libraries work with bb: - https://github.com/borkdude/sci/issues/418 (support invoking constructor on records) Also I included the exception type in bb master now. Regarding spec: Please leave a message here https://github.com/borkdude/babashka/issues/558 if you think spec proper should be included in bb.

2020-09-21T07:28:10.028Z

Yeah Iā€™d seen this issue, but I donā€™t feel qualified to contribute to the discussion at this stage. Presumably including spec1 will bloat the binary somewhat, and itā€™ll be hard to remove. How many libs can you statically link and maintain in the bb binary? FWIW the spartan.spec hack seemed sufficient (putting a :bb conditional over the require in integrant) for getting integrant to work.

borkdude 2020-09-21T07:30:21.028400Z

Why does integrant need spec though?

2020-09-21T07:31:16.028600Z

It has a phase of initialisation called ig/pre-init-spec where you can hook specs in to validate a components config

borkdude 2020-09-21T07:31:47.028800Z

ah

2020-09-21T07:33:14.029100Z

Strictly speaking though I agree it could have that phase but not depend on spec. It really only depends on it so it can raise an error with an s/explain message that includes the name of the component that failed the spec.

2020-09-21T07:38:37.029300Z

I guess it could in theory be made pluggable in this regardā€¦ Though that might mean some systems end up needing a combination of spec and another validation lib; as itā€™d make each component specify itā€™s validator; rather than having a single standard one for all systems.

borkdude 2020-09-20T09:46:37.024900Z

> though it would be nice to run the test suites for dependency and integrant under the bb environment bb also supports clojure.test

2020-09-21T07:24:39.027700Z

:thumbsup: Yeah Iā€™d seen this, I just hadnā€™t got around to running the projects test suites with your test runner snippet. https://github.com/borkdude/babashka#running-tests

2020-09-21T08:10:24.029600Z

Where is borkdude.deps-test defined? I get the following error:

2020-09-21T08:10:39.029800Z

2020-09-21T08:11:35.030200Z

ah I think thatā€™s my projectā€¦

borkdude 2020-09-21T08:13:11.030400Z

deps-test is just an example

šŸ‘ 1
2020-09-21T08:13:12.030600Z

Yeah it is ā€” please ignore

2020-09-21T08:14:29.030900Z

I clearly need more coffee ā€” eyes glazing over šŸ˜³

borkdude 2020-09-21T08:15:08.031100Z

no problem :)

borkdude 2020-09-20T09:46:58.025400Z

I would also be happy to run your projects under the smoke tests that are running with bb in CI

borkdude 2020-09-20T09:47:06.025600Z

(see script/run_lib_tests)

borkdude 2020-09-20T10:06:36.026300Z

@rickmoynihan lol, the record constructor already works with bb master:

user=> (defrecord Foo [x])
#'user/Foo
user=> (Foo. 1)
{:x 1}
user=> (ns bar)
nil
bar=> (import user.Foo)
nil
bar=> (Foo. 1)
{:x 1}
Just not released yet. Try with latest binary from master in #babashka_circleci_builds

šŸŽ‰ 1
2020-09-21T08:18:32.031300Z

Ok I think thereā€™s a bug/limitation with constructor support

2020-09-21T08:19:00.031500Z

If the constructor call occurs inside the defrecord definition it doesnā€™t work

2020-09-21T08:19:07.031700Z

e.g.

2020-09-21T08:19:11.031900Z

(defrecord MapDependencyGraph [dependencies dependents]
  DependencyGraph
  (immediate-dependencies [graph node]
    (get dependencies node #{}))
  (immediate-dependents [graph node]
    (get dependents node #{}))
  (transitive-dependencies [graph node]
    (transitive dependencies #{node}))
  (transitive-dependencies-set [graph node-set]
    (transitive dependencies node-set))
  (transitive-dependents [graph node]
    (transitive dependents #{node}))
  (transitive-dependents-set [graph node-set]
    (transitive dependents node-set))
  (nodes [graph]
    (clojure.set/union (set (keys dependencies))
                       (set (keys dependents))))
  DependencyGraphUpdate
  (depend [graph node dep]
    (when (or (= node dep) (depends? graph dep node))
      (throw (ex-info (str "Circular dependency between "
                           (pr-str node) " and " (pr-str dep))
                      {:reason ::circular-dependency
                       :node node
                       :dependency dep})))
    (MapDependencyGraph.
     (update-in dependencies [node] set-conj dep)
     (update-in dependents [dep] set-conj node)))
  (remove-edge [graph node dep]
    (MapDependencyGraph.
     (update-in dependencies [node] disj dep)
     (update-in dependents [dep] disj node)))
  (remove-all [graph node]
    (MapDependencyGraph.
     (remove-from-map dependencies node)
     (remove-from-map dependents node)))
  (remove-node [graph node]
    (MapDependencyGraph.
     (dissoc dependencies node)
     dependents)))

borkdude 2020-09-21T08:20:55.032100Z

ah makes sense. I'll make an issue in sci

šŸ‘ 1
2020-09-21T08:21:54.032300Z

Minimal example here:

2020-09-21T08:21:56.032500Z

user=>  (defprotocol Foo (foo [a]))
{:ns #object[sci.impl.vars.SciNamespace 0x70ea4d21 "user"], :methods #{#object[clojure.lang.MultiFn 0x16f3c5e "clojure.lang.MultiFn@109ab8718"]}}

user=>  (defprotocol Foo (foo [a]))
: Could not resolve symbol: user=>
user=> {:ns #object[sci.impl.vars.SciNamespace 0x70ea4d21 "user"], :methods #{#object[clojure.lang.MultiFn 0x16f3c5e "clojure.lang.MultiFn@109ab8718"]}}
user=>

borkdude 2020-09-21T08:22:29.032800Z

borkdude@MBP2019 ~ $ clj
Clojure 1.10.1
user=> (defprotocol IFoo (foo [this]))
IFoo
user=> (defrecord Foo [x] IFoo (foo [this] (Foo. x)))
user.Foo
user=> ^D
borkdude@MBP2019 ~ $ rlwrap bb
Babashka v0.2.1-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=>  (defprotocol IFoo (foo [this]))
{:ns #object[sci.impl.vars.SciNamespace 0x3b233ecd "user"], :methods #{#object[clojure.lang.MultiFn 0x75d2c228 "clojure.lang.MultiFn@108b423c8"]}}
user=>  (defrecord Foo [x] IFoo (foo [this] (Foo. x)))
: Unable to resolve classname: Foo
user=>

borkdude 2020-09-21T08:22:49.033Z

I think the second example should read something with defrecord maybe?

2020-09-21T08:24:14.033200Z

Yeah sorry I pasted you the wrong bit :thumbsup:

2020-09-21T08:24:36.033400Z

(defrecord Bar [] Foo (Bar.))
: Could not resolve symbol: user/Bar.

borkdude 2020-09-21T08:25:06.033700Z

nice. Pasted the issue here: https://github.com/borkdude/sci/issues/419

borkdude 2020-09-21T08:25:42.034100Z

Luckily this does work for now:

(defrecord Foo [x] IFoo (foo [this] (->Foo x)))

2020-09-21T08:25:43.034300Z

Thanks :thumbsup:

borkdude 2020-09-20T10:07:48.027Z

I hope to make a new release somewhere end of this week

borkdude 2020-09-20T21:22:36.027500Z

On master:

$ bb -e "(require '[org.httpkit.server :as srv]) (srv/run-server (fn [_] {:body \"Hello\"}) {:port 8088}) @(promise)"
WARNING: the org.httpkit.server namespace is experimental and may be removed in future versions of babashka.
Please leave a note at <https://github.com/borkdude/babashka/issues/556> to let us know how you are using it.
You can turn this warning off using -Dbabashka.httpkit-server.warning=false
This namespace will remain available under a feature flag, see <https://github.com/borkdude/babashka/blob/master/doc/build.md#feature-flags>
$ bb -Dbabashka.httpkit-server.warning=false -e "(require '[org.httpkit.server :as srv]) (srv/run-server (fn [_] {:body \"Hello\"}) {:port 8088}) @(promise)"