Fork me on GitHub
#babashka
<
2019-11-14
>
Jakub Holý (HolyJak)07:11:26

@borkdude I have opened a few new issues. I hope I will have chance to look into bb code today and fix some of them!

borkdude07:11:33

@holyjak Thanks. For the write issue, you might already be able to use spit with the append option for it

👍 4
borkdude07:11:51

getAbsolutePath will be added, but you can also use getCanonicalPath

jeroenvandijk15:11:54

I've created this pull request https://github.com/borkdude/babashka/pull/106 I'm available for questions or remarks. Not sure how I should go about testing this

borkdude15:11:49

I commented

jeroenvandijk15:11:51

ah cool, I missed the submodule clone part 🙂 Thanks!

borkdude15:11:56

If you think anything can be improved to the docs, feel free to do it

jeroenvandijk15:11:46

No I was just too quick

Jakub Holý (HolyJak)15:11:46

@borkdude I am trying to figure out how to add support for binding but am lost. Would exposing clojure.core/binding work? But it is a macro , not a fn...

Jakub Holý (HolyJak)16:11:51

Workaround: Yess, I will do that. But it feels suboptimal to open and close the file for each line I'm writing

borkdude16:11:24

I understand. But why do you need to use binding, when you can also call .write?

borkdude16:11:52

Because it isn't mapped yet?

borkdude16:11:02

(I checked, .write doesn't do anything yet.)

Jakub Holý (HolyJak)18:11:33

I don't need it if I've write but it would be nice as it is I believe the standard way to do it in clojure, ie using print* with binding *out*

borkdude18:11:50

ok, I think it's good to add then

Jakub Holý (HolyJak)19:11:14

working on it (.write and .append that is)

borkdude19:11:16

that's good. I'm currently refactoring the interop bit, so it might become a lot easier to add classes in the future, just by adding something to reflection.json

borkdude16:11:27

That would also be my approach with binding probably

borkdude16:11:10

probably not the easiest "first issue"

borkdude16:11:24

I'm now trying support for interop using a reflection config. Seems to work well so far...

$ ./bb --verbose '(. "foo" (endsWith "o"))'
true
So maybe this will make adding classes easier

jeroenvandijk16:11:01

Is it possible to replace the babashka process with a new process? Thus not using clojure.java.shell/sh, but something like exec in bash

jeroenvandijk16:11:42

I want to quickly validate commandline args with babashka and everything is ok, start a jar with the same args (long running process)

borkdude16:11:42

is that possible in normal clojure itself?

jeroenvandijk16:11:00

I think through Java, but maybe not

borkdude16:11:09

so it's essentially fork

jeroenvandijk16:11:17

i guess that's the name

borkdude16:11:59

what would be against just running it as a subprocess?

jeroenvandijk16:11:40

I would have to pipe the output to get proper feedback. sh collects the output until the process terminates

borkdude16:11:14

would conch be of help here?

borkdude16:11:21

it has a bunch more options than sh

jeroenvandijk16:11:31

Ok cool, I'll test that. Thanks

jeroenvandijk16:11:01

Btw, the reader conditionals are useful for what I'm trying

borkdude16:11:17

under the conch namespace

sogaiu16:11:28

fwiw, there was some discussion about using clojure.java.shell/sh with pipe (look for openssl) on #clojure recently -- i think there might have been some success without using conch or java interop

sogaiu17:11:38

user=> (clojure.java.shell/sh "sh" "-c" "echo U2FsdGVkX19YpBxGXZiFhpXjmogTE5OIbdQaHrXUIVQ=|openssl aes-256-cbc -d -a -pass pass:aaa")

jeroenvandijk17:11:56

conch works btw, but you have to manage the process underneath yourself and handle user input etc. So e.g. I just tried with a repl (`lein repl`) that fails in many ways 😁

borkdude17:11:09

what about making a wrapper bash script that first throws the command line args to babashka to validate and if that passes, continue with the actual process.

jeroenvandijk17:11:10

yeah I think that makes more sense

borkdude17:11:39

so:

#!/bin/sh

set -euo pipefail
bb '(assert (= 3 (count *command-line-args*)))' "$@"
# do the actual thing
echo "$@"
$ /tmp/script 1 2 3
1 2 3
$ /tmp/script 1 2 3 4
Assert failed: (= 3 (count *command-line-args*))

jeroenvandijk17:11:11

yeah I think that will work. Thanks 🙂

Jakub Holý (HolyJak)19:11:00

@borkdude When I run env BABASHKA_TEST_ENV=native script/test or script/test it gets stuck at

lein test babashka.impl.socket-repl-test
Does the test wait for me to connect to the socket repl or...?

borkdude19:11:18

it should not get stuck. can you test the master version and see if you have the same problem?

4
Jakub Holý (HolyJak)20:11:13

I was on master of my fresh fork. Or have you changed something very recently?

borkdude20:11:10

I'm changing things all the time, but I test this locally and on CI, I don't notice anything strange. Could it be there is still a socket REPL open on your machine that it tries to connect to?

Jakub Holý (HolyJak)20:11:34

hm, that is possible

Jakub Holý (HolyJak)20:11:14

well, I had bb --socket-repl 1666 running. After killing it the tests passed.

borkdude19:11:41

interop via reflection is getting interesting:

$ ./bb "(map #(.getName %) [java.io.File java.lang.String])"
("java.io.File" "java.lang.String")

borkdude21:11:31

$ ./bb "java.io.File/pathSeparator"
":"
^ entirely using reflection, I haven't added a binding for that field

borkdude22:11:02

This is a work in progress branch with reflection support. So the only thing to do when adding support for a class to babashka is adding something to reflection.json and the :classes argument to sci. Then it should "just work TM". Note the deletion of the babashka.impl.File namespace: https://github.com/borkdude/babashka/compare/reflect

borkdude22:11:47

The last two commits to sci were needed to support this: https://github.com/borkdude/sci/commits/master

borkdude23:11:34

This is what it looks like to add support for all methods + fields for Double for example: https://github.com/borkdude/babashka/commit/465f3b9b9fb12feebee3adf421e009e2b9b704ef

$ ./bb 'Double/MAX_VALUE'
1.7976931348623157E308

borkdude23:11:07

$ ./bb 'Double/SIZE'
64

borkdude23:11:58

$ bb '(Double/toHexString 2.5)'
"0x1.4p1"

borkdude23:11:02

Pretty amazing 🙂

metal 4
👏 4