Fork me on GitHub
#babashka
<
2022-04-17
>
craftybones06:04:53

@borkdude - small suggestion. Can babashka have a function that returns a simple bb.edn template? This way, I can make a bb.edn by merely evaling a function in the REPL

borkdude06:04:26

Yes, we could have something like bb init

borkdude06:04:47

Please post an issue

craftybones06:04:17

or even just a *bb.edn*

craftybones06:04:30

I wish clojure had it too. A simple way of just evaling a deps.edn into existence

andy.fingerhut18:04:42

OK, sorry for very basic simple questions here, but I've been living under a rock where babashka wasn't in use before. Details of my question in reply thread.

andy.fingerhut18:04:31

This bb.edn file has many keys in a map that is the value of its :tasks key: https://github.com/clj-kondo/clj-kondo.lsp/blob/master/bb.edn#L48-L51

andy.fingerhut18:04:04

including lsp-jar as one of the keys, which I've linked directly to the lines that define it.

andy.fingerhut18:04:26

It contains this key/value pair: :depends [java1.8 build-server -jar]

andy.fingerhut18:04:53

and the Clojure code that is the value of the :task key just after that contains an occurrence of the symbol -jar

borkdude18:04:12

The tasks on which this task depends bring in values that can be used in the task

andy.fingerhut18:04:13

I am guessing that this :depends is something like a Makefile dependency, where all :depends tasks are executed first, recursively if those tasks have their own :depends non-empty sequence of tasks, and then the return value of the task -jar becomes the value of the symbol -jar in the code of lsp-jar's :task ?

andy.fingerhut18:04:51

What would you recommend as a good way to learn the return value of a function like fs/copy in bb? I tried (doc fs/copy) in a bb interactive session, which gave some docs, but doesn't mention the return value. A reasonable guess is that it returns either the source or destination path of the fs/copy, but not obvious which.

andy.fingerhut18:04:06

