I’m working with the pod.babashka.aws pod and it’s very noisy with logging statements (via clojure.tools.logging). Is there a way to silence these logs? If this were straight up clojure, I’d do something along the lines of -Dclojure.tools.logging.factory=clojure.tools.logging.impl/disabled-logger-factory
. I see I can set Java system properties that are read by babashka using -D
, but I suspect they’re not being passed to the pod? The more likely case is I’m just Doing it Wrong™.
@grzm There is a workaround for this. You can start the pod using the filename instead of the qualified symbol and then pass "-Dclojure.tools.logging.factory=clojure.tools.logging.impl/disabled-logger-factory"
as an argument to it
I think we could support this better by allowing to pass :command-line-args
or so via the options
I'm not sure if this even works, since the command line property may already have been read at compile time (top level) so it would be good to try this out first.
correct me if this thing already exists, but I think it would be nice to have somewhere in the docs a link to a comparison/translation between "standard" bash scripts and the equivalent Babashka scripts. Would be maybe a good way to onboard people who know bash but don't really know clojure much, if they can see how to do things they already know
There is currently an experimental setup possible for getting clojure-lsp support in babashka scripts: https://github.com/babashka/babashka/issues/733#issue-811939787 Feel free to give it a try and suggest improvements.
@ericdallo I wonder how clojure-lsp behaves if you have both a deps.edn
and a bb.edn
in the same project, which is pretty common
it will the one specified from user I think
but what if you want lsp support in both src/myclojure.clj
and script/mybb.clj
?
Oh, it has the capability to support both but I found a bug where it uses only the specified by users instead of merging with the default
which might make sense in some cases
so user would need to have two project-specs until this bug is fixed
ok
ATM it is (or (get settings :project-specs) default-project-specs)
I think that makes sense, it gives you the power to override lsp
but now lsp will use the bb classpath for clojure sources too?
which may not be a big issue
no, it will use only if finds the path configured by project-path
in this case bb.edn
yeah ok, but if I added one for deps.edn
as well
then the classpaths would be concatenated?
yes
that's probably fine, unless people use different versions of libraries in their clojure projects than what babashka uses
it will use the same classpath for both script and src folder if that's what you are asking
and this is why the script may be a better solution since it gives you the flexibility to change something
Hum, I still think it's too much manual work but it's a good start 😅
what users could do that makes sense is have a project root different for the scripts
> it will use the same classpath for both script and src folder if that's what you are asking yes, so it will use the babashka.fs library from bb itself to give LSP support in a Clojure project too, which may use an entirely different babashka.fs version
users could have different project-roots on lsp-mode one for scripts and another for the src
and different .lsp/config.edn with different project-specs
but yeah, it looks too hard to configure IMO for the end user
probably in practice it should be fine
let's first see what users come across
Btw. babashka also has an nREPL server which gives auto-completion for built-in libraries. Can this be used by LSP somehow
No, LSP don't uses/connect to any repl
this is a frequent question that people think that LSP should use the repl like cider or something, but this is not part of the LSP spec
that clojure-lsp uses clj-kondo behind the scenes is also not relevant to the LSP spec. similarly it could use an nREPL server to get extra info from
but people might as well use CIDER with the bb nrepl-server then, which people already do
Yeah, it could be added but there are already libs that do that very well, not sure it worth, but it's and idea that could be explored
@ericdallo Like: clojure-lsp could offer some hook where people can insert a script that fetches the necessary information for clojure-lsp to do something. e.g. it could be a babashka script that spits out some EDN. where it gets this EDN from is up to the user.
One such script could just make an nREPL request and clojure-lsp can be completely agnostic about this
yeah, looks cool, but is not clear to me when clojure-lsp would do the request, what would do with the result
think of it as an alternative way of getting clj-kondo analysis information, from some other source than clj-kondo
hum, I think cider does that right?
looks kind of huge parse the NREPL response and handle as analysis
not sure what's the best way to do that, maybe just a cookbook style, with two columns for each example and an explanation before/after the two implementations
well, the script would just give you the processed data, the script would then be responsible for the nREPL stuff
and clojure-lsp can be agnostic about nREPL
the script could provide it in the same format as clj-kondo analysis
so instead of saying: give me a classpath to analyze, you could say: give me the analysis
I see, it could work, but it looks too work for user, isn't ? I don't see too many users using that feature
the complexity would be contained in the script, which can be offered as a library. users use complex libraries all the time without understanding what it does internally
just a thought, you're probably right that this isn't used much
Yeah, but it looks to me a nice extension for clojure-lsp, giving this optional power to users, thanks for the idea 🙂 Maybe in the future I could do some POC
Cheers! There might be some issues with the using the disabled-logger-factory this way in particular (see https://clojurians.slack.com/archives/C03S1KBA2/p1621346387005200), but the general idea likely still holds.
added it https://github.com/babashka/babashka/issues/852 to not forget
Hi there, noticed the following - I was expecting a map in output:
ls | bb -i -O '{:report true :paths (vec *input*)}'
[:report true]
[:paths ["bin" "README.md" "resources" "scripts" "setup" "src" "target" "test" "tests.edn"]]
Should I file a bug or it is the expected behavior?Hi there, I am trying to uberjar my script
clojure -e "(require 'postgryoshka.core) (compile 'postgryoshka.core)"
but I am getting
Could not locate babashka/fs__init.class, babashka/fs.clj or babashka/fs.cljc on classpath.
Uberscript and running bb script works.
What should I do to create *.jar with all the dependencies?
This is a bug. There is a predicate that determines if multiple objects should be printed and currently this is coll?
, but obviously that is wrong. Probably sequential
is better
Issue welcome.
To create an uberjar with dependencies for babashka itself, you should only have to do:
bb uberjar foo.jar
I'm not sure why you are trying to do clojure -e
etc
Hi, how to source
some of the existing bash script file and run specific bash function from that file in babashka?
@grzegorzrynkowski_clo babashka doesn't interpret bash, it is a Clojure scripting environment
if you want to run bash, use bash by shelling out to it using babashka.process
(or if you are using tasks: shell
)
e.g. you can do (shell "bash -c 'source foo && foo_fn'")
makes sense, thanks a lot 🙇🙏
I used an example from babashks book ... To exclude these dependencies, you can use the following :classpath-overrides in your deps.edn...
`$ rm foo.jar $ bb -cp $(clojure -A:remove-clojure -Spath) uberjar foo.jar -m foo $ bb foo.jar :hello $ ls -lh foo.jar -rw-r--r-- 1 borkdude staff 871B Aug 19 17:07 foo.jar`
This was written before bb.edn
was there. You can now just put your deps inside bb.edn
and run bb uberjar foo.jar
I will update the book with this info.
I have fixed it quickly, sorry I might have broken the tests - will try to improve the PR later with more time at hand https://github.com/babashka/babashka/pull/853
I was trying babashka.curl
on Windows (just for curiosity, not that I care) and got the following error:
user=> (curl/get "<http://www.google.com|www.google.com>")
clojure.lang.ExceptionInfo: curl: option --compressed: the installed libcurl version doesn't support this
curl: try 'curl --help' for more information
[at <repl>:1:1
hmmm
https://superuser.com/questions/497310/curl-compressed-command-not-recognized-in-windows
https://superuser.com/questions/497310/curl-compressed-command-not-recognized-in-windows
I wonder if it's possible to probe curl if it supports this option, so we can cache that for the next call
This works, but it be good to detected it instead:
(curl/get "<http://www.google.com|www.google.com>" {:compressed false})
> I wonder if it's possible to probe curl if it supports this option, so we can cache that for the next call
Maybe with --version
?
curl.exe --version
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL Release-Date: 2017-11-14, security patched: 2019-11-05
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
I get this on macOS:
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
I think it is the libz
feature. On NixOS:
curl --version
curl 7.74.0 (x86_64-pc-linux-gnu) libcurl/7.74.0 OpenSSL/1.1.1k zlib/1.2.11 libssh2/1.9.0 nghttp2/1.41.0
Release-Date: 2020-12-09
Protocols: dict file ftp ftps gopher http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz NTLM NTLM_WB SPNEGO SSL TLS-SRP UnixSocke
Another interesting thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1605540
ok, I'll make an issue for this tomorrow if you don't beat me to it :)
> Another interesting thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1605540
So it seems it needs to check both for libz
and brotli
:thinking_face:
> ok, I'll make an issue for this tomorrow if you don't beat me to it 🙂
I don't care too much about Windows support, but I can make an issue
I have made a check in a delay
so it checks for this only once during the duration of a bb program, but it adds 10ms or so when doing the first request.. Perhaps the result could be cached in a file, but this leads to problems like: what if the system updates the curl binary.
on linux systems this time is probably lower
perhaps it's worth it though
and usually requests take anywhere between 50-100 ms anyway
perhaps catching the exception and then retry also a way to handle it
or perhaps only applying this check on Windows
ironically, I have Windows tests in place but apparently appveyor has a curl installed that does support this
hmm, maybe I should just add some docs for Windows 10 that they should either upgrade curl or use :compressed false
and not bother trying to work around some edge case in windows
### Compression
From babashka 0.2.4 onwards, this library will call `curl` with `--compressed`
by default. To opt out, pass `:compressed false` in the options. On Windows 10
the default installed curl does not support this option. You can either upgrade
curl or perform all requests using `:compressed false`.
Well, seems fine to me While the behavior right now is not really portable, at least it is consistent and the error is clear. Checking for features could lead to too much magic where people that expected e.g. that the compression worked would suddenly have a surprise when their scripts doesn't have compression on Windows
Right. I am stalking the people at MSFT now. https://twitter.com/borkdude/status/1395090669098700800
@borkdude How complete is the included implementation of agents in bb? I can create new instance of an agent. I can send
and send-off
, but not send-via
and if I put agent into failed state, I cannot recover with restart-agent
. I cannot tell if it's a feature or a 🐛
@ales.najmann These functions should be in babashka/impl/clojure/core.clj
in core-extras
, I think it's just a matter of adding them
Should I create an issue on GH?
My concern is to have full support for agents if possible.
or not having them at all, which would be a loss in my opinion, as they are great worker pattern.
@ales.najmann I have created a branch here: https://github.com/babashka/babashka/tree/more-agents Please inspect the commit to see if I have caught them all
and then you can go to appveyor to test it (if you run on Windows)
or CircleCI for macOS and linux
or get it from #babashka-circleci-builds
I would also be interested in hearing about your pattern :)
I have no pattern 🙂 it's just that agents have nice properties.
you said: great worker pattern
so I was curious how you are using them
Perhaps I could have used them to implement parallel tasks, I see await
is a lot simpler than what I did with core.async ;)
to be honest, I was just learning agents and I was curious how to use them with bb... so sorry, I but don't have anything specific 😄
no worries, I think it's good to add support for it
the build is done. https://ci.appveyor.com/project/borkdude/babashka/build/artifacts
please test :)
hmm, I need to patch these functions for binding conveyance as well.
there are more functions to add...
await-for
agent-error
error-handler
error-mode
get-validator
shutdown-agents
add-watch # ?
remove-watch # ?
I'll make an issue for that
I did add agent-error
what is handler-error?
can you use the full var names?
it's error-handler... sorry
add-watch and remove-watch are already there
Added these now:
+ 'await-for (copy-core-var await-for)
+ 'error-handler (copy-core-var error-handler)
+ 'error-mode (copy-core-var error-mode)
+ 'get-validator (copy-core-var get-validator)
I listed functions from this page: https://clojure.org/reference/agents#_related_functions
ok, I have them all now
there is a small patch needed for binding conveyance. when you have a dynamic var binding, the started agent thread also needs to see it. but this should be doable
for now you can test the build when it's ready
🙏 great
there is also agent-errors, but is marked as deprecated in clojure, and I don't think it should be included.
ok
So the problem I'm fixing right now:
$ clojure -M:babashka/dev -e '(def ^:dynamic *foo* 1) (def a (agent nil)) (binding [*foo* 2] (send-off a (fn [_] *foo*))) @a'
1
This should be 2
Luckily this is relatively easy
Fix pushed
Nice PR. I'm surprised it makes sense to my untrained eyes.
ok, I merged it now