This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-09
Channels
- # announcements (3)
- # babashka (120)
- # beginners (87)
- # calva (7)
- # clj-kondo (35)
- # cljsrn (25)
- # clojure (94)
- # clojure-austin (4)
- # clojure-europe (53)
- # clojure-nl (2)
- # clojure-norway (6)
- # clojurescript (16)
- # conjure (8)
- # cursive (6)
- # data-oriented-programming (2)
- # data-science (19)
- # datahike (1)
- # datalevin (29)
- # datomic (13)
- # fulcro (50)
- # gratitude (1)
- # honeysql (9)
- # jackdaw (2)
- # kaocha (7)
- # leiningen (3)
- # malli (4)
- # off-topic (4)
- # polylith (3)
- # re-frame (5)
- # reagent (1)
- # releases (1)
- # reveal (4)
- # shadow-cljs (17)
- # tools-deps (10)
- # vim (17)
- # vscode (4)
- # xtdb (3)
Hello,
i am super new to scripting but i wanna do something.
So i have a video stream that i am storing using ffmpeg and i would like to use babashka to cut that ongoing stream by hour.
So each hour i stop the recording and i create new folder and continue storing in that new folder.
Idea is to have stream segmented by hour.
/videos/13:00/stream (lenght 1h)
/videos/14:00/stream (length 1h)
...
Currently i have everything setup with clojure.java.shell
but the main problem is that i don't know how to stop the process after i initiate it with sh.
(sh "ffmpeg" ... file-name)
This is blocking and i don't know how to interrupt it.
Maybe i am doing this wrong way?
Any suggestions ?@U45SLGVHV Hey welcome!
I recommend taking a look at the built-in babashka.process
library
I see there's also an ffmpeg library which does this for you in bb: https://github.com/luissantos/ffclj
Thanks! So stream is 24/7 and i want to chunk it. i couldn't find a way to stop ffclj. wait task - will just hang because i am recording a stream process - i also couldn't fin a way to stop the process. Did i miss anything in the documentation? My idea was to have a loop, read the stream and store it to file, after 1h stop and repeat (but to new file).
Is there a way to get the Babashka version of the stack trace at runtime? I'd like to make https://github.com/hlship/trace work with BB, but it uses Thread.getStackTrace
and a small amount of guesswork to approximate where the code is called from https://github.com/hlship/trace/blob/main/src/net/lewisship/trace.clj#L65 ... I tried (-> (Thread/currentThread) .getStackTrace sci.core/format-stacktrace)
but it returns [].
you can try:
(catch ^:sci/error Exception e)
This is a new experimental feature which puts the interpreter stacktrace info as ex-data
on e
which can be processed with sci/stacktrace
and formatted with sci/format-stacktrace
(require '[sci.core :as sci])
(defn foo [x]
(/ 1 x))
(defn bar []
(foo 0))
(try (bar)
(catch ^:sci/error Exception e
(->> e
(sci/stacktrace)
(sci/format-stacktrace)
(run! prn))))
I'll give this a try when I can; it may involve throwing an exception just to catch it for its stack trace, which is not great performance-wise, but that's a lesser concern. I'm sure even in the JVM getting the current stack trace is relatively expensive.
Remember back in the day where people convinced themselves that the best way to write an efficient loop was to write an infinite loop that throws an exception, and to catch the exception outside the loop? I try not to be that person. One of my big Tapestry regrets is that I used a little bit of throwing exceptions for flow of control, something I would never do now.
The above is just to expose the error handling that SCI normally offers outside of the interpreter to within the interpreter e.g. in a -main
function. Throwing and immediately catching probably results in an empty stack trace due to how this is implemented.
I'll have to experiment; alternately, is there a way to know the namespace and fn name in Babashka at macro expansion time? I wish Clojure exposed this, but of course due to order of operations, it might not even know.
> is there a way to know the namespace and fn name in Babashka at macro expansion time? Not sure what you mean here, got an example?
Calls to trace
output something like:
{:in my.example.ring-handler/handle-request,
:line 6,
:thread "nREPL-session-c3dde1ce-ca19-4e78-95ad-d0e4beda61eb",
:method :get,
:uri "/status"}
I'm doing some tricks with stack traces and name de-mangling to get the :in
key, which represents the namespace and function (possibly nested) where the trace
macro is expanded. I was wondering if sci exposes something extra that would make it easier to determine this inside my macro, but failing that, I want to adapt the same technique to BB.Well, the line and column are available as metadata on &form
and *file*
has the current file, I guess the only thing missing is the parent function then right?
what do you think about including this in babashka? https://clj-commons.org/camel-snake-kebab/
since inevitably every project contains an adhoc and buggy version of one of the features of this
zero deps, too
only 163 lines according to tokei
That raises the larger question of what is the cutoff for any library being baked in; I would say criteria involve universality and how useful it would be baked into the implicit user namespace and whether it requires Java classes be baked in; for camel-snake-kebab that isn't so useful in user namespace (this is very subjective) and the library can otherwise just be added as a dependency in bb.edn. I mean, I can definitely see using it or https://github.com/trhura/clojure-humanize in tools I write, but baking it in also means locking down the version.
I tested humanize and it doesn't work due to the dependency on joda time. If the project maintainer can be convinced to java.time it might work.
Commenting out the date-related functions, then it seems to work:
$ bb --classpath $(lein classpath) -e "(require '[clojure.contrib.humanize :as h]) (h/intcomma 1000) "
"1,000"
$ bb --classpath $(lein classpath) -e "(require '[clojure.contrib.humanize :as h]) (h/numberword 1000) "
"one thousand"
No longer actively maintained: https://github.com/trhura/clojure-humanize/issues/26#issuecomment-1087023364
first I've heard of that library, it looks great! stars it
I prefer to keep libraries that work perfectly fine as a library out as the binary image size can then be used for something else. There are exceptions but those exceptions are probably already built-in: tools.cli, data.csv :)
Hey Look Ma eql
works natively on Windows too 😎
https://github.com/littleli/scoop-clojure/pull/180 @lilactown
I hadn't considered json to edn and then using eql
amazing!!
@lilactown Why does your example contain --no-pretty
?
I haven't used eql
that much, but it's good, maybe it's also an option to bake into jet eventually
The reason I use —no-pretty is because the CLI I wrote expects the EDN passed via stdin to be on one line
it should read until stdin is closed right?
I thought so too but recall running into issues. I'll try again when I'm back at my computer
For now I'm doing this
cat ~/.config/bb.edn my-bb.edn | jet --collect --func "(fn [edns] (apply merge edns))"
I wanted some sort of global config support$ bb -e "(babashka.deps/merge-deps ['{:deps {a 1}} '{:deps {a 2 b 3}}])"
{:deps {a 2, b 3}}
Anyone have a sense of what’s going on with Babashka on nixpkgs master?
[nix-shell:~]$ hydra-check babashka --arch=aarch64-darwin --channel=master
Build Status for babashka.aarch64-darwin on master
⚠ This job is not a member of the latest evaluation of its jobset. This means it was removed or had an evaluation error.
Pinging @UKFSJSM38, @U4NGX0FHN and @UFDRD93RR
@U050CT4HR Looks fine for me, at least looking at the hydra logs
Well, this is also failing for me, but: https://hydra.nixos.org/build/186540565
This question might belong in #nix, but I don’t yet understand how to find a working nixpkgs SHA for n
packages and m
architectures.
> How did you find that build? I generally just search in the Web interface directly. It list the latest builds
Works for one individual package, but not for n
packages. We’re just using Nix to create reproducible development environments. Should I be pinning different versions of nixpkgs for each package we need?
I was confused as to why bb test
was failing for me on babashka/fs
on Windows.
The which
tests rely on on-path
being on the PATH
.
It seemed that the bb.edn
test
tasks was https://github.com/babashka/fs/blob/111894217039261c45e4b9f415e6371ae41cf148/bb.edn#L8-L9:
:tasks
{:requires ([babashka.fs :as fs])
test (clojure {:extra-env {"PATH" (str "on-path" fs/path-separator (System/getenv "PATH"))}}
"-M:test")
But then I noticed the https://github.com/babashka/fs/blob/111894217039261c45e4b9f415e6371ae41cf148/appveyor.yml#L49:
set PATH=on-path;%PATH%;
“Huh”, I thought, why is that needed?
I typed set
from a cmd
prompt and saw that path was showing under environment var Path
.
If I change the bb.edn
above to use Path
instead of PATH
:
:tasks
{:requires ([babashka.fs :as fs])
test (clojure {:extra-env {"Path" (str "on-path" fs/path-separator (System/getenv "PATH"))}}
"-M:test")
the path is updated appropriately on Windows and the test passes.Running tests in #{"test"}
Testing babashka.fs-test
FAIL in (list-dirs-and-which-test) (fs_test.clj:292)
expected: (fs/which "foo.foo")
actual: (not (fs/which "foo.foo"))
Ran 42 tests containing 144 assertions.
1 failures, 0 errors.
Error while executing task: test
^Before
Running tests in #{"test"}
Testing babashka.fs-test
Ran 42 tests containing 144 assertions.
0 failures, 0 errors.
^After
So basically confirmed?Huh! Yes! Thanks @UBLU3FQRZ!
Ok… here’s an interesting test on Windows:
bb
Babashka v0.9.161 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (require '[babashka.tasks :as t])
nil
user=> (t/shell {:extra-env {"pAtH" "foo"}} "clojure")
Clojure 1.11.0
user=> (System/getenv "PATH")
"C:\\Program Files\\Parallels\\Parallels Tools\\Applications;...etc...etc..."
user=> (System/getenv "pAtH")
"C:\\Program Files\\Parallels\\Parallels Tools\\Applications;...etc...etc..."
user=> (get (System/getenv) "PATH")
nil
user=> (get (System/getenv) "Path")
"C:\\Program Files\\Parallels\\Parallels Tools\\Applications;...etc...etc..."
user=> (get (System/getenv) "pAtH")
"foo"
From https://docs.oracle.com/javase/tutorial/essential/environment/env.html: > There are many subtle differences between the way environment variables are implemented on different systems. For example, Windows ignores case in environment variable names, while UNIX does not.
Ok, so maybe the way babashka/process
is merging :extra-env
environment vars needs to be tweaked for Windows.
It seems that the Windows shells match case insensitively when overriding:
cmd.exe:
C:\Users\lee>set foo=bar
C:\Users\lee>echo %FOO%
bar
C:\Users\lee>echo %fOo%
bar
C:\Users\lee>set FOO=gum
C:\Users\lee>echo %fOo%
gum
C:\Users\lee>echo %FOO%
gum
C:\Users\lee>set | grep -i FOO
foo=gum
Powershell:
PS C:\Users\lee> $env:foo = "bar"
PS C:\Users\lee> echo $env:foo
bar
PS C:\Users\lee> echo $env:FoO
bar
PS C:\Users\lee> $env:FOO = "gum"
PS C:\Users\lee> echo $env:foo
gum
PS C:\Users\lee> echo $env:FoO
gum
PS C:\Users\lee> Get-ChildItem Env: | grep -i FOO
foo gum
macOS on default zsh:
❯ foo=bar
❯ echo $foo
bar
❯ echo $FoO
❯ FOO=gum
❯ echo $FOO
gum
❯ echo $foo
bar
is case sensitive. Same idea for bash on Linux.@U04V15CAJ, when you have a moment to read the above, lemme know if you'd like an issue/PR on babashka/process
I don't think fs has to account for Windows flakes this much, Java also doesn't do that right?
Java does not seem to handle this well for process builder environment on Windows. Behaviour does not match Windows shell behaviour. System/getenv seems to behave like you'd expect though.
This is the first time I hear about this. Perhaps with Path/PATH it's more common, but I'd rather just fix our tests than having to do a str/lower comparison etc.
Well not many Clojure users use Windows, so there's that too...
Path
on Windows is normally updated via PATH
when setting, but not for :extra-env
.
I personally think it is worth fixing, but of course, your call.
I could do a little poking around to see examples of what others have done around process builder environment for Windows.
Can you formulate a clear problem statement and a proposed solution? I'm not sure I get it entirely.
It's Path
on my Windows VM, and apparently on @UBLU3FQRZ's Windows too.
I'm assuming Path
is the default name of path on Windows. Could double-check that, but it seems to be the case.
If you do extra-env then you automatically merge the already set Path, so I don't see how that could go wrong
Yah, thanks @UBLU3FQRZ, that helps.
Here's an openjdk bug someone raised around the issue: https://bugs.openjdk.org/browse/JDK-8245431
but to add more confusion... if you run env
command from powershell or cmd.exe
there is PATH not Path... :thinking_face:
well, in such case I think well documented way to run programs. I mean to communicate requirements is a way to go.
Problem statement + proposed solution + considered alternatives welcome. My favorite alternative is "leave it" right now, unless I learn more in a digestible format that isn't a long-threaded conversation. ❤️
Ok, I think it is worth raising as an issue to consider in babashka/process. Will invest the time to do so.
I see Stackoverflow has a few issues on that one too. An example: https://stackoverflow.com/questions/48686267/windows-10-system-environment-variables-path-vs-path
Case sensitivity is the endless source of unexpected behaviour, not just on Windows, but also on Mac.
In a company where I work we have a 20+GB repo, that you cannot clone with Git on Mac because case sensitivity issue.
Ok, fwiw, issue raised: https://github.com/babashka/process/issues/79