(and for fs/copy being successful, I guess it doesn't matter much which)

andy.fingerhut18:04:18

(source fs/copy) in a bb interactive session shows "Source not found"

borkdude18:04:38

@U0CMVHBL2 if the return value is not specified I would say it's undefined :)

borkdude18:04:00

(i.e. I probably didn't think hard enough about that)

andy.fingerhut18:04:36

Your bb.edn file uses the return value of fs/copy, I think, yes?

andy.fingerhut18:04:54

in the lines that I highlighted, as the value of the symbol -jar

borkdude18:04:56

The return value is the return value java java.nio.file.Files/copy

andy.fingerhut18:04:40

I'm not complaining, by the way, or saying there is a bug or anything. Just looking for recommended ways to discover the behavior here.

borkdude18:04:46

Docs should probably be more clear on this

andy.fingerhut18:04:43

I did find in the doc page on bb tasks you linked that I can find out experimentally for that bb.edn file what the return value of a task is by running a command like this: bb run --prn lsp-jar which shows that copy returns the source file here, so I'm good to go.

👍 1
_II_23:04:53

Is it normal that when I create bb uberjar with deps it doesn't work?

_II_23:04:07

the app works without uberjaring, also if I create an uberjar but don't use honeysql - the uberjar works fine.

_II_23:04:33

but if I uberjar with honeysql as dep - then - after compiling the jar I have this message: ^--- Could not find namespace: honeysql.core.

_II_23:04:06

without using honeysql in the uberjar, using simple sql strings with a pod go-sqlite3 it works

_II_23:04:20

my bb.edn is

_II_23:04:21

{:paths ["src"] :deps { honeysql/honeysql {:mvn/version "1.0.461"} } :pods { org.babashka/go-sqlite3 {:version "0.1.0"} } }

_II_23:04:31

also I tried adding deps.edn file with { honeysql/honeysql {:mvn/version "1.0.461"} }

_II_23:04:37

but no luck

borkdude07:04:20

How did you create the uberjar, with bb uberjar?

_II_08:04:02

Hello! yes of course

_II_08:04:22

I call it "bb uberjar"

_II_08:04:46

also maybe it wouldnt be a bad idea if "bb uberjar" generated <appname>.bb.jar instead of .jar

borkdude08:04:56

This worked fine for me:

bb uberjar app.jar
bb -cp app.jar -e "(require 'honeysql.core)"

borkdude08:04:26

The name of the jar up to you

_II_08:04:34

right now I'm at my office

_II_08:04:41

bb uberjar
that one worked?

borkdude08:04:23

bb uberjar app.jar

borkdude08:04:38

This will produce a jar file called app.jar

_II_08:04:26

yes of course

_II_09:04:21

I mean "bb uberjar" with honeysql produced a jar file that works? or you have to put -e "(require 'honeysql.core)" ?

borkdude09:04:35

> a jar file that works

borkdude09:04:12

What exactly do you mean by this? You have to be more specific. Or you can create a repository that someone can clone locally to exactly see what you are seeing.

borkdude09:04:35

You can specify a main function with -m foo.bar that will execute when you run the uberjar with bb app.jar

borkdude09:04:45

It's not clear to me if you mean this

_II_09:04:49

yes sorry I'm bit distracted right now

_II_09:04:25

I didn't remember exactly the command

_II_09:04:47

I make jar with

_II_09:04:48

bb -cp $(clojure -A:remove-clojure -Spath) uberjar bbapp1.bb.jar -m http://bbapp1.app

borkdude09:04:34

if you use bb.edn, you don't need the -A:remove-clojure thing. Where did you read that? I should probably remove that.

_II_09:04:23

it's from the book I use this one

_II_09:04:39

bb -cp $(clojure -Spath) uberjar bbapp1.bb.jar -m http://bbapp1.app

_II_09:04:29

I just copied it right now to check if it works, sorry I'm with few things at the same time xD

_II_09:04:07

I'm gonna check if this works with -e "(require 'honeysql.core)"

_II_09:04:12

(ns http://bbapp1.app (:require [honeysql.core :as hsql] [honeysql.helpers :refer [select where from] :as helpers]) (:gen-class)) (defn -main [& a_args] (println "OK?"))

_II_09:04:19

this is the program

_II_09:04:44

this is the bb.edn

_II_09:04:45

{:paths ["src"] :deps {honeysql/honeysql {:mvn/version "1.0.461"}} :pods {}}

_II_09:04:22

that is the structure

_II_09:04:39

the thing is that if I do

_II_09:04:56

it works

_II_09:04:13

if I do this:

_II_09:04:14

bb -cp $(clojure -Spath) uberjar bbapp1.bb.jar -e "(require 'honeysql.core)" -m http://bbapp1.app

_II_09:04:25

it makes a jar but it throws this

borkdude09:04:30

remove -cp ...

borkdude09:04:41

you do not need that

borkdude09:04:45

also remove -e

_II_09:04:09

you're right

_II_09:04:31

it was because of -cp

borkdude09:04:57

because then it uses the dependencies from deps.edn, not from bb.edn

_II_09:04:22

well for me the Java world, classpaths and all that is a reason why I don't use java

borkdude09:04:44

I simplified the book now

borkdude09:04:11

(will take a few minutes for the github docs to refresh)

borkdude09:04:24

ah it's there now. please refresh

_II_09:04:33

thank you very much

_II_09:04:50

would it be possible to implement something like "bb init"

_II_09:04:07

so it creates bb.edn

borkdude09:04:15

yes, there is a new issue for this since yesterday.

_II_09:04:27

and bb i honeysql.core

_II_09:04:32

turning to npm

_II_09:04:51

I'm too used to node and npm

_II_10:04:12

and convention over config

borkdude10:04:30

There is this command line tool you can use: https://github.com/babashka/neil It is is babashka script to add dependencies etc to deps.edn or bb.edn

borkdude10:04:47

If you are used to node.js then you might like #nbb

borkdude10:04:00

You can use any Node.js dependency from that.

_II_10:04:03

I'm sure I'll like it

_II_10:04:19

but for now I'm like trying to forget about node a bit

_II_10:04:56

also maybe if Neil is ready you should feature it at https://babashka.org/

_II_10:04:16

just to say you - you are great! thank you

borkdude10:04:06

:smiling_face_with_3_hearts: