babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Karol Wójcik 2021-04-23T08:20:11.384500Z

@borkdude Can I join babashka pods paths? I would like to take some default pods from ~/.babashka and some other from /.native-deps

borkdude 2021-04-23T08:35:13.384900Z

@karol.wojcik I'm not sure what you want to do with the joined path?

Karol Wójcik 2021-04-23T08:37:52.388300Z

I want to pack babashka runtime as an AWS Layer with babashka-aws as a default pod. Default pods will be stored in .babashka folder, but still I want allow the users to upload their own pods. Those extra pods will be stored at .native-deps directory, therefore I want babashka to look either in .babashka or .native-deps directory for pods 🙂.

borkdude 2021-04-23T08:39:32.389200Z

@karol.wojcik Yes, sure. The way you would have to call those pods must be using the filename then instead of the fully qualified symbol, right?

Karol Wójcik 2021-04-23T08:43:16.392500Z

I don't want the user to specify pods via the filename. From the user perspective it doubles the work to deploy an artifact. 1. Use fully qualified symbols. 2. Download and pack pods (soon via bb pods --download). 3. Rename dependencies to use filenames instead of fully qualified symbols. What I would like from babashka side is to allow extra paths for pods (like classpath).

Karol Wójcik 2021-04-23T08:44:06.393200Z

Maybe via environment variable. Something like: BABASHKA_PODS_LOOKUP

borkdude 2021-04-23T08:44:55.394500Z

@karol.wojcik A fully qualified symbol implies the pod is downloaded from the registry (or in the expected already downloaded location). The other option is to use the pod's filename and then it will be looked up from the system path. There is no combination of these two.

Karol Wójcik 2021-04-23T08:45:11.394900Z

I don't want to combine those two.

Karol Wójcik 2021-04-23T08:45:53.395800Z

I want to specify an extra "already downloaded location" for fully qualified declared pods.

Karol Wójcik 2021-04-23T08:46:23.396200Z

The change would be in resolve function: https://github.com/babashka/pods/blob/82aa3627106181a0ad58c289cd45129603e4fa24/src/babashka/pods/impl/resolver.clj#L159

Karol Wójcik 2021-04-23T08:47:19.397300Z

We could use "or" in 169 and 170 line for custom babashka pods paths.

Karol Wójcik 2021-04-23T08:47:58.397800Z

I would love to make a PR for it if you would like me to.

borkdude 2021-04-23T08:49:38.398400Z

I don't understand the use case. Why not use the location that is already supported?

Karol Wójcik 2021-04-23T08:59:10.405800Z

Ok let explain myself a little bit. Here is how babashka runtime looks like. It's packed together with following things: .babashka, .m2 and bb executable

#!/bin/sh

set -e

export _JAVA_OPTIONS=-Duser.home=.
export BABASHKA_DISABLE_SIGNAL_HANDLERS=true
export XDG_CACHE_HOME=.

./bb -cp "$(cat classpath)" -m "$(cat ENTRYPOINT)"
In .babashka i store aws-pod since it will be so commonly used with babashka runtime that it's just a waste of resources to pack this dependency on each release. All of those files will be shipped as an AWS layer which means that upon lambda invocation .zip file will be extracted in /var/task directory (layer) to which items from user lambda release artifact will be merged. Which means that user cannot pack babashka pods in .babashka, because it will remove all dependencies declared! Instead holy-lambda will pack extra user pods in .native-deps from which I want babashka to lookup for extra pods if an artifact could not be found in .babashka. Let me know, whether it makes sense to you.

borkdude 2021-04-23T09:01:22.406200Z

I don't understand this part: > to which items from user lambda release artifact will be merged. Which means that user cannot pack babashka pods in .babashka, because it will remove all dependencies declared! What is it, merge or replace?

borkdude 2021-04-23T09:01:53.406600Z

Are you not able to add to directories in layers, do they always replace? That seems odd to me

Karol Wójcik 2021-04-24T08:13:25.473800Z

I can implement it on babashka side if you would like me to 🙂

borkdude 2021-04-24T09:08:10.474Z

I reacted in the issue

Karol Wójcik 2021-04-23T09:04:04.409100Z

Imagine that you unzip two zips in place which both have the same directory inside.

borkdude 2021-04-23T09:04:53.409600Z

I think that should merge, but doesn't it?

Karol Wójcik 2021-04-23T09:05:34.410700Z

Hmm.. Actually i did not test it, but my intuition says no :D will check it out!

borkdude 2021-04-23T09:05:55.411Z

let's put it to the test

borkdude 2021-04-23T09:13:58.411200Z

I tested it and it merges (like I would expect)

borkdude 2021-04-23T09:14:36.411800Z

merging is not the right word: it just creates files into the directory structures, but doesn't remove any existing ones. on overwrite zip will prompt you

