Fork me on GitHub
#babashka
<
2022-01-04
>
dabrazhe13:01:43

I am having issues working with files relative to a bb project. I want to save files to a subfolder in the bb project, eg resources/report.csv However,

(spit (str "resources/report.csv") "test") results in: 
java.io.FileNotFoundException: resources/report.csv (No such file or directory)
I have defined the following in bb.edn :paths ["script" "resources"] I am certainly missing something simple ..

borkdude13:01:16

@dennisa does the resources folder exist?

dabrazhe13:01:03

It does exist. I am trying to evaluate spit in repl, if it matters

borkdude13:01:31

What do you get for (babashka.fs/exists? "resources")

dabrazhe13:01:39

(babashka.fs/exists? "resources") 
true

borkdude13:01:30

and if you do (spit (str "resources/report.csv") "test") in the REPL?

borkdude13:01:41

I assume you are on macos or linux here

dabrazhe13:01:22

Macos on M1

borkdude13:01:55

(spit "resources/foo.txt" "hello")

borkdude13:01:01

that should work

dabrazhe13:01:17

Somehow it does : ))

dabrazhe13:01:32

Maybe your aura made it work ))

😄 1
dabrazhe13:01:41

Does is suppose to work even if the bb repl is started in another folder, ie not the current bb project root?

borkdude13:01:13

no, the current working directory is the current working directory

borkdude13:01:59

and spit with a relative path writes relative to the current working directory

borkdude13:01:13

you can see the current working directory with (System/getProperty "user.dir")

dabrazhe13:01:14

this it's relative to the folder where the REPL has been started, not path defined in bb.edn? This part is a bit confusing

borkdude13:01:54

yes, where the process has been started is the current working directory

borkdude13:01:07

:paths in bb.edn are for resolving dependencies

borkdude13:01:20

relative to the current working directory

borkdude13:01:30

or rather, relative to the bb.edn file

dabrazhe14:01:26

how can I force bb to write to "resources" dir even if the repl is started in another dir? (eg /mac/bbproj1/resources/report.cvs when the repl is started in /mac/awsproject I am sometimes working on several bb projects and re-evaluating them all in the repl is a chore

borkdude14:01:51

by using an absolute path

borkdude14:01:41

or by using ../bbproj1/resources etc

borkdude14:01:08

perhaps you can use an atom or so where you set the root dir

borkdude14:01:25

which defaults to the current working directory, but you can alter that in your REPL and use that atom in spit

dabrazhe15:01:16

../bbproj1/resources works ) Thank you, you have been most helpful as always

🎉 1
dabrazhe15:01:56

I've been using (fs/absolutize ..) to achive this but ../bbproj1/resources is more universal

borkdude13:01:50

:paths is only relevant to namespaces you would load from the classpath

heow19:01:32

Babashka made Thoughtworks Tech Radar! https://www.thoughtworks.com/radar/platforms/babashka

👍 2
borkdude19:01:03

I already knew, but it's nice to hear it once more :)

lukasz19:01:42

👏 I can see all the millions of dollars rolling in @borkdude

borkdude19:01:28

I hope soon ;)

borkdude19:01:37

I'm also offering enterprise support/consulting for those that need an extra level of support around my projects (or related work). https://blog.michielborkent.nl/oss-highlights-nov-dec-2021.html#enterprise-support Sponsors get a discount on the hourly rate.

😎 2
dviramontes20:01:43

Hi all, can bb tasks pull dependencies from deps.edn ? is that a workflow that can work or would be encouraged / discouraged ?

borkdude20:01:20

@dviramontes yes, it can. Just put {:deps {current/deps {:local/root "."}}} in your bb.edn

thanks3 1
introom12:01:41

Is it possible to specify an alias, only to reference the deps of, for example, the :dev alias

borkdude12:01:50

This is currently not yet supported in bb.edn but you can do it programmatically with:

(babashka.deps/add-deps (clojure.edn/read-string (slurp "deps.edn")) {:aliases [:dev]})

👍 1
vlad_poh21:01:05

Anyone tried nbb and exceljs. I.e using nbb to read and write to an excel file? https://github.com/exceljs/exceljs#create-a-workbook

vlad_poh21:01:22

I've tried the following without success (ns excel (:require ["exceljs" :as j :refer [Excel.Workbook]] ["exceljs/Excel$Workbook" :as xl])) (Excel.Workbook.) => Could not resolve symbol ... (j/ExcelJS.Workbook.) => Could not find static method ExcelJS.Workbook. (xl) => Could not resolve symbol ...

borkdude21:01:01

Let's continue in #nbb

👍 1
borkdude21:01:35

The issue is that you need to add $default in exceljs$default

👍 1