Fork me on GitHub
#babashka
<
2021-09-30
>
mmer13:09:45

Hi, I was wondering if it is possible to run 'portal' against a bb nrepl? All the portal examples use the clj repl.

borkdude14:09:34

@mmer this should be possible. @djblue may know

borkdude14:09:19

@mmer in the README of portal:

bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "0.15.1"}}}'
`

borkdude14:09:36

and then follow the JVM example

borkdude14:09:49

you can now also put that dependency in bb.edn

mmer14:09:04

@borkdude does that start an nrepl?

borkdude14:09:21

ah sorry, nrepl

borkdude14:09:38

just do the same but append nrepl-server to the bb invocation

borkdude14:09:48

and then you can execute the JVM example from your connected editor?

borkdude14:09:29

I just checked and it worked for me

borkdude14:09:40

With this bb.edn : {:deps {djblue/portal {:mvn/version "0.15.1"}}}

👍 1
borkdude14:09:02

And then bb nrepl-server from the terminal

mmer14:09:30

Thanks - not sure why it worked this time

Spencer Apple16:09:03

Can you require other bb files? Or what’s the best way to build a library of common bb fns/modules? Ideally I would like some bb files to be my library code, that my scripts could then require and use. The two ways I would imagine it working from the book: • are using bb.edn with the paths set • using preloads https://book.babashka.org/#_preloads

borkdude16:09:27

@splayemu Yes, if you set bb.edn to {:paths ["."]} you can just require any script from the top level of your project. You can also choose another directory

🙌 1
borkdude16:09:49

so with that you can:

./foo.clj
(require '[foo :as f])

borkdude16:09:17

or {:paths ["script"]}

script/foo.clj
(require '[foo :as f])

borkdude16:09:45

Perhaps we should just add the current working directory to the classpath automatically (in nbb I've done this)

borkdude16:09:03

Then you could do (require '[script.foo :as f])

Spencer Apple16:09:57

Thank you a ton! I now realize my problem was my directory structure didn’t equal my ns name, so I guess deps.clj couldn’t find the namespace I was looking for.

👍 1
Spencer Apple16:09:01

Is there a similar thing for BB as CLJ_CONFIG?

CLJ_CONFIG=../.clojure

borkdude16:09:18

@splayemu do you mean for bb.edn ?

borkdude16:09:23

What's the use case?

Spencer Apple16:09:37

Yeah for bb.edn

Spencer Apple16:09:33

In a monorepo, I want to execute scripts from various sub directories. Would like all the paths (and eventually tasks) to be able to execute from any sub directory.

borkdude16:09:32

What you could also do is make a root bb.edn and use :dir (as in (shell {:dir ..} ..) and (clojure {:dir ...} ...) to execute commands in dirs from the root dir?

1
borkdude16:09:57

invoke with:

bb native-image-test :dir config/com.taoensso/nippy/example :graalvm-version 21.1.2

borkdude16:09:04

There is an issue about what you are talking about I think here: https://github.com/babashka/babashka/discussions/869 Feel free to contribute to the discussion. What I'm missing most is a complete mono-repo setup where this kind of usage makes sense and I can try locally.

borkdude16:09:34

At work we have a mono-repo setup but each project just has its own bb.edn since the tasks are quite unique for each sub-project

borkdude16:09:58

What you can also do is split the code you want to use into a library and then use this library from each bb.edn

borkdude16:09:04

using :local/root

Spencer Apple16:09:41

👀 :thinking_face:

borkdude16:09:05

you can see how local/root works here: https://clojure.org/guides/deps_and_cli

Spencer Apple16:09:41

ah yeah that’s what we do for our non bb code

Spencer Apple17:09:56

okay let me try some of these suggestions out, thanks a lot for your hard work and quick responses! really appreciate it and love bb

ag18:09:52

Is there a way to change dir and stay there?

borkdude18:09:28

@ag That's a common question and unfortunately this is not possible in a JVM-ish environment. But on the other hand, it can also seen as a source of less confusion. E.g. when you change paths, and require a namespace or load-file, suddenly your relative root has changed?

borkdude18:09:50

The counter-solution to this is to pass :dir arguments to functions that need to be aware of a prefixed directory

borkdude18:09:03

Both shell and clojure support them in babashka.tasks for example

borkdude18:09:14

Also babashka.process/process

borkdude18:09:50

In nbb it is possible:

$ nbb -e '(js/process.chdir "proj") (js/process.cwd)'
"/private/tmp/proj"
This is because node allows it.

ag18:09:09

ah, right. I just remembered I've had this problem before.

ag18:09:00

I'm gonna do it without having to stay in the same dir. but thank you for nbb suggestion.

colliderwriter21:09:41

Has any thought been given to a sci-derivate package updater? I'm starting to lose track of which clj-kondo or babashka or pcp etc (neil?) i have installed and whether updates are available. Someone must have a clever solution already.

borkdude21:09:52

the three tools you mention are available via brew

borkdude21:09:48

I did start to write my own package manager a while back: https://github.com/borkdude/glam But I haven't been using it much. I figured it makes sense to go with the flow: people won't switch to a niche package manager for just a few packages?

colliderwriter21:09:10

Linux laptop here, so brew itself is a foreign package manager:) . I'm not sure where the line is either

borkdude21:09:53

brew works for linux