Fork me on GitHub
#babashka
<
2021-03-31
>
borkdude09:03:11

A small demo how you might leverage fully qualified main functions: https://twitter.com/borkdude/status/1377185155077402627

borkdude10:03:57

Any Windows users want to help with this issue? https://github.com/babashka/babashka/issues/766

borkdude10:03:36

never mind, figured it out

borkdude10:03:47

Babashka shebang in a .bat script works!

babashka 3
grazfather15:03:07

I see you use bat

grazfather15:03:12

I am trying to get them to respect emacs modelines since they don’t respect bb on the shebang as clojure

borkdude15:03:54

who is them?

grazfather15:03:50

yeah, but bat would use bash syntax

borkdude16:03:02

oh you mean that bat, I thought you meant Windows .bat :)

grazfather16:03:40

Yeah, funny confusion 🙂

nate16:03:38

wow, impressive project automation with babashka, this is great to read through

lread16:03:10

Thanks Nate, I started in bash but have now fully embraced babashka!

borkdude17:03:33

@UE21H2HHD Just FYI, this pattern exists: https://book.babashka.org/#main_file Maybe it comes in handy somewhere in rewrite-clj if you want to prevent side effects when e.g. execute bb doc ...

lread18:03:26

Cool, thanks, I was going to switch to that convention when/if I switched to vanilla tasks, but I think it is probably worth doing now.

richiardiandrea16:03:46

If I create a uberjar or a uberscript, would my pods be included there as well?

borkdude17:03:25

pods are not included as they are platform specific

richiardiandrea17:03:17

I see, given target machine is compatible with dev machine, how would you recommend distributing a .bb script that uses, for instance, the sql pod?

borkdude17:03:25

@U0C8489U6 if you use (load-pod 'org.babashka/postgresql "0.0.x") the pod will be automatically downloaded

richiardiandrea17:03:52

yeah I am in an environment where I am not likely to access the internet

borkdude18:03:28

@U0C8489U6 In this case it's better to download the pod(s) yourself and copy them yourself to your artifact/docker image/container

👍 1
borkdude18:03:05

you can load pods also just using a path: (load-pod "./pod-babashka-postgresql")

richiardiandrea18:03:51

would just cloning the repo do the job there? (sorry newbie question)

borkdude18:03:54

cloning what repo?

richiardiandrea22:03:43

I have an additional question on this one...I have ":/home/cokap/.m2/repository/org/postgresql/postgresql/42.2.2/postgresql-42.2.2.jar" as result of babashka.classpath/get-classpath...why can't I (import 'org.postgresql.util.PGobject)? Am I missing something?

borkdude22:03:05

The postgres driver is not part of babashka, it's only part of the pod

borkdude22:03:34

do you want to transform something into json or an array?

richiardiandrea22:03:54

no unfortunately I have to store a BYTEA

borkdude22:03:11

ah, byte array, yeah, in this case you can just send over the byte array directly

borkdude22:03:23

and it will be stored automatically as bytea

richiardiandrea22:03:20

oh cool! I was worried for a second 😄 let me try that

richiardiandrea22:03:29

works flawlessly!

[query "INSERT INTO file_blobs (name, mime_type, byte_size, content) VALUES (?, ?, ?, ?) RETURNING id"
 sqlvec [query (:title image) (:mime-type image) (:byte-size image) (Files/readAllBytes (:jpath image))]
 inserted-rows (db/execute! db sqlvec)]

richiardiandrea00:04:47

#### [UPDATE diagnostic_reports SET image_descriptors = ? WHERE id = ? AND version_id = ? [{:image-id 3e3df4b6-0668-49aa-b1e6-c17375e98320, :image-included true, :image-caption Heart.jpg}] ed8d5263-b8ec-4e00-887b-bf1cfa65d42f 841d545d-8c62-4d49-8e52-60cb9f4e7318]
[Error] Rolling back "Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use."
This one is a puzzling one, does anyone spot any obvious problem?

lread17:03:43

Here’s a ramble-thought. My bb scripts used to fail fast if a they were not being run with a minimum version of bb. This was done as nicety for folks running my bb scripts. Instead of a mysterious failure, they’d get “hey, upgrade your bb, buddy”. I just removed this min version check because it, ironically, it was relying on recent bb features. My question is: Would it make sense for a bb script or maybe bb.edn to somehow specify a min version of bb and fail fast if that version is not met? I realize this would only help bb versions moving forward, so maybe my idea is a bit late.

borkdude17:03:18

