This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-27
Channels
- # announcements (11)
- # asami (7)
- # babashka (140)
- # beginners (58)
- # calva (12)
- # clj-kondo (5)
- # cljsrn (9)
- # clojure (60)
- # clojure-australia (8)
- # clojure-boston (1)
- # clojure-europe (35)
- # clojure-france (2)
- # clojure-germany (5)
- # clojure-italy (8)
- # clojure-nl (7)
- # clojure-sweden (14)
- # clojure-uk (23)
- # clojurescript (16)
- # community-development (2)
- # cursive (7)
- # datomic (6)
- # docker (1)
- # emacs (4)
- # fulcro (11)
- # graalvm (5)
- # honeysql (6)
- # jobs (6)
- # jobs-discuss (36)
- # lsp (19)
- # malli (7)
- # meander (8)
- # off-topic (18)
- # pathom (16)
- # practicalli (33)
- # re-frame (43)
- # react (2)
- # remote-jobs (11)
- # sci (83)
- # shadow-cljs (55)
- # tools-deps (48)
@thiagokokada you can do it like this
(shell (format "env VAR1=%s VAR2=%s %s" "var1" "var2" "ls -la")
Like I said in the above thread, I want to change the current environment variables for the program, not for a subprocess
@thiagokokada https://gist.github.com/mikeananev/c87c1596aed50b7bb095a816f6921737 you can read env vars for the current process (see line 14) and then modify them as usual map.
I may have understand wrong, but in this case I really need to export the environment variables again
I can of course inject then in every shell call and every usage in my Clojure program, but this get old really quickly
@mike1452 the above can be done better by passing a map with :extra-env as the first arg:
(shell {:extra-env {"FOO" "BAR"}} "ls -la")
Cool.
There is also :env
to overwrite all env vars. These are the same options as in babashka.process
what is fqdn of shell ? babashka.process
? can't find it there
@mike1452 shell
is a variant of babashka.process tweaked more towards usage in bb.edn. It is automatically imported from babashka.tasks
Thanks! Now it works
bb -e '(babashka.tasks/shell {:extra-env {"FOO" "BAR"}} "env")'
bb -e '(babashka.tasks/shell {:env {"FOO" "BAR"}} "env")'
I wanted to check env settings from one line script.
Maybe this will interest someone, it is a modification of test_runner.clj
that automatically discovers test files: https://gist.github.com/thiagokokada/fee513a7b8578c87c05469267c48e612
FYI, i’ve been playing with autocompletion on the command line. I’ve created a small POC that could maybe grow into something bigger. It’s inspired by how the aws
cli tool is structured and can do autocompletion in the same way. The responsiveness is much better though 😎 https://github.com/jeroenvandijk/matryoshka
@UGNFWPPGF I started with your work as inspiration, but i couldn’t figure out how to do nested completions. I’m not sure if the AWS approach is better or not, but it works
https://github.com/jeroenvandijk/matryoshka/blob/9f70e63418b7b9ee7a58255d83a392da4b7f35de/matryoshka#L83
This is not a "doesn't work yet" problem, but a problem that aliases are only valid in the next top level s-expression. You should use resolve
to resolve a fully qualified symbol, if you are in the same expression.
Clojure 1.10.1
user=> (defn foo [] (require '[clojure.set :as set]) (set/union #{1 2 3} #{4 5 6}))
Syntax error compiling at (REPL:1:47).
No such namespace: set
Yeah indeed. I guess I have to have a better look at what you did in bb tasks. This was a quick “addon” for now (i should have left it out)
@U0FT7SRLP would your solution work for both bash / zsh? it would be very nice :)
I’m using zsh, not sure about bash, but I’m guessing if we try we could even make it work for Windows 🙂 It uses the same approach as the AWS tool https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html#cli-command-completion-linux
The output is slightly different from what @UGNFWPPGF did. Maybe the underlying framework is different
I don’t know if this is the way for bash, but in my (basic) bash shell it doesn’t work:
bash-3.2$ autoload bashcompinit && bashcompinit
bash: autoload: command not found
bash-3.2$ autoload -Uz compinit && compinit
bash: autoload: command not found
bash-3.2$ compinit
bash: compinit: command not found
bash-3.2$ export PATH=".:$PATH"
bash-3.2$
not out of the box at least 😅
@U0FT7SRLP really cool!
i'll have to dig into the implementation later today
the other thing that keeps coming to mind is wanting to support all of bb's cli opts, not just tasks
@U04V15CAJ I’ve fixed the :deps
and :requires
“feature”. This works now https://github.com/jeroenvandijk/matryoshka/blob/main/tasks/custom.edn
I don’t know yet. I am looking for something that I can use or all my projects. The autocompletion makes this actually feasible. You start with a category and the suggestions help you navigate
I was thinking of wrapping these commands https://github.com/practicalli/clojure-deps-edn so that I can use them everywhere without having to do constant lookups
I’m not sure if I’m missing something other than the global part
good question. Not in some particular way, but the difference with babashka tasks is that all the tasks are isolated and it has a tree structure so it should stay fast
I’m not saying this could not be part of babashka tasks and that this is better (i just started working on it today so it’s nothing really). I don’t know yet where this will end. When I have a structure I like I’ll try to see what the main differences are
If I have a global library of tasks this could easily become really big. So code loading would be an issue if you are not careful. If you try the aws cli you feel the difference 🙂
But i think it’s a bit premature to talk about my “benefits”. I’m not actually using it for something
well, it's good to take future use case into account without locking down the design to exclude that possibility right now, that's why I am asking
Especially the autocompletion needs to stay fast for a nice experience
The #include
is lazy loading here https://github.com/jeroenvandijk/matryoshka/blob/main/tasks.edn#L1
So you don’t get hit by a huge startup penalty when you add many libraries. It’s only about the nesting. So a nesting of 4 would mean having to load 4 of these files
instead of something to the power of 4
I think these things can also be implemented using normal keywords instead of reader tags btw
it's first parsed as EDN only and only the task that is executed is actually re-parsed as code
ah yeah so i’m guessing it’s a bit premature
i was also thinking what if you could add a module
i was thinking you could have an aws
module and it would look like this file
that was my fantasy at least 😅 Not sure what parts are actually required for this to work
I’m curious how you would use keywords instead of the reader tags btw
(I stole the #include
idea from https://github.com/juxt/aero btw. That one is not lazy though)
haha hmmm no that would be too simple 😛
fair enough, that would be better
yeah, I know that lib. personally I would like to avoid reader tags a little bit, but maybe my feeling isn't justified on good reasons
no i think you are right, probably better to keep it simple
(forgot the link)
Hmm, crap, if you have :deps
in bb.edn
but if you also have deps.edn
, those deps.edn deps are actually also downloaded and added to the classpath ;)
Note sure if it is related, but I noticed that babashka.deps/add-deps
doesn’t complain when I give it rubbish
I didn't add the '{:deps ...}' wrapping and I was wondering why my require wasn't working. So not really rubbish, but it was invalid config
+1 here. I ran into the above described situation as well. I can confirm it can give unexpected errors and slower load time
Cool 🙂
The case where it was giving me unexpected results was when I had my custom bb tasks runner script and giving it empty {:deps {} }
. So I wasn’t expecting anything, however the deps.edn
in that directory had an error, so the whole call failed. But the script I was trying to run was a hello world (without deps), so it was confusing at first
Normally this hello world would be quick, but due to the (failing) deps it was slower
i’ll try the new binary!
I'll add another check for an empty deps map, since it doesn't have to call out to tools.deps in that case
so far everything works. Calling tools.deps with an empty map adds 10ms. Not major
I've been in a few programming language chats and one popular topic / channel was #naming-things
I'm trying to make a babashka project with a structure that mirrors a clojure one, and I want a test
task that comes with the test dir added to the classpath.
First I tried this, but it looks like there's no :extra-paths
like in deps.edn
{:paths ["src"]
:tasks
{test {:extra-paths ["test"]
:requires ([foo.test-runner :refer [run]])
:task (run)}}}
Then I tried to work around it, but it looks like the require needs to be in a separate expression from where it's used, so this doesn't work either.
{:paths ["src"]
:tasks
{test {:requires ([babashka.classpath :as cp])
:task (do (cp/add-classpath "test")
(require '[foo.test-runner :refer [run]])
(run))}}}
I also tried something similar with requiring-resolve
, but no luck.
Any suggestions?@madstap tasks do not (yet) support :extra-paths
. you can take a look at how @thiagokokada did it here:
https://clojurians.slack.com/archives/CLX41ASCS/p1619532085157000
you could just add the test dir to the classpath in the script and load the script using (load-file ...)
in the task
The test-runner script would have to be on the classpath then, for me to be able to run it as a task, or I'd have to run it as a standalone script
you could first use load-file
and then call a function from that script, that would work too
Maybe I'm missing something, but this doesn't work
{:paths ["src"]
:tasks
{test {:task (do (load-file "test/foo/test_runner.clj")
(require '[foo.test-runner])
(foo.test-runner/run))}}}
The gilardi scenario is basically this:
user=> (defn foo [] (require '[clojure.set :as set]) (set/union #{1 2 3} #{4 5 6}))
Syntax error compiling at (REPL:1:47).
No such namespace: set
The reader has to know about the alias (or namespace) set
already before the requires has happened
:aliases {:test {:extra-paths ["test"]}}
:tasks {test {:aliases [:test] :task foo.test-runner/run}}
Are aliases preferable to an :extra-paths
key in the task?
:tasks {test {:extra-paths ["test"] :task foo.test-runner/run}}
I think one could also do it like this, perhaps:
{:tasks {-add-test-cp (babashka.classpath/add-classpath "test"),
test {:depends [-add-test-cp] :task foo.test-runner/run}
could you try that, just for fun...?This doesn't work though.
{:paths ["src"]
:tasks {-add-test-cp (babashka.classpath/add-classpath "test"),
test {:depends [-add-test-cp]
:requires ([foo.test-runner :refer [run]])
:task (run)}}}
that doesn't work because the :requires are processed on the top level before anything else
@madstap I pushed support for :extra-paths
and :extra-deps
in tasks to master now. Are you willing to take it for a spin?
since you can depend on a task that adds extra-deps and extra-paths as a sort of alias
ok, here is a binary: https://17876-201467090-gh.circle-artifacts.com/0/release/babashka-0.3.7-SNAPSHOT-linux-amd64.tar.gz fresh from #babashka-circleci-builds