borkdude 2021-04-23T09:16:12.412300Z

Here you have foo1.zip and foo2.zip. Both contain a dir foo with different files. After unpacking both, the foo dir has both files.

Karol Wójcik 2021-04-23T09:18:01.412900Z

I hope that aws lambda does the same.

Karol Wójcik 2021-04-23T09:18:14.413300Z

I will check it out and let you know!

borkdude 2021-04-23T09:19:42.413600Z

I think docker works the same way, but it would be good to check

borkdude 2021-04-23T12:38:03.414400Z

If someone wants to have some fun, perhaps one could find out how to get zsh (or bash) completions for a project specific bb.edn?

❤️ 5
2021-04-23T13:20:22.417300Z

Hello. I'm converting some scripts to bb task. I want to use shorthand syntax for functions. But getting an exception: "Exception in thread "main" java.lang.RuntimeException: No dispatch macro for: (" any hint?

(run!  #(cp-to % dest) (fs/glob rp "**.{css}"))
;;(run! (fn [f] (cp-to f dest)) (fs/glob rp "**.{css}") )

borkdude 2021-04-23T13:23:43.417700Z

@fnumatic Since bb.edn is an EDN file you cannot use #(...) unfortunately.

borkdude 2021-04-23T13:24:42.418200Z

if necessary you can split out functions into a different file and put it on your classpath using :paths

2021-04-23T13:25:48.419300Z

@borkdude ok, thanks.

borkdude 2021-04-23T13:25:53.419500Z

off topic: a nasty trick to inject code into every namespace (by modifying clojure.core) https://github.com/babashka/babashka/issues/799#issuecomment-825654751

2021-04-23T13:35:29.421600Z

is there a short way to just copy a file to a specific directory? my bash script right now

cp $RP/index.html $DOCS

borkdude 2021-04-23T13:36:24.422100Z

Does (fs/copy "foo" "bar") work?

borkdude 2021-04-23T13:37:08.423100Z

(fs/copy (fs/path (System/getenv "RP") "index.html") (System/getenv "DOCS"))

borkdude 2021-04-23T13:37:16.423400Z

it's not really short, but that should do it

borkdude 2021-04-23T13:37:41.423800Z

you could also define a variable in :init to make it shorter

borkdude 2021-04-23T13:38:03.424400Z

{:init (do (def docs (System/getenv "DOCS")))}

2021-04-23T13:40:57.426500Z

nope. System vars are not the problem. I just cannot choose a destination dir. I always have to use explicit destdir + destfilename.

borkdude 2021-04-23T13:41:36.426700Z

hmm, let me check

2021-04-23T13:44:02.427600Z

this is my current workaround in a let block

cp-to (fn [f dir]  
         (fs/copy f (fs/file dir (fs/file-name f)) 
          {:replace-existing true}))

borkdude 2021-04-23T13:45:14.427900Z

yeah this is annoying and should be fixed.

2021-04-23T13:45:45.428200Z

good work, by the way

borkdude 2021-04-23T13:51:28.429200Z

Thanks. I see the behavior is similar to:

(require '[<http://clojure.java.io|clojure.java.io> :as io])

(io/copy (io/file "file") (io/file "foo"))
so at least it's consistent, also with me.raynes/fs

borkdude 2021-04-23T13:51:46.429500Z

Maybe we should have a function copy-into or something which copies a file into a dir

👍 1
borkdude 2021-04-23T13:52:13.429800Z

so it's not a bug at least, but slightly annoying

borkdude 2021-04-23T13:58:25.430600Z

@fnumatic btw if your use case it to copy a dir into another dir, then you should consider using fs/copy-tree

👍 1
2021-04-23T15:20:18.432700Z

https://github.com/babashka/fs/pull/23

borkdude 2021-04-23T15:21:56.433400Z

@fnumatic please add tests. As I currently see it, the function calls itself infinitely

borkdude 2021-04-23T15:22:18.433800Z

also some bikeshedding: copy-into or copy-to? any preferences anyone?

2021-04-23T15:22:37.434100Z

yes, omg

2021-04-23T15:23:33.434500Z

would prefer copy-to

borkdude 2021-04-23T15:23:55.434700Z

yeah, I think so too

borkdude 2021-04-23T15:24:36.435200Z

well, copy-into is less ambiguous perhaps. copy-to could still mean that you copy file X to file Y

2021-04-23T18:37:06.437300Z

Copy into

borkdude 2021-04-23T18:37:37.438Z

Whoops. Whenever I'm not certain about a name, I just toss a coin on Twitter. https://twitter.com/borkdude/status/1385662077600243715

lukasz 2021-04-23T18:38:09.438800Z

cp

lukasz 2021-04-23T18:38:19.439200Z

(a new challenger appears)

borkdude 2021-04-23T18:38:21.439300Z

yeah, I think copy-to is more esthetically pleasing, but copy-into is less ambiguous, so even if the poll is in favor of copy-to I may still choose copy-into based on arguments

borkdude 2021-04-23T18:38:28.439600Z

cp is ambigious in itself

lukasz 2021-04-23T18:38:36.439800Z

oh, so there's a difference?

lukasz 2021-04-23T18:38:37.440Z

hm

lukasz 2021-04-23T18:38:51.440600Z

I always liked Ruby's FileUtils module where all methods were named after shell commands

lukasz 2021-04-23T18:38:56.440900Z

(mkdir, mkdir_p etc)

borkdude 2021-04-23T18:39:26.441700Z

cp behaves like foo target-dir: copy into the dir, and cp foo target-dir/non-existing-or-file creates or overwrites the file, which over time you just learn

borkdude 2021-04-23T18:39:53.442100Z

what's mkdir_p?

lukasz 2021-04-23T18:40:07.442500Z

create directory if doesn't exist, otherwise report success

borkdude 2021-04-23T18:40:21.443Z

oh mkdir -p equivalent

lukasz 2021-04-23T18:40:26.443200Z

or create a whole path structure mkdir -p ...

lukasz 2021-04-23T18:40:27.443500Z

yep

dharrigan 2021-04-23T18:40:56.444Z

I sorta feel that the destination should come first, given it's ...into and ...to

dharrigan 2021-04-23T18:41:12.444500Z

i.e., (fs/copy-into "quux/dir" "foo/bar/baz.txt")

borkdude 2021-04-23T18:41:13.444600Z

copy x into y

dharrigan 2021-04-23T18:41:23.444800Z

yes, I'm aware of the implicit

2021-04-23T18:41:37.445300Z

I think destination first is confusing.

dharrigan 2021-04-23T18:41:43.445500Z

but it reads better and in my mind feels better when the destination comes first

borkdude 2021-04-23T18:41:58.445900Z

I think the unix world disagrees

2021-04-23T18:42:01.446Z

I wouldnt expect that to be the behaviour

dharrigan 2021-04-23T18:42:03.446200Z

you look at it and you think "I'm copying into /foo/bar/baz.txt"

borkdude 2021-04-23T18:42:59.446900Z

the argument names solve that problem, copy arguments usually go from src to dest, left to right

dharrigan 2021-04-23T18:44:13.447400Z

how about (fs/copy-from....)

dharrigan 2021-04-23T18:44:57.448400Z

that is a perfectably reasonable choice too

dharrigan 2021-04-23T18:45:26.448800Z

(fs/copy-from "foo/bar/baz.txt" "quux/dir")

dharrigan 2021-04-23T18:45:43.449200Z

(fs/copy-from "foo/dir" "quux/dir")

borkdude 2021-04-23T18:46:44.449500Z

The second example is already supported by copy-tree

dharrigan 2021-04-23T18:46:59.449700Z

it was an example

borkdude 2021-04-23T18:47:09.450Z

sorry, I don't find it intuitive :)

dharrigan 2021-04-23T18:47:18.450300Z

copy-from has better readability

dharrigan 2021-04-23T18:47:28.450600Z

I'm copying from x to y

borkdude 2021-04-23T18:48:04.451200Z

it doesn't explain whether you are copying from file X to a new file Y or into a dir Y

dharrigan 2021-04-23T18:48:32.451600Z

that's irrelevant

dharrigan 2021-04-23T18:48:41.451800Z

do you care if you do cp x y

borkdude 2021-04-23T18:49:20.452500Z

babashka.fs doesn't try to emulate bash, it is based on java.nio.file and there such semantics matter

2021-04-23T18:49:26.452800Z

Everything is a file 😉

borkdude 2021-04-23T18:49:38.453200Z

e.g. fs/copy is based on java.nio.file.Files/copy

dharrigan 2021-04-23T18:49:47.453600Z

THe problem you are introducing the -into or -to is that the explict reading of it in english sets up a wrong premise

borkdude 2021-04-23T18:49:52.453800Z

so we already have a "style guide" that we have to stick to

dharrigan 2021-04-23T18:50:16.454200Z

if you read out (fs/copy-into "foo/bar/baz.txt" "quux/dir") out loud, you'll see that it just reads wrongly,

dharrigan 2021-04-23T18:50:32.454700Z

ditto with to

borkdude 2021-04-23T18:50:50.455200Z

(&gt; 5 6): 5 greater than 6 (copy-into foo bar) copy foo into bar makes sense to me

dharrigan 2021-04-23T18:51:09.455400Z

I'm copying into foo bar

borkdude 2021-04-23T18:51:25.455800Z

foo copy-into bar

borkdude 2021-04-23T18:51:31.456Z

it's lisp

borkdude 2021-04-23T18:51:55.456700Z

x op y is written as (op x y) in lisp

dharrigan 2021-04-23T18:52:03.456900Z

I'm aware of lisp

dharrigan 2021-04-23T18:52:35.457700Z

but you're trying to shoehorn a LISPy schematic into a file system action

borkdude 2021-04-23T18:52:58.458500Z

now this is a better argument of putting the destination first: https://twitter.com/danielglauser/status/1385667548620869633 I don't agree. this is how you write functions / predicates in lisp in general.

dharrigan 2021-04-23T18:53:00.458800Z

all I'm saying is that it reads wrong if you read it out, in both choices, where as the -from actually does precisely what the action is doing.

borkdude 2021-04-23T18:53:54.459300Z

I think often the order of arguments can be counter-intuitive and you can explain it both ways, I'll give you that

borkdude 2021-04-23T18:56:12.460600Z

(apply copy-foo dir [x y z])

borkdude 2021-04-23T18:57:58.461200Z

(run #(fs/copy-to-dir % dir) ...)

borkdude 2021-04-23T18:59:45.462100Z

Maybe copy-to-dir is the most explicit name we can have and, to be compatible with the other copy functions, I think it's least confusing if we put the order the same, src -> dest

borkdude 2021-04-23T19:01:12.462300Z

or maybe not include it... :)

borkdude 2021-04-23T19:05:17.462600Z

funny enough, me.raynes.fs didn't have this function

borkdude 2021-04-23T19:05:34.463Z

does anyone know how python or Ruby calls this function, if available?

borkdude 2021-04-23T19:08:09.463500Z

Just copy in python it works for both copying into a dir and creating a new file by name

borkdude 2021-04-23T19:10:38.464400Z

In fs copy already is based on Files/copy so we can't alter that behavior I think (better stick to the standard here). It's better to create another function, it's only the name that is difficult

borkdude 2021-04-23T19:38:11.465300Z

ok, let's be open minded: Maybe we could change fs/copy to copy the file "into" a dir if the dest is a dir... and deviate a bit from java.nio.files. What do y'all think?

Karol Wójcik 2021-04-23T20:20:32.467700Z

@borkdude my bad. Layer goes to /opt/var. User packed artifacts go to /opt/task. Seems that I need babashka pods classpath. ;(

2021-04-23T20:47:28.467900Z

That would be even better. My goal is, to get rid of various shell scripts. As of now, just copy file to file is counterintuitive. Everything is a file, as @qmstuart said.

borkdude 2021-04-23T21:00:26.468200Z

ok, let's do it

borkdude 2021-04-23T21:08:36.468700Z

@karol.wojcik Can you make an issue in the pods repo to clearly explain the case so I can give it some thought?

Karol Wójcik 2021-04-23T21:09:21.469Z

Sure

borkdude 2021-04-23T21:42:36.469200Z

Thanks! I'll give it a night's sleep and will look at it this weekend

borkdude 2021-04-23T21:52:23.469900Z

ok, fs/copy now accepts dirs as dest: https://babashka.org/fs/babashka.fs.html#var-copy published as 0.0.4 and will be available in a new bb near you soon

🎉 3
russmatney 2021-04-23T21:59:07.470100Z

I took a shot at this and have a prototype working as documented here https://github.com/russmatney/bb-task-completion

🎉 1
russmatney 2021-04-23T22:00:30.470400Z

Right now it just stringifies the task definition, so looks like

russmatney 2021-04-23T22:02:11.470800Z

I'm not sure the best approach for a few things - i listed those in the readme - if you have thoughts on next steps, let me know and i can take a shot at a PR, but feel free to run with this however you see fit

borkdude 2021-04-23T22:05:15.471Z

Awesome, I'll take a deeper look tomorrow :)

borkdude 2021-04-23T22:05:54.471200Z

Note that there is also :doc in tasks which you could use to print

borkdude 2021-04-23T22:06:16.471400Z

although I haven't used it in the case of antq's bb.edn

borkdude 2021-04-23T22:06:33.471600Z

1
russmatney 2021-04-23T22:13:31.471700Z

gotcha - i'll update to prefer that if it's present

Karol Wójcik 2021-04-23T22:38:18.472100Z

Here it is: https://github.com/babashka/babashka/issues/801 ;)

2021-04-23T22:47:37.472400Z

The stringified task definitions break with some tasks:

{:tasks
 {all {:depends [lint-eastwood]}

  lint-eastwood
  {:task (clojure "-M:dev:eastwood '{:source-paths [\"src/main\" \"src/test\"}]'")}}}

russmatney 2021-04-23T23:35:44.472800Z

thanks for trying it! good find - we'll probably need to escape those quotes