Oh, that's a great suggestion! I was considering adding something code-wise in bb for it: https://github.com/babashka/babashka/issues/663 but adding this to bb.edn is probably even better

onetom02:04:29

node.js has a similar feature for ensuring the version of the runtime (and even the OS and the CPU arch): https://docs.npmjs.com/cli/v7/configuring-npm/package-json#engines it's not necessarily the best place to copy ideas from, but might give u some ideas.

borkdude17:03:05

I also quite like the version-clj library, but this isn't built-in and have people require it just to compare the bb version is a bit too much overhead maybe

lukasz17:03:00

(remind's me of a similar config option in Leiningen )

lread17:03:39

I am surprised more languages don’t offer this kind of check. Or maybe they do, and I am just not aware. I mean backward compatibility is great but it would be nice to effectively say, “yeah, we don’t support forward compatibility, you’ll need to upgrade” instead of failing mysteriously when an old version of tool x tries to access a non-existent new feature.

borkdude17:03:23

lein supports it but deps.edn doesn't (yet?)

lread17:03:42

maybe soon (?) with this new build support coming to clojure cli in the pipes.

borkdude17:03:26

I guess in deps.edn you can just say {:deps {org.clojure/clojure {:mvn/version "1.11.0"}}} and that's your minimum version

borkdude17:03:03

does pom.xml support a min java version?

lread17:03:11

Oh yeah, I suppose you are right there.

lread17:03:39

Can’t remember about pom.xml I think there is something in there about what version you want to compile to.

borkdude17:03:51

This is maybe a bad idea, but we could (not should) make :min-bb-version download the min bb version and run the project using that one, so the system bb invokes the needed bb if it's below the minimum

borkdude17:03:24

but I guess the first minimal step is just exit with an error

lread17:03:27

Gradle just wafted into my brain. I think I remember it downloading whatever version the gradle file specifies.

borkdude17:03:43

yeah, boot does that too using boot.properties

borkdude17:03:07

but both gradle and boot aren't very popular, so maybe that's a bad sign? ;)

lread17:03:58

Ha! I vaguely remember kinda liking gradle, but I was young and impressionable.

borkdude17:03:01

I heard some people get caught up with the DSL and making builds way too complex

borkdude17:03:20

I don't have any experience with it myself

lread17:03:31

Mind you I was coming from maven. So…

borkdude17:03:59

I know maven only through clojure, I guess I'm shielded a little bit

lread17:03:26

Ya, I remember it being convenient - so long as you didn’t want to do anything it does not normally do, then, oh boy!

borkdude17:03:37

then use make/bash + XML-generate the pom.xmls? Sounds a bit like what I'm doing now with deps.edn sometimes ;)

lukasz17:03:26

From a security perspective you don't want tools to randomly download binaries, just saying

borkdude17:03:09

@lukaszkorecki Yeah, I understand from that point of view. I started wondering though: what's the difference with downloading binaries (from a controlled source) or .jar files for that matter? Both can screw up your system, but somehow binaries are often considered more suspicious

lukasz17:03:00

Jars are not usually executable, in this case a binary downloads another binary and replaces itself, right?

lukasz17:03:27

In some setups machines come with pre-installed stuff, and this approach might not even be an option

borkdude17:03:09

Note that pod binaries can now be downloaded automatically from a pod registry when loading them, this was by popular request. The bb binary would not replace the system bb, the system bb would just delegate to the newer one if needed.

lukasz17:03:28

I see. Maybe this should be an opt-in?

borkdude17:03:57

Yeah, I'm not implementing this in the foreseeable future, just throwing it out here for initial feedback.

lukasz17:03:02

:thumbsup:

borkdude17:03:52

anyway, :min-bb-version seems like a good idea for bb.edn

lread18:03:17

yeah @lukaszkorecki I sometimes do work on cljdoc and it has a (probably not well known?) feature where you can download a zipped version of docs for offline viewing. I was thinking this could be a potential vehicle, however unlikely, to get something nasty on somebody’s system, if we aren’t careful.

richiardiandrea00:04:47

#### [UPDATE diagnostic_reports SET image_descriptors = ? WHERE id = ? AND version_id = ? [{:image-id 3e3df4b6-0668-49aa-b1e6-c17375e98320, :image-included true, :image-caption Heart.jpg}] ed8d5263-b8ec-4e00-887b-bf1cfa65d42f 841d545d-8c62-4d49-8e52-60cb9f4e7318]
[Error] Rolling back "Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use."
This one is a puzzling one, does anyone spot any obvious problem?