Fork me on GitHub
#babashka
<
2022-02-21
>
Oliver Marks06:02:29

I am trying to package bb I have just packaged jet and clj-kondo but running script/uberjar in the repo gives me an error. Execution error (FileNotFoundException) at babashka.impl.xml/eval181$loading (xml.clj:1). Could not locate sci/core__init.class, sci/core.clj or sci/core.cljc on classpath. Is there some prerequisit I am missing I woul have expected lein to pull sci ?

borkdude08:02:21

Oh yes, you also need to pull submodules

oly11:02:52

ah that may complicate things using the tar.gz release at present will have to do a bit of research to see if thats a thing in the context of a build

borkdude11:02:25

what are you trying to do, can you give more info?

oly11:02:54

building linux packages basically, they usesually want a source release which you checkout and build from

oly11:02:20

I think it can use git directly, just need to find out if I can pull the submodules as part of that

oly11:02:56

it may be I can just run a git command after to pull those in outside the initial pull

borkdude11:02:44

you can do it in one go

borkdude11:02:57

git clone  --recursive

borkdude11:02:20

or do it a second step.

oly11:02:41

yeah I am doing a bit of googling https://dev.getsol.us/D12925 thats for clj-kondo you specify a source location to fetch from

oly11:02:59

sure I can find a way around it though now I know thats needed

oly11:02:12

package.yaml being the main file

Oliver Marks19:02:14

cheers for the help earlier, with a bit of luck babashka should pop up in solus this week along with jet and clj-kondo 🙂

borkdude12:02:11

I think this self-contained executable approach could also work for babashka: https://www.youtube.com/watch?v=JRwxx2jc2zU&amp;t=1186s&amp;ab_channel=LeandroFacchinetti You would package babashka itself + your project in its own executable and then you could deploy it. The author is using a golang stub and a tarball of the project which extracts itself at runtime to implement it.

borkdude17:02:37

Documented producing a self-contained executable on the wiki: https://github.com/babashka/babashka/wiki/Self-contained-executable

🚀 3
caumond21:02:06

Hello, there. First thanks a lot for your work! it's awesome. I have a log file already there, and the two processes below should append to that log file. I try to launch some long living processes which should append to an existing (log) file (so I'd like them non blocking). I found no way to do that. Thanks in advance

(p/process ["npm" "install"]
             {:out :inherit :err :inherit :dir "app"})
(p/process ["npx" "shadow-cljs" "watch" "app2"]
             {:out :inherit :err :inherit :dir "app2"}))

borkdude21:02:21

@U018QDQGZ9Q :inherit means that the stream is written to the output stream of the babashka process. You can use (io/file "output.txt") instead to write the output to a file.

caumond21:02:24

I got this, but with`io/file`, I found no append option. I tried the example below and it did not work, I only have the last file output in it. Moreover, I'd like to append to an existing file:

(let [f (io/file "output.txt")]
    (p/process ["npx" "shadow-cljs" "watch" "app"]
               {:out f :err :inherit :dir "app"})
    (p/process ["npx" "shadow-cljs" "watch" "app"]
               {:out f :err :inherit :dir "app"}))

borkdude21:02:11

ah I got it. let me figure out a workaround. We should really add an option for this in process.

borkdude21:02:08

(doto (:pb (p/pb ["npx" "shadow-cljs" "watch" "app"]
                 {:err :inherit :dir "app"}))
  (.redirectOutput
   (java.lang.ProcessBuilder$Redirect/appendTo
    (io/file "/tmp/log.txt")))
  (.start))

borkdude22:02:07

But I will add better support for this

caumond22:02:06

Yes, I've just tested it and it perfectly fit in my use case !!!! thanks

borkdude12:02:25

@U018QDQGZ9Q in babashka 0.7.6 (just released) you can now do this: https://github.com/babashka/process#redirecting-output-to-a-file

👍 1
jaide22:02:53

https://replit.com/@eccentric-j/Babashka-Clojure?v=1 Nothing came up when searching for Babashka so hopefully this fixes that 😅 Going to make an nbb one too.

🎉 1
borkdude22:02:17

So if I understand correctly, replit supports nix out of the box?

jaide22:02:13

Yeah was able to use it as the base box, added babashka, clojure-lsp, and copied a bit of config for the .replit from the main clojure one

jaide22:02:27

have not published yet. https://replit.com/@eccentric-j/Node-Babashka-Template#package.json looks like nbb may be a bit trickier. Seems it has some custom interpreter support with their prybar library https://github.com/replit/prybar might have to try an upstream pr. Looking through the node one to see if it can be customized to run nbb at all

jaide22:02:19

Thinking I'll go for the naive get-it-done approach to make it similar to the babashka one. Then can support these other features later or someone can fork it and go for it.

borkdude22:02:03

what exactly is the problem here?

borkdude22:02:23

you might have to add "type": "module" to package.json to be allowed to import nbb

borkdude22:02:31

since nbb as a library is an ES6 module

jaide23:02:10

It's more that the node replit template supports a debugger and instead of running a command, runs an interactive console interpreter

borkdude23:02:52

hmm interesting

jaide23:02:12

But the interpreter seems like it's mostly suited for running the languages hard-coded into that repo like prybar-clojure or prybar-nodejs https://github.com/replit/prybar/tree/master/languages

jaide23:02:37

Given the clojure one, doesn't look like it would be too bad to create a PR to add languages/bb or languages/nbb but that's a bit more than I can take on atm so will set up the replit to run a nbb hello-world script like similar to the bb script, at least it will be consistent

borkdude23:02:25

We could embed this or at least link to this on the README of both projects

borkdude23:02:05

even this worked!

cli.core=> (range)
^C"Error: Script execution was interrupted by `SIGINT`"
cli.core=> 

jaide23:02:49

I think I like this approach of running the repl from within the main for these. This way if you just want to start trying out some cljs then there's the repl, and if you wanted to make a script of some kind they can comment it out and start writing as they're already in the defn main

jaide23:02:35

Updated the Babashka one to also run a repl in the main

edannenberg22:02:45

Hello, I'm currently looking into porting a fairly complex bash project to babashka, is there a way to implement sort of a plugin system with bashbaska? Which plugin (namespace?) to load would be determined by a passed arg, ideally users can add their own plugins via secondary class path.

borkdude22:02:44

That should certainly be possible

edannenberg22:02:18

Great. I got a little prototype that looks promising, except for the dynamic require. Any hints on how to approach this?

borkdude22:02:33

well, you can require dynamically using ... require :)

borkdude22:02:55

(require (symbol (first *command-line-args*)))

borkdude22:02:33

If you can share your prototype and where you are stuck, that would be easier to say something about. I'm sure there is a solution

borkdude22:02:52

It's almost midnight, but I'll look tomorrow

edannenberg23:02:13

(require (symbol (first *command-line-args*)))
Tried that, it ran but I didn't get the test output from the plugin. After your comment I put a println directly in the plugin ns which confirmed the ns was actually loaded. 🙈 Turns out the problem was that I tried to execute the function symbol directly which always returned nil . After a bit of googling using https://clojuredocs.org/clojure.core/ns-publics https://clojuredocs.org/clojure.core/resolve did the trick.

edannenberg23:02:31

Thank you for the awesome project btw, so nice to have Clojure on the shell. ❤️

borkdude08:02:56

cool! there is also a combination of require + resolve which is called requiring-resolve