This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-13
Channels
- # announcements (3)
- # babashka (130)
- # beginners (73)
- # calva (22)
- # cider (46)
- # cljdoc (18)
- # cljs-dev (196)
- # cljsrn (18)
- # clojure (255)
- # clojure-europe (2)
- # clojure-finland (8)
- # clojure-gamedev (1)
- # clojure-germany (2)
- # clojure-losangeles (6)
- # clojure-nl (1)
- # clojure-spec (16)
- # clojure-uk (33)
- # clojurescript (32)
- # community-development (1)
- # conjure (40)
- # core-logic (11)
- # cursive (4)
- # datascript (8)
- # devcards (17)
- # emacs (21)
- # exercism (2)
- # fulcro (29)
- # funcool (15)
- # graalvm (18)
- # jobs (17)
- # jobs-rus (1)
- # lambdaisland (1)
- # lumo (1)
- # malli (19)
- # off-topic (15)
- # pathom (22)
- # quil (7)
- # re-frame (3)
- # reagent (3)
- # shadow-cljs (14)
- # spacemacs (41)
- # specter (2)
- # sql (5)
- # tree-sitter (1)
- # unrepl (16)
- # vscode (3)
- # xtdb (11)
- # yada (1)
Hi there, what’s the best way to use something like JSch with babashka? Ssh is often needed for scripting tasks and native clients are not always friendly (e.g. requires keychain on osx)
@romantsopin babashka doesn’t have Jsch, but you can either shell out or use #spire, which is similar to bb but specialized in provisioning
Thanks! I have separately compiled jsch tool, but thought it would be nice to somehow combine bb and jsch into single binary
It’s not open source now, but basically I connect to remote host by ssh (just for forwarding) but before that I check that 22 port is open and do some basic scripting. It’s a good fit for bb, but I don’t want to use system ssh, so I compiled jsch
Actually problem could be formulated more broadly, If I know that some tool could be graal compiled maybe there is a generic way to use it within bb?
@romantsopin Yes, classes can be added in babashka/impl/classes.clj
.
But you cannot use it with an existing version of bb, it has to be compiled together with it
Thank you! Will try it out
check out https://github.com/borkdude/babashka/blob/master/doc/dev.md for some pointers. Note that you have to use git clone
to clone the repo.
made some tweaks to the deps.clj babashka script: it now no longer shells out to calculate checksums or find executables on the path 🙂 so as pure Clojure as can be. https://github.com/borkdude/deps.clj
nice! btw, in https://github.com/borkdude/deps.clj#rationale perhaps another reason for its existence could be if you wanted to know more-or-less what the bash script does, it might be easier to study your implementation. wdyt?
@sogaiu Do you perhaps have a working Windows environment where you can build graalvm binaries? I can't build anymore in mine and don't know what's going on. I was trying to reproduce an issue I'm having with babashka.curl. It now writes to a tempfile, but apparently the path to a tmp dir is hardcoded in graal and when that dir doesn't exist, curl doesn't work anymore. This is the repro:
public class TempFile {
public static void main(String [] args) throws .IOException {
.File f = .File.createTempFile("foo", "bar");
System.out.println(f.exists());
System.out.println(f.getPath());
}
}
I made an issue for it here: https://github.com/borkdude/babashka/issues/352 - have a good dinner
So my script is getting big enough that I want to break it into parts... so I have some related questions, 1. Is there a way to get to bash's $0 - aka the full path to the executing bb script? (this is so I can do an add-class to a subdirectory which has utils code) (I'm aware of the Preloads option, but I'm ignoring that atm) 2. is :all not an option with require? aka (require '[utils :refer :all))
@bherrmann I think you want to use user.dir
maybe?
$ bb -e '(System/getProperty "user.dir")'
"/Users/borkdude/Dropbox/dev/clojure/deps.clj"
I think I will implement it at one point, but it kind of goes against most commonly accepted style guides. Using explicit refers is preferred and if that becomes too elaborate, use an alias.
I'm going to add :refer :all
now:
$ lein run "(require '[clojure.walk :refer :all]) (postwalk identity {:a 1})"
{:a 1}
changed most of the things you I could do quickly, added command line options changed the readme a bit, removed all implicit requires (i think) and gave better logging
also now you manually select the dependencies you want to require, or just choose all of them if you're super lazy
Syntax error compiling at (which.clj:12:17).
No such namespace: io
Full report at:
/var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/clojure-2111109642317177985.edn
you now select which ones you want, if you want to use all of them because you're lazy you can use -d all
why don't I just get an option to compile my script unmodified? that seems less to think about?
[which:99014] analysis: 14,457.98 ms
Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.ClassLoader.defineClass(String, byte[], int, int) is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
so here: https://github.com/MnRA/nativity/blob/700d3e88c44d54ed1233a90eaddf7e1d75c4eaa7/nativity.clj#L57
I don't think wrapping all of the code in a large -main is a great idea, but we already discussed that. I think you should leave most things on the top level of the script. I tend to believe that most scripts require a few minor tweaks to make them work with graalvm. E.g. adding type hints to prevent reflection. It will be a major headache on your side to deal with these sorts of issues. Just a project which generates a skeleton in which you can paste your script code and take it from there is what I would go for. This can just be a template for instance on https://clj-templates.com/
Hmm, I'm getting:
Unrecognized option: -H:+ReportExceptionStackTraces
Error: Could not create the Java Virtual Machine.
Yeah I wanna have this quick and dirty version running sorta decent, then I'll make other packaging solutions
so this version is if you just made a bb script with inline stuff really quick and dirty and you have to pass it off to someone else next I'll make the more skeleton version which will leave everything except 1 function out of the main
I keep getting the same exception. I think it doesn't like functions being defined in the -main. When I do this, it works:
borkd[email protected] /tmp $ cp which.clj src/which.clj
[email protected] /tmp $ clj -A:native-image
like I said, the implicit requires are only used for one-liners. e.g. cat foo.json | bb '(json/parse-stream *in*)'
. Not for scripts. Although that works, you should NOT rely on it.
for namespaces: you don't have to, but you can use a namespace. and bb libraries will most certainly have them
hmmm okidoke then I'll leave this mode as the one-liner mode, and make another one that leaves it completely untouched
There will be other issues, but people can figure those out once they have their generated skeleton, which is the strength of this project imho
oh in that case should I make it keep the source files by default? right now it deletes the generated clj and deps.edn
Awesome. Maybe we can add some hints to what people can do to make their script compatible with both native-image and babashka itself. Using the which script as an example maybe?
- use a namespace form and explicit requires
- add (:gen-class)
to the namespace form (bb will just ignore this)
- add a -main
function and call it using a conditional (like the which.clj script).
cool! did I miss something or did you miss the clean flag here? https://github.com/MnRA/nativity#clean-files
$ bb
Babashka v0.0.84-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (require '[clojure.set :refer :all])
nil
user=> (union #{1 2 3} #{4 5 6})
#{1 4 6 3 2 5}
See #babashka_circleci_builds for new binaries 🙂ok, thanks, I agree that :all is for the extremely lazy... or for the transition process of breaking something into pieces...
and *file*
does seem to hold the path to my script!!
I really appreciate the error messages from babashka are concise, relevant and helpful. Makes using it fun! (I can stay in the zone and not get sidetracked with mysterious errors)
Ha! (assuming you arent joking) when anything is not defined, or when missing a '}" or ')' - It could in part be the speed too, it is very immediate.
ah right. no I wasn't joking.
$ bb "("
clojure.lang.ExceptionInfo: EOF while reading, expected ) to match ( at [1,1] [at line 1, column 1]
I tested the :all change locally, it worked. I used *file*
to locate a library of common code, also worked great. Thanks.
I wonder if it makes sense if babashka sets a java property when you use a -main function like bb -cp . -m foo
(System/getProperty "babashka.main")
"foo"
so then you can write:
(defn -main [& args]
(when-first [executable args]
(println (where executable))))
(when-not (System/getProperty "babashka.main")
(apply -main *command-line-args*))
?
I don't think Clojure itself has a way of detecting if you're running with a main arg or just as a scriptI mean, when we would introduce custom variables for this like joker has, *main-file*
or something, this would break clj-kondo
for my single script, I simply invoke main at the end... ala...
(docopt/docopt usage *command-line-args* main)
nil
@bherrmann That's OK, almost all scripts do that (not having a -main I mean)
The readme is updated, If you guys have any other suggestions lemme know. I'm going to go eat something since I forgot to eat lunch
New version with directed mode, which wraps a slice of your script with a main call and leaves the rest as is.
Added a link to your project here: https://github.com/borkdude/babashka/#nativity
Hi, I'm trying to use sci in my own code. When I use it as part of the malli library it works (they use sci 0.0.11-alpha.2). When I use that same dependency it works. When I use sci 0.0.13-alpha.14 I get this error immediately when requiring the namespace in repl:
nREPL server started on port 39131 on host 127.0.0.1 -
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.10.1
OpenJDK 64-Bit Server VM 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08
...
user=> (require '[sci.core :as sci])
Execution error (IllegalStateException) at sci.impl.parser__init/load (REPL:13).
Attempting to call unbound fn: #'edamame.impl.parser/normalize-opts
project.clj:
(defproject playing "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/core.async "1.1.587"]
[org.clojure/spec.alpha "0.2.187"]
[metosin/malli "0.0.1-SNAPSHOT"]
[borkdude/sci "0.0.13-alpha.14"]]
:profiles {:dev {:source-paths ["dev"]
:dependencies [[org.clojure/tools.namespace "1.0.0"]]}}
:global-vars {*warn-on-reflection* true})
Yes, I think malli explicitly depends on an older version. When I add [borkdude/edamame "0.0.11-alpha.6"]
it works:
user=> (require '[sci.core :as sci])
nil
user=> (sci/eval-string "(+ 1 2 3)")
6