Fork me on GitHub
#babashka
<
2021-05-26
>
ambrosebs04:05:21

I moved to selmer instead for templating...it's amazingly quick with bb! 40 files in 150ms https://github.com/typedclojure/typedclojure/blob/fd7e00a134425e0ee6b13adbc418c0991dd97608/dev/src/typed/dev/selmer.clj#L77-L117 Totally changed my workflow, thanks @borkdude!

🎉 9
ribelo10:05:47

Is it possible to use a different encoding in slurp than utf-8?

lispyclouds10:05:19

(slurp "/path/to/file" :encoding "ISO-8859-1")

ribelo11:05:35

which means that my encoding is not included

lispyclouds11:05:21

what are you trying with?

lispyclouds12:05:40

Yeah can confirm bb raises the java.io.UnsupportedEncodingException with both cp1250 and Windows-1250 @borkdude any ideas?

borkdude12:05:38

Seems we need to add -H:+AddAllCharsets, https://github.com/oracle/graal/issues/1370

borkdude12:05:34

PR welcome in a branch. First let's see what it does to the binary size :)

lispyclouds21:05:39

@U0BBFDED7 please have a look at the PR above, let us know of your use case, we can consider adding it 🙂

ribelo21:05:54

I will check as soon as I have some time

borkdude12:05:07

Not sure if I mentioned it here already, but: Maybe you need just a little bit of CLJS in your babashka httpkit app and you don't want to set up a whole new CLJS project for it. Performance and bundle size may not be that important. Then scittle may be suited for you: https://borkdude.github.io/scittle/

❤️ 17
cfleming21:05:33

Is there any way to introspect the classes that are available to bb?

borkdude21:05:23

@cfleming I can give you a full list as JSON, if that is useful?

cfleming21:05:00

Can that be obtained at runtime, or is that hardcoded somehow? I assume that classes are added to that from time to time?

borkdude21:05:10

I'm not sure how to do this at runtime, how would you do that in Clojure?

borkdude21:05:37

The churn in classes isn't that high though, so it would probably be ok if you updated this every so often

cfleming21:05:09

Ok, or I’ll download it from github based on the version of the bb runtime. Thanks!

cfleming21:05:53

Having looked at it, it looks like all the namespaces available to the bb runtime are available immediately, i.e. I can see them being returned by all-ns. Is that correct?

borkdude21:05:30

except for libraries from the "classpath"

borkdude21:05:47

so all-ns does return all the built-in ones

cfleming21:05:57

Great. I’m trying to figure out how to best support bb in Cursive, and the problem is the built-in libs. But if I can introspect those that will probably work well.

cfleming21:05:22

Users will still have to mark specific files as being bb rather than normal Clojure in some way, but I think that’s ok.

borkdude21:05:23

yeah. babashka does have a bb.edn now which is similar to deps.edn but this isn't mandatory, so it's still useful to have an option to flag a file as "bb"

borkdude21:05:45

so there currently we have a script to obtain the latest deps in babashka and lsp does analysis on those deps

cfleming21:05:48

Ok so there you’re actually getting the deps.edn from github for the built-in deps, correct?

cfleming21:05:22

Interesting, that might work well for Cursive too.

borkdude21:05:22

correct. not sure how well it works, it hasn't seen a lot of usage yet I think, but that's the idea

cfleming21:05:52

Is the deps.edn published as part of a release?

cfleming21:05:16

Hmm, looks like not.

borkdude21:05:22

no, but we tag every release, so maybe that helps somehow

cfleming21:05:59

I think for tags you have to know the sha

cfleming21:05:35

Yes, I just tried clicking the link 🙂

cfleming21:05:42

Ok, great, that will help.

cfleming21:05:34

I’ll try that and see how far I get, thanks.

👍 3
borkdude21:05:41

I suggested to ericdallo that bb could spit out a deps.edn-like structure with its built-in deps and also the deps and paths from bb.edn combined. Maybe that would help too, but he would rather see a complete classpath with all deps downloaded, which is basically what that script does. Feel free to post in that issue as well, if you have some new insights.

cfleming21:05:04

I’ll read through it all after breakfast.

cfleming21:05:28

Is there only one bb.edn in the root of a project, normally?

borkdude21:05:55

typically yes. but it's relatively new and not mandatory for say, single one-off scripts

borkdude21:05:21

I'm afk now as it's almost midnight here, have a great day

cfleming21:05:07

Thanks for the help!

bherrmann22:05:45

Is there an xpath like thing for babashka? I'm trying to read the version of a pom file... I want to say something like short and sweet like

(xpath "...pom.xml" "/version[0]" ) 
but instead, I'm doing
(def pom-file  ".../pom.xml")
(def pom (xml/parse (io/input-stream pom-file)))
(def element-type (class pom)) ;; instanceof didnt like class literal
(def children-of-toplevel-pom (filter #(instance? element-type %) (:content pom)))
(def version-element (first (filter #(= "version" (name (:tag %))) children-of-toplevel-pom)))
(def current-version (first (:content version-element)))

bherrmann22:05:02

That is way better.

borkdude22:05:57

(require '[babashka.deps :as deps])

(deps/add-deps '{:deps {org.clojure/data.zip {:mvn/version "RELEASE"}}})
(require '[clojure.data.zip.xml :as xmlz]
         '[clojure.data.xml :as xml]
         '[clojure.zip :as zip])

(def xml "<pom><version>1.0.0</version></pom>")

(-> xml
    xml/parse-str
    zip/xml-zip
    (xmlz/xml1-> :pom :version zip/down zip/node))

;; => 1.0.0

❤️ 3
isak22:05:19

I think I had this problem before and solved it in like 5 lines of specter. Haven't tried it with babashka, though.