Fork me on GitHub
#babashka
<
2022-04-28
>
mukundzare11:04:52

Trying something on our work linux servers with babashka. How do I add a dependency to say babashka.fs in my remote machine which is restricted from using the internet? I tried copying babashka.fs files from github to the remote under ~/bb-deps/fs-master path and used deps.edn to add dependency as : {:deps {local/deps {:local/root "~/bb-deps/fs-master/"}}} I tried fs-master as well as fs-master/src in the deps.edn above, and it doesn't work. My definition of "doesn't work" is that I get the following error for adding a simple :require for babashka.fs in a helloworld.clj file -- Don't know how to create ISeq from: clojure.lang.Keyword

borkdude11:04:10

@mukundzare babashka.fs is built into babashka, you don't need a dependency on that

mukundzare11:04:10

I thought so too, but it was throwing the error message regardless of the dependency so I tried adding a dependency.

mukundzare11:04:26

Not the smartest thing.. But was a wild guess

borkdude11:04:05

> but it was throwing the error message Maybe you could start there, what error message

mukundzare11:04:25

Sorry for the potato quality photo.. I can't access slack from work, have to chat via mobile

mukundzare11:04:06

This is the code

borkdude11:04:18

you forgot parens around :require in the ns form

borkdude11:04:01

the syntax is:

(ns foo (:require [...]))

mukundzare11:04:09

Oh man, thanks! I got it .. It works

🎉 1
mukundzare11:04:36

Thanks for your prompt responses!

👍 1
wilkerlucio18:04:11

hello, we are starting to use babashka on deploy scripts in my company, but I notice that every time I run it, I'm getting:

Could not find /root/.deps.clj/1.11.0.1100/ClojureTools/clojure-tools-1.11.0.1100.jar
Downloading tools jar from  to /root/.deps.clj/1.11.0.1100/ClojureTools
Downloading: babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.pom from clojars
I tried to cache those deps, but in Gitlab we cannot cache deps that are not in the same project, so, is there a way to change this directory .deps.clj? I tried using export DEPS_CLJ_TOOLS_DIR, but since the dir is empty it keeps downloading to /root/.deps.clj anyway. in the end what I want to have the script run without spending so much time downloading these deps

borkdude18:04:03

@wilkerlucio This seems to work?

borkdude@MBP2019 /tmp/yolo $ DEPS_CLJ_TOOLS_DIR=. bb clojure -M -e '(+ 1 2 3)'
Could not find ./clojure-tools-1.11.0.1100.jar
Downloading tools jar from  to .
6
borkdude@MBP2019 /tmp/yolo $ DEPS_CLJ_TOOLS_DIR=. bb clojure -M -e '(+ 1 2 3)'
6

👀 1
wilkerlucio18:04:26

one curiosity, why babashka deps uses a different cache directory? why don't use ~/.m2/repositories with the rest of maven deps?

borkdude18:04:05

@wilkerlucio that's not what the clojure CLI uses either, it uses /usr/local/lib etc to store those libs

borkdude18:04:19

the tools jar is not a maven lib

wilkerlucio18:04:48

ah, ok, I'm seeing I don't really understand those deps, I though they were all jars from mvn deps

wilkerlucio18:04:47

I have tried to point the deps dir to where clojure is installed, that didn't worked, but now I'm trying to use a custom, local directory and cache it, but currently it takes 15 min to run that task, hopefully the cache will work with the local path setup

borkdude18:04:23

The only extra thing besides ~/.m2 to add to the cache is ~/.deps.clj

wilkerlucio18:04:15

this is what my gitlab task looks like now:

build-artifact:
  stage: artifact
  script:
    - export GITLIBS=".gitlibs/"
    - export DEPS_CLJ_TOOLS_DIR=".deps-clj"
    - which clojure
    - bb DO_THING
  cache:
    key:
      files:
        - deps.edn
    paths:
      - ./.m2/repository
      - ./.gitlibs
      - ./.deps-clj

borkdude18:04:52

you store maven deps into the local dir too?

wilkerlucio18:04:54

I find the gitlab limitation to only cache directories that are local to the repo to be quite annoying, because requires all these path alterations to have any cache at all

wilkerlucio18:04:05

yeah, I have to, given the Gitlab constraints

borkdude18:04:17

anyway, looks good to me.

wilkerlucio18:04:47

there is an issue with 6+ years on gitlab about this https://gitlab.com/gitlab-org/gitlab/-/issues/14151

borkdude18:04:36

Why is this dep used btw?

babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.pom

wilkerlucio18:04:11

not sure, there are a lot of deps here in this process that I'm not familiar with yet

wilkerlucio18:04:48

