nbb

grzm 2022-08-30T04:23:43.685559Z

I'm hoping to use the com.stuartsierra/component library with nbb. (I'm also pretty new to nbb.) I can't seem to load it directly.

npx nbb --classpath $(clojure -Sdeps '{:deps {com.stuartsierra/component {:mvn/version "1.1.0"}}}' -Spath) -e "(require 'com.stuartsierra.component)"
----- Error --------------------------------------
Message:  Could not find namespace: com.stuartsierra.component
Could not find namespace: com.stuartsierra.component

borkdude 2022-09-01T14:47:30.448339Z

Looking at this message now

borkdude 2022-09-01T14:49:13.765819Z

Yes, a failing test is a good start :-D

borkdude 2022-09-01T14:49:38.127409Z

I'll also take a look at this to investigate some possibilities

grzm 2022-09-01T15:09:05.598339Z

Cheers. What's your development workflow for, say, testing the behavior of a sci change in nbb? For example, when you added clj->str in sci, and confirmed that the next issue for component was IPrintWithWriter, what was your setup? I assume you made a local sci build, used that in a local nbb build, and then used that nbb build on either the component source directly or via nbb.edn.

borkdude 2022-09-01T15:10:07.537149Z

I added type->str directly in nbb, but in general, yes, that

borkdude 2022-09-01T15:10:32.938739Z

but in this issue, I would usually just test on SCI directly

borkdude 2022-09-01T15:10:46.356019Z

and then add the new version of SCI to nbb

grzm 2022-09-01T15:11:59.498069Z

Right. My goal was to confirm that I was seeing the same deref error in nbb that I'm seeing in the failing sci test (to replicate what you did to find the next failure make sure I was setting up the test correctly, given I'm really cargo-culting/learning by example here)

borkdude 2022-09-01T15:13:06.374009Z

What I did to test with component, was, I added it in nbb.edn, added test->str in nbb and then commented out the IPrintWithWriter in the .nbb directory

grzm 2022-09-01T15:13:39.089279Z

(The deref error appears "odd" enough—far enough removed from the IPrintWithWriter protocol stuff—that I wasn't sure I wasn't just screwing up writing the test.)

grzm 2022-09-01T15:14:24.224599Z

Cool. I'll see if I can follow that methodology myself.

borkdude 2022-09-01T15:15:52.004079Z

I added some notes here: https://github.com/babashka/sci/issues/794

🙏 1
grzm 2022-09-01T15:17:35.992709Z

Gosh, now I want to work on this now. But $dayjob beckons.

grzm 2022-09-01T15:17:47.734419Z

Thanks for looking at this.

borkdude 2022-09-01T16:11:22.110299Z

@grzm 75693266c6690b0971155bd6139d9854e2b1289a fixes the weird deref error message and gives a better error message

😄 1
borkdude 2022-09-01T16:11:27.501829Z

(on master)

grzm 2022-09-01T16:18:10.964109Z

Nice. Good error messages are so helpful. I spent a couple of hours yesterday and the day before improving some in some internal tool that I released after Real Users™ found the edge cases I didn't catch.

grzm 2022-09-01T16:19:12.683799Z

ERROR in (iprint-with-writer-test) (/Users/grzm/dev/sci/test/sci/core_protocols_test.cljc:118:10)
expected: (= "#<Foo>" (eval* "(defrecord Foo [])\n                             (extend-protocol IPrintWithWriter\n                               Foo\n                               (-pr-writer [this writer opts]\n                                 (-write writer \"#<Foo>\")))\n                             (pr-str (->Foo))"))
  actual: #error {:message "Protocol not found: IPrintWithWriter", :data {:type :sci/error, :line 2, :column 30, :message "Protocol not found: IPrintWithWriter", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 2, :column 30, :ns #object[sci.lang.Namespace], :file nil} {:line 2, :column 30, :ns #object[sci.lang.Namespace], :file nil, :sci.impl/f-meta {:ns #object[sci.lang.Namespace], :macro true, :sci/built-in true, :name extend-protocol}})}], :file nil}, :cause #error {:message "Protocol not found: IPrintWithWriter", :data {:type :sci/error, :line 2, :column 30, :file nil}}}
😄

borkdude 2022-08-30T09:21:58.398209Z

The next error after type->str I get is:

