Fork me on GitHub
#babashka
<
2021-02-22
>
cheel03:02:32

An example on talking to a babashka-pod with common-lisp. Just tried it out for chills https://github.com/rorokimdim/stash/tree/master/scripting-examples/common-lisp

🤓 2
borkdude08:02:05

@dorabThanks for sponsoring on Github. Would you like an invite to the private sponsors channel?

dorab20:02:45

Sure. Thanks.

Eamonn Sullivan10:02:41

How do you sponsor on Github? I've never done that, though I probably should...

borkdude08:02:54

Thanks for your kind donation on Kofi!

Eamonn Sullivan08:02:57

Well, it's not much, but there's so many different packages that I use every day. I made several one-off $/£/€ donations this morning and set a reminder to do the same next year. I'll make it a Lent thing!

Eamonn Sullivan10:02:34

Oh, I see the opencollective link now...

borkdude10:02:14

@eamonn.sullivan You can go to https://github.com/sponsors/borkdude and then it should be self-explanatory I hope

borkdude10:02:30

Thanks for considering

👍 2
borkdude10:02:02

As a sponsor you will get priority in bug reports and also access to the private sponsors channel, but the main thing is to ensure continuity of this project.

borkdude12:02:26

@pfeodrippe Thanks for sponsoring! Would you like to have access to the private sponsors channel?

pfeodrippe12:02:03

Hi @U04V15CAJ o/ Yes, of course :) Thanks

Mikko Harju14:02:22

What's the best way to achieve . ${MY_CNF_SCRIPT} in babashka? Basically that file includes just a bunch of bash variables that can be then subsequently used later in the script. I'd like to reuse that file and just get the vars to babashka env

Mikko Harju14:02:02

I have a legacy project that has extensive bash tooling and I'm extending that setup with a couple of separate scripts that use babashka instead of Bash

grazfather14:02:08

source is a builtin, it’s special that it ‘survives’ the ‘subprocess’, Have you tried making a script that itself does source, and then source that bb script?

grazfather14:02:49

actually, I think just setting the env in your babashka and then sourcing that script might work

Mikko Harju14:02:41

Yeah, that is what I imagined what I'll have to do – I thought there could be some nifty way to get the variables set by the script to be incorporated directly withing a babashka script. Thanks!

grazfather15:02:30

I don’t think so: The invoker must explicitly be setup to ‘adopt’ the changed env vars, and that’s what source does. Let me know if a simple source where bla does setenv works, I am curious (and at work and cannot check)

borkdude15:02:26

I do have a nifty hack here: produce some bash with babashka and source that ;) https://stackoverflow.com/a/64804398/6264

1
grazfather15:02:38

Ah, sneaky. You just output a script 🙂 Probably nicer to use process substitution? e.g.

source <(bb -o ...

Mikko Harju18:02:39

Nice, thanks!

borkdude19:02:19

Adam is working on some babashka scripts here, while streaming: https://www.twitch.tv/adam_james_tv

🚀 3
🙂 1
grazfather19:02:54

Oh nice, I actually asked him to do something like that

borkdude21:02:04

Is Adam from the stream in this channel?

borkdude21:02:22

I have a solution for his spec problem ;)

grazfather21:02:55

I don’t know, but I told him that I found his stream via your post so he’s at least aware of this slack

grazfather21:02:43

Never trust a man with two first names

adam-james23:02:23

Hey, I resemble that remark 😉

borkdude21:02:15

Ah right. So what you can do:

/tmp $ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {borkdude/spartan.spec {:git/url "" :sha "e5c9f40ebcc64b27b3e3e83ad2a285ccc0997097"}}}')
/tmp $ cat spartan.clj
(require '[spartan.spec])

(alias 's 'clojure.spec.alpha)

(s/valid? int? 1)

/tmp $ bb -f spartan.clj --uberscript spartan.uber.clj
/tmp $ bb spartan.uber.clj
true
Using alias will avoid uberscript loading in the source from the "real" spec. And since spartan.spec create the clojure.spec.alpha namespace already, this is a good solution. I will change the spartan.spec README as well.

adam-james00:02:29

Thanks for this example. I am able to get your code working, however, it doesn't work when I also pull in my svg library. As soon as I require svg-clj (where the real use of spec occurs), uberscript will pull in clojure spec's code.

adam-james00:02:08

If I modify my ns

(ns svg-clj.main
  (:require [clojure.string :as st]
            #_[clojure.spec.alpha :as s] ;; eliminate spec requirement here
            [clojure.pprint :as pp]
            [clojure.data.xml :as xml]
            #?(:clj
               [hiccup.core :refer [html]])
            #?(:cljs
               [cljs.reader :refer [read-string]])))
Then your approach works. I was thinking of spartan as a complete 'drop in' replacement, but I may have to use a reader conditional in my library to get it to work with an uberscript

borkdude08:02:16

Yeah, it's a partial drop-in since not everything in spec is implemented (generators and instrumentation). But the way it creates the clojure.spec.alpha namespace is non-standard which confuses the uberscript

borkdude21:02:46

If you are using uberscripts solely for the purpose of being able to run them from anywhere, an alternative might be to just add the script "project" directory to the path

adam-james00:02:21

These are good suggestions. The uberscript approach was the first one I tried and succeeded with. I still plan to try uberjars as well. It's the next on the list. I'm still very much in the 'exploratory' phase of scripting :)

borkdude09:02:01

I love it :)

borkdude21:02:58

Another alternative is to create "uberjars" from them and wrap it in a tiny bash wrapper if you don't want to type bb foo.jar

👍 1