currently it takes about 10min just downloading deps

wilkerlucio18:04:17

the beginning of the list:

wilkerlucio18:04:19

Could not find .deps-clj/clojure-tools-1.11.0.1100.jar
Downloading tools jar from  to .deps-clj
Downloading: babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.pom from clojars
Downloading: nrepl/bencode/1.1.0/bencode-1.1.0.pom from clojars
Downloading: org/babashka/sci/0.3.2/sci-0.3.2.pom from clojars
Downloading: borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.pom from clojars
Downloading: borkdude/edamame/0.0.19/edamame-0.0.19.pom from clojars
Downloading: org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.pom from central
Downloading: org/clojure/pom.contrib/0.2.2/pom.contrib-0.2.2.pom from central
Downloading: borkdude/edamame/0.0.19/edamame-0.0.19.jar from clojars
Downloading: org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.jar from central
Downloading: org/babashka/sci/0.3.2/sci-0.3.2.jar from clojars
Downloading: borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.jar from clojars
Downloading: nrepl/bencode/1.1.0/bencode-1.1.0.jar from clojars
Downloading: babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.jar from clojars
Downloading pod org.babashka/aws (0.1.2)
Successfully installed pod org.babashka/aws (0.1.2)
Cloning: 
Checking out:  at 7d40500863818c6f9a6e077b18db305d02149384
Downloading: org/clojure/clojure/1.11.0/clojure-1.11.0.pom from central

borkdude18:04:35

What I mean is, if you're using babashka, you don't really need these deps, they are built into babashka

borkdude18:04:21

Such a long download is pretty weird.

borkdude18:04:42

Perhaps you are using a custom mvn repo or an s3 repo or so that is very slow

wilkerlucio18:04:17

babashka is installed there, when/why it needs to download those tools?

wilkerlucio18:04:46

I've never seen it before as well, I'm used to make these setups on Github, but using the marketplace there things just work fine, now on Gitlab I'm facing these things because I'm bad at setting up those 😛

borkdude18:04:20

> babashka is installed there, when/why it needs to download those tools? like I said, for babashka itself this isn't necessary. perhaps you or one of your colleagues put those into deps.edn or bb.edn. I don't know :)

wilkerlucio18:04:25

we do use tools build, the babashka command getting ran here is: (shell "clojure" "-Sdeps" "{:mvn/local-repo \"./.m2/repository\"}" "-A:prod" "-T:build" "uber" "env" "prod")

wilkerlucio18:04:33

seems like I got the Could not find .deps-clj/clojure-tools-1.11.0.1100.jar fixed! thanks!

wilkerlucio18:04:44

but it still downloading more deps, I guess because of the aws pod usage

wilkerlucio18:04:51

Downloading: babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.pom from clojars
Downloading: nrepl/bencode/1.1.0/bencode-1.1.0.pom from clojars
Downloading: org/babashka/sci/0.3.2/sci-0.3.2.pom from clojars
Downloading: borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.pom from clojars
Downloading: borkdude/edamame/0.0.19/edamame-0.0.19.pom from clojars
Downloading: org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.pom from central
Downloading: org/clojure/pom.contrib/0.2.2/pom.contrib-0.2.2.pom from central
Downloading: borkdude/edamame/0.0.19/edamame-0.0.19.jar from clojars
Downloading: org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.jar from central
Downloading: org/babashka/sci/0.3.2/sci-0.3.2.jar from clojars
Downloading: borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.jar from clojars
Downloading: nrepl/bencode/1.1.0/bencode-1.1.0.jar from clojars
Downloading: babashka/babashka.nrepl/0.0.6/babashka.nrepl-0.0.6.jar from clojars
Downloading pod org.babashka/aws (0.1.2)
Successfully installed pod org.babashka/aws (0.1.2)

wilkerlucio18:04:15

(pods/load-pod 'org.babashka/aws "0.1.2")
(require '[pod.babashka.aws :as aws])

wilkerlucio18:04:26

when we go though this way, where the deps get saved?

borkdude18:04:13

there are no deps, except the pod which is downloaded to ~/.babashka/pods

borkdude18:04:47

This is currently not configurable but you could download the pod yourself and load it from a specified path

borkdude18:04:24

it will be configurable probably soon.

wilkerlucio18:04:57

cool, I'm going to dig down on what is making those deps load, because I currently don't understand it

borkdude18:04:47

You're not using babashka as a JVM library do you?

wilkerlucio18:04:28

when running bb, I believe my current thing to change the mvn/local-repo isn't applying for bb, I tried using -Sdeps but I see bb doesn't support it, is there a way to tell bb to use a custom directory for mvn deps?

borkdude18:04:46

you need to put it in the bb.edn file

wilkerlucio18:04:15

humm, but I need to make it different when running local vs CI, otherwise its gonna be a mess for development

borkdude18:04:48

yes, I understand, but we don't have a good solution for this right now. you could make a copy of the bb.edn and name it bb-ci.edn and then run with bb --config bb-ci.edn

wilkerlucio18:04:06

cool, gonna try this path

borkdude18:04:55

this only affects deps in bb.edn

borkdude19:04:13

deps in deps.edn are never requested by bb unless you use a local/root on the current project or so

borkdude12:05:48

I forgot to mention, the locations were pod stuff is downloaded can be influenced by setting XDG_CACHE and XDG_DATA

borkdude12:05:16

I will add BABASHKA_PODS_DIR for the next release which will cover everything related to pod downloading

dvingo19:04:33

hi - I'm trying to make use of this java lib via bb: https://github.com/tomas-langer/chalk I've included it in bb.edn like so:

$ cat bb.edn
{:min-bb-version
 "0.4.0"

 :paths
 ["src"]

 :deps
 {com.github.tomas-langer/chalk
  {:mvn/version "1.0.2"}}}
I see it is on the classpath:
$ bb print-deps --format classpath | tr : \\n | sort
/Users/alpha/.gitlibs/libs/babashka/babashka.core/52a6037bd4b632bffffb04394fb4efd0cdab6b1e/src
/Users/alpha/.m2/repository/babashka/babashka.curl/0.1.1/babashka.curl-0.1.1.jar
/Users/alpha/.m2/repository/babashka/fs/0.1.2/fs-0.1.2.jar
/Users/alpha/.m2/repository/cheshire/cheshire/5.10.2/cheshire-5.10.2.jar
/Users/alpha/.m2/repository/clj-commons/clj-yaml/0.7.108/clj-yaml-0.7.108.jar
/Users/alpha/.m2/repository/com/cognitect/transit-clj/1.0.329/transit-clj-1.0.329.jar
/Users/alpha/.m2/repository/com/cognitect/transit-java/1.0.362/transit-java-1.0.362.jar
/Users/alpha/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.12.4/jackson-core-2.12.4.jar
/Users/alpha/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.12.4/jackson-dataformat-cbor-2.12.4.jar
/Users/alpha/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.12.4/jackson-dataformat-smile-2.12.4.jar
/Users/alpha/.m2/repository/com/github/tomas-langer/chalk/1.0.2/chalk-1.0.2.jar
but I am unable to import it:
$ rlwrap  bb
Babashka v0.8.1 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (import com.github.tomaslanger.chalk.Chalk)
java.lang.Exception: Unable to resolve classname: com.github.tomaslanger.chalk.Chalk [at <repl>:3:1]
I also confirmed it is on local disk:
(base) Thu Apr 28, 15:51:23:~/.m2/repository/com/github/tomas-langer/chalk/1.0.2
$ jar tf chalk-1.0.2.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/github/
com/github/tomaslanger/
com/github/tomaslanger/chalk/
org/
org/fusesource/
org/fusesource/jansi/
com/github/tomaslanger/chalk/Ansi$AnsiCode.class
com/github/tomaslanger/chalk/Ansi$BgColor.class
com/github/tomaslanger/chalk/Ansi$Color.class
com/github/tomaslanger/chalk/Ansi$Modifier.class
com/github/tomaslanger/chalk/Ansi.class
com/github/tomaslanger/chalk/Chalk$1.class
com/github/tomaslanger/chalk/Chalk$NoOpChalk.class
com/github/tomaslanger/chalk/Chalk.class
Not sure what else to try. I'm not sure if this lib is graalvm compatible, but figured I'd get some errors if that was the case

dvingo19:04:58

the underlying lib makes use of some JNI libs: https://github.com/fusesource/jansi so maybe that's the problem? is there a way to determine if a lib is supported or not in bb?

dvingo20:04:28

I'm (perhaps obviously) attempting to add colorized/styled text output to a terminal - if there is a way to do that in bb some other way, I'd be open to use that too

dvingo20:04:25

answering my own q: https://github.com/babashka/babashka/blob/master/doc/projects.md#clojure-term-colors i am curious though about why that above import failed..

borkdude20:04:29

Because babashka cannot use any other Java classes than those that are built-in.

com.github.tomaslanger.chalk.Chalk

dvingo20:04:21

aha, thanks - is there someplace I can learn more about why?

borkdude20:04:21

The reason is that babashka is a native image compiled with graalvm. A native image is a closed world

dvingo20:04:46

Got it - that explains my ignorance, I haven't looked into the details of graalvm and the implications of using it. thanks for the info!

👍 1