user=> (require '[com.stuartsierra.component :as component])
"#error {:message \"No protocol method IDeref.-deref defined for type null

borkdude 2022-08-30T09:26:26.265329Z

Ah this hinges on IPrintWithWriter on line 185. When I remove this, then it all seems to work

borkdude 2022-08-30T09:26:42.566179Z

We should somehow add support for IPrintWithWriter...

borkdude 2022-08-30T09:27:00.997569Z

but maybe you can fork for now and remove this, so you won't be blocked by this

grzm 2022-08-30T12:37:00.409499Z

re: jars vs nbb. Thanks for the reminder. I knew that a couple of weeks ago and forgot it in the interregnum.

grzm 2022-08-30T12:38:20.654269Z

re: type->str is this a case of "nbb doesn't have support yet" or "this isn't something nbb is likely to support in the future and we could look at an upstream patch to component"?

borkdude 2022-08-30T12:47:20.791899Z

I added that on master now

grzm 2022-08-30T12:48:29.203129Z

Cheers!

grzm 2022-08-30T13:23:01.264239Z

What's the path for IPrintWithWriter support? It looks like SciRecord implements it, but there's a piece I must be missing: https://github.com/babashka/sci/blob/3288e2988594a20daaadb4ee0662e0c2b2a8ca01/src/sci/impl/records.cljc#L223-L226

borkdude 2022-08-30T13:25:12.155649Z

@grzm Hmyeah. For the JVM Clojure path, there is hard-coded support for print-method (which is the JVM equivalent of IPrintWithWriter ). We should probably do something similar for the CLJS path. Haven't looked into this that much yet

borkdude 2022-08-30T13:25:39.331569Z

But I have ran into this a couple of times, so it's probably good to address this sooner than later

grzm 2022-08-30T13:26:23.480009Z

I noticed it came up in one of my first SCI issues 😉 https://github.com/babashka/sci/issues/684

grzm 2022-08-30T13:26:58.112579Z

Clearly I've got some kind of inner magnetic pull towards this thing.

borkdude 2022-08-30T13:27:48.069309Z

Ah, right, well, print-method now works :)

grzm 2022-08-30T13:28:28.784099Z

Indeed it does! The progress you've made in this whole ecosystem is just amazing.

grzm 2022-08-30T13:29:00.965309Z

And (as always happens) you rightly pointed out a better solution to what I was actually trying to do.

borkdude 2022-08-30T13:30:18.042489Z

I made a new issue: https://github.com/babashka/sci/issues/794

👀 1
grzm 2022-08-30T04:26:06.097589Z

Taking a look at the component library itself, I see there's a cljs.core/type->str function used in com.stuartsierra.component.platform namespace. I think this might not be available in nbb.

grzm 2022-08-30T04:28:22.480399Z

As a way to confirm, I translated the component project.clj to deps.edn and ran:

npx nbb --classpath $(clojure -Spath) -e "(require 'com.stuartsierra.component.platform)"
----- Error --------------------------------------
Message:  Could not resolve symbol: type->str
Phase:    analysis
Could not resolve symbol: type->str

grzm 2022-08-30T04:30:06.025599Z

Is this likely the root of why the component library can't be loaded? I didn't see any other nbb error logging, but I haven't dug in further.

borkdude 2022-08-30T06:06:54.073209Z

The issue is that nbb doesn't load jar files. This is documented in the README. You can use nbb.edn though

borkdude 2022-08-30T06:07:29.797979Z

What that does is copy the jar files to a working directory and unzips them, then adds them to the classpath

👍 1
grzm 2022-09-01T04:32:30.452969Z

Been seeing how frustrated I can make myself how much I can learn by poking around and trying to implement this. I've got a failing test (as expected) and would like to confirm the behavior of my local SCI build (from master including the type->str fix) in nbb with the component library. Would you say this is a reasonable thing to do? Or is there a shorter, more direct approach you'd recommend?

grzm 2022-09-01T04:35:34.507139Z

(Here's the test I've written, unfinished, but minimal which shows a failure):

(ns sci.core-protocols-test ,,,)
,,,
#?(:cljs
   (deftest iprint-with-writer-test
     (is (= "#<Foo>" (eval* "(defrecord Foo [])
                             (extend-protocol IPrintWithWriter
                               Foo
                               (-pr-writer [this writer opts]
                                 (-write writer \"#<Foo>\")))")))))
And it even fails 🙂
% script/test/node -n sci.core-protocols-test
Running CLJS test in Node with optimizations :none

Testing sci.core-protocols-test

ERROR in (iprint-with-writer-test) (/Users/grzm/dev/sci/test/sci/core_protocols_test.cljc:118:10)
expected: (= "#<Foo>" (eval* "(defrecord Foo [])\n                             (extend-protocol IPrintWithWriter\n                               Foo\n                               (-pr-writer [this writer opts]\n                                 (-write writer \"#<Foo>\")))"))
  actual: #error {:message "No protocol method IDeref.-deref defined for type null: ", :data {:type :sci/error, :line 2, :column 30, :message "No protocol method IDeref.-deref defined for type null: ", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 2, :column 30, :ns #object[sci.lang.Namespace], :file nil} {:line 2, :column 30, :ns #object[sci.lang.Namespace], :file nil, :sci.impl/f-meta {:ns #object[sci.lang.Namespace], :macro true, :sci/built-in true, :name extend-protocol}})}], :file nil}, :cause #object[Error Error: No protocol method IDeref.-deref defined for type null: ]}

Ran 5 tests containing 9 assertions.
0 failures, 1 errors.