Fork me on GitHub
#babashka
<
2019-12-22
>
Jakub Holý (HolyJak)11:12:30

@deleted-user I believe File has a toPath?

👍 4
borkdude19:12:30

@deleted-user @holyjak I didn't add java.nio.filePaths earlier because I never could figure out how to use it from Clojure:

$ clj -e '(java.nio.file.Paths/get (into-array String "src")))'
Execution error (IllegalArgumentException) at java.lang.reflect.Array/set (Array.java:-2).

borkdude19:12:14

but this seems to work now:

$ bb '(java.nio.file.Paths/get "/home/justin" (into-array [".lein" "profiles.clj"]))'
#object[sun.nio.fs.UnixPath 0x566ebefb "/home/justin/.lein/profiles.clj"]

👍 8
Jakub Holý (HolyJak)12:12:46

hm, I think into-array takes a seq while your 1st arg as "src" - you likely wanted ["src"]

borkdude19:12:28

(found it on StackOverflow)

borkdude20:12:26

@deleted-user Yeah, let's first see how this library approach pans out (e.g. the clj-http-lite one)

borkdude20:12:11

Note that you can set the babashka classpath in BABASHKA_CLASSPATH as well

borkdude20:12:22

and you can require things in BABASHKA_PRELOADS.

borkdude20:12:37

so that gives enough room to not include any non-standard deps.edn stuff I think

borkdude20:12:51

Adding convenience is something you can add later, but fundamentals are hard to change

borkdude20:12:55

clojure will pull it for you if you do that

borkdude20:12:43

@deleted-user You're free to obtain the git dep in any other way and set the classpath to the src folder

borkdude20:12:19

but that only works if that deps doesn't have any other deps. and dependency management is not a problem I want to re-invent the wheel for

borkdude20:12:03

@laheadle Following the example of clj-http-lite here: https://github.com/borkdude/clj-http-lite/blob/master/Readme.md#babashka I guess you could publish your curl-wrapping code also as a babashka library

👍 4
borkdude20:12:38

This way we could have multiple competing approaches for the same problem. Over time we can see what makes sense to include in bb itself.

👍 4
borkdude22:12:39

@deleted-user What about something like this?

#!/usr/bin/env bb

(def deps '{:deps
            {clj-http-lite
             {:git/url ""
              :sha "f44ebe45446f0f44f2b73761d102af3da6d0a13e"}}})

(require '[clojure.java.shell :as shell])

(def classpath (:out (shell/sh "clojure" "-Sdeps" (pr-str deps) "-Spath")))

(add-to-classpath! classpath)

(require '[clj-http.lite.client :as client])

(:status (client/get "")) ;; 200

borkdude22:12:59

that's just a detail here

borkdude22:12:31

You could just ship the library in the docker container and do (add-to-classpath! "/some/dir/with/clj-http-lite/src"). Without needing clojure.

borkdude22:12:02

or use git clone, or whatever, that's not really the point here

borkdude22:12:46

But then again, you could just use --classpath in that case

borkdude22:12:33

shipping bb + a script in a container and running it standalone is already possible today

borkdude22:12:46

if you mean Docker container

borkdude22:12:21

btw, lol:

#!/usr/bin/env bb

(def deps '{:deps
            {clj-http-lite
             {:git/url ""
              :sha "f44ebe45446f0f44f2b73761d102af3da6d0a13e"}}})

(require '[clojure.java.shell :as shell])

(def classpath (:out (shell/sh "clojure" "-Sdeps" (pr-str deps) "-Spath")))

(def script '(do (require '[clj-http.lite.client :as client])
                 (:status (client/get ""))))

(print (:out (shell/sh "bb" "--classpath" classpath (str script)))) ;; prints 200

borkdude22:12:42

yeah, pre-pull them and copy them over, as part of the image building

borkdude22:12:20

The joker author told me he never wrote a multi-file script himself so far btw, so this is probably a bit speculative still

borkdude22:12:21

it's good to aim high. we have at least one public babashka library now

borkdude22:12:28

there might be more coming

borkdude22:12:18

it seems there is a package manager for bash here: https://www.bpkg.sh/

👀 8
borkdude22:12:03

maybe we can adopt guix, so I can learn something new 😛

borkdude22:12:41

but I guess there is no way around installing a package manager before using it

borkdude22:12:56

guix isn't nix btw, it's a different but similar project

borkdude22:12:28

I mean you either use clojure / lein to pull deps, or require people to install npm, rubygems, bpkg, whatever. I guess you can just choose it for yourself and your own scripts what makes sense. If your company is heavy on JS, just put some scripts in npm?

borkdude22:12:00

what is it?

borkdude22:12:37

these tools already have good installers

sogaiu22:12:47

guix is great -- but iirc there is one aspect to it that one should be aware of.

sogaiu22:12:49

the last time i worked with it, i recall them being very oriented toward free software only. that can be a problem for some folks who want to also use other bits. nixos on the other hand, doesn't have that kind of policy -- but last i checked they have a different significant issue.

sogaiu22:12:05

last i checked, to use nixos requires learning a pretty not-so-nice language. guix on the other hand gives you guile.

borkdude22:12:24

we need gunix

sogaiu22:12:50

lol. i've run systems with both for some time -- but that was a bit back. it's possible things have evolved / changed a bit.

borkdude22:12:31

@deleted-user Don't agree. Leiningen has a bash script to install itself and so has clojure.

borkdude22:12:41

Which is currently mostly brew (crossplatform for linux and mac) and maybe scoop for Windows

sogaiu22:12:33

i'm interested in the reality of how many folks use brew for linux-ish systems -- and whether that is growing.

borkdude22:12:38

But maybe we're getting a bit off topic. Babashka isn't going to provide a binary packagement system, nor will it probably invent its own dependency management system.

deleted22:12:19

if every ruby library had to navigate adding bin files via whatever package managers it would have seriously limited its growth

borkdude22:12:00

Can you give an example of a ruby lib that needs a specific binary on the path?

borkdude22:12:16

ah like npm also does, right?

borkdude22:12:02

maybe this is because CLIs weren't really an option before GraalVM, joker, lumo etc

borkdude22:12:42

I guess we can lean on another package manager for now, which could maybe be npm

borkdude22:12:02

I don't know if the npm folks like having other stuff than JS in there

borkdude22:12:13

brew is also kinda nice. I guess one could write a babashka script and put it in brew with a dependency on babashka

borkdude22:12:23

and you can brew install and run it

borkdude22:12:10

brew works on linux too. debian packages are a pain in general

borkdude22:12:29

sure, why not. I don't know the ruby ecosystem very well

borkdude22:12:13

the question is: does one make things better by inventing yet another package manager

sogaiu22:12:16

have you tried nixos or guix?

sogaiu22:12:33

similar -- it was way too much work. really cool stuff, but i didn't have the time or computing resources to keep up.

borkdude22:12:48

Same here, tinkered with nix package manager, but nothing more than that

sogaiu22:12:06

my uneasy management of multiple versions of things is done via things like nvm and the unfortunate java switching system provided in arch linux. some day may be some of this will be more sane.

sogaiu22:12:37

i've looked at that a tiny bit -- but since it didn't handle java (or not well?) and i don't use most of the rest of its bits, using asdf + sdkman didn't seem like a win for me. if i used some of the other provided bits, the story might be different.

borkdude23:12:02

I've been using jenv for switching java versions

sogaiu23:12:40

hadn't heard of jenv -- will look at that. may be i'll look at sdkman again.

borkdude23:12:17

no, but you can register versions and it detects installed ones and switch more easily between them

borkdude23:12:24

I use AdoptOpenJDK for installing

borkdude23:12:35

e.g. I can also register my downloaded Graal JVM in ~/Downloads with jenv and switch to that, per shell session, directory, system, etc

borkdude23:12:10

and if I throw it away, I just type jenv remove ...

borkdude23:12:40

if it freezes, that's probably the wait-for test.

borkdude23:12:01

did you maybe have a socket REPL running?

borkdude23:12:29

and what's your python version when you type python?

borkdude23:12:57

We currently use python to start a webserver quickly during the tests, but it assumes v2 and not v3

borkdude23:12:20

This may change in the future, if someone has a better idea of doing this

sogaiu23:12:39

the python issue may be more likely on linux boxes

sogaiu23:12:08

apple went against the pep recommendation in their naming of python binaries afaict

borkdude23:12:44

fwiw these tests run on both linux and mac on circleci

borkdude23:12:33

one idea that I had was to just skip the python-required tests if python is not installed or is not v2

sogaiu23:12:14

> We expect Unix-like software distributions (including systems like macOS and Cygwin) to install the python2 command into the default path whenever a version of the Python 2 interpreter is installed, and the same for python3 and the Python 3 interpreter. > When invoked, python2 should run some version of the Python 2 interpreter, and python3 should run some version of the Python 3 interpreter. so if macos has python2, according to the recommendations, it ought to have python2 as a name for it -- do you think that is a reasonable interpretation of what's written above?

borkdude23:12:17

python2 works on my system

sogaiu23:12:56

so if the tests use python2, then using python2 for the name doesn't seem too bad?

borkdude23:12:31

feel free to try python2 in the tests, and see if that works on circleci as well

sogaiu23:12:23

i modify my local test to use python2 (the name) pretty frequently 🙂 will have to see if it works on circleci

borkdude23:12:28

one test is using python2 http server for testing if a socket is closed properly. since that server is single-threaded, it was blocking when a socket wasn't closed before

borkdude23:12:53

I don't know if the server in python3 is multi-threaded

borkdude23:12:29

but if there's another way to test this, feel free to refactor out the python stuff

borkdude23:12:47

but maybe first making the python2 change is good so we can add that to the readme?

borkdude23:12:16

yeah, change python to python2 in the tests

borkdude23:12:23

and then see if that works on circleci

borkdude23:12:55

so then we can document that the user should have a system where python2 works

borkdude23:12:18

PR welcome for that as well

borkdude23:12:12

so: trying python2, if that doesn't work, try python -V and check version, if that isn't the right version, print a warning and skip the tests that require python 2?

borkdude23:12:09

that would be fine by me, but like I said earlier: > I don't know if the server in python3 is multi-threaded

sogaiu23:12:10

fwiw, some searches suggest python 3's default web server is not multithreaded -- but i'm not sure if that will remain true (if it is atm)

borkdude23:12:29

ok then that's good

borkdude23:12:13

does this mean python apps suck for web development? I mean, you have to be able to serve two concurrent users?

sogaiu23:12:23

aren't there some thread-like things?

sogaiu23:12:27

there's twisted ofc

sogaiu23:12:31

but that's diff

sogaiu23:12:45

the important characteristic for the test was: > since that server is single-threaded, it was blocking when a socket wasn't closed before

borkdude23:12:46

the test only fails when the socket is not closed AND the server is single threaded

borkdude23:12:16

so you'd have to check by not closing the socket and running python3, that should result in a failing test

borkdude23:12:30

is HTTPServer not around anymore in python3?

borkdude23:12:45

maybe we should just use something more internally to check this which simulates a single-threaded connection handler

borkdude23:12:23

it has a socket repl

borkdude23:12:26

anyway, that's the idea of the test. I don't care how it's tested, python is just a detail here

borkdude23:12:32

gotta go now, getting late

👋 12