babashka-sci-dev

lispyclouds 2023-01-24T09:17:29.533369Z

ive noticed that when i use :local/root deps with relative paths in bb.edn and use it from another place via --config, the local paths are resolved relative to my pwd and not the bb.edn. is it due to deps.clj being used there and its an expected behaviour? if yes, should it be changed as we say --config <file> Replacing bb.edn with file. Relative paths are resolved relative to file.?

lispyclouds 2023-01-28T09:11:01.920909Z

compared to the https://github.com/babashka/babashka/pull/1478#issuecomment-1407181862 from mac, linux has a very different error:

lein test babashka.bb-edn-test
=== deps-root-tests

Error building classpath. ../../home/lispyclouds/code/repos/babashka (Is a directory)
java.io.FileNotFoundException: ../../home/lispyclouds/code/repos/babashka (Is a directory)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:158)
        at java.base/java.io.FileReader.<init>(FileReader.java:75)
        at $slurp_edn.invokeStatic(io.clj:42)
        at clojure.tools.deps$slurp_edn_map$fn__664.invoke(deps.clj:39)
        at clojure.tools.deps$slurp_edn_map.invokeStatic(deps.clj:39)
        at clojure.tools.deps$slurp_deps.invokeStatic(deps.clj:96)
        at clojure.tools.deps.script.make_classpath2$read_deps.invokeStatic(make_classpath2.clj:163)
        at clojure.tools.deps.script.make_classpath2$run.invokeStatic(make_classpath2.clj:174)
        at clojure.tools.deps.script.make_classpath2$_main.invokeStatic(make_classpath2.clj:228)
        at clojure.tools.deps.script.make_classpath2$_main.doInvoke(make_classpath2.clj:195)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:705)
        at clojure.core$apply.invokeStatic(core.clj:667)
        at clojure.main$main_opt.invokeStatic(main.clj:514)
        at clojure.main$main_opt.invoke(main.clj:510)
        at clojure.main$main.invokeStatic(main.clj:664)
        at clojure.main$main.doInvoke(main.clj:616)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:705)
        at clojure.main.main(main.java:40)
Tests failed.

lispyclouds 2023-01-28T09:12:38.128119Z

some level of deps-root testing is there on my PR though

borkdude 2023-01-28T09:31:49.360179Z

it seems it tries to read the deps.edn file as a directory?

borkdude 2023-01-28T09:31:59.235789Z

(the other way around)

lispyclouds 2023-01-28T09:36:18.393669Z

its the same test im running here too, not sure if there is a better way to test this that doenst depend on where its running

borkdude 2023-01-28T09:38:43.533369Z

I'm not sure what you are doing. Is this up somewhere?

borkdude 2023-01-28T09:39:03.634519Z

In the PR?

lispyclouds 2023-01-28T09:39:17.453699Z

this code here: https://github.com/babashka/babashka/pull/1478#issuecomment-1407181862

lispyclouds 2023-01-28T09:39:57.609529Z

im running this in the same deftest i added to the PR

lispyclouds 2023-01-28T09:40:10.004459Z

didnt push it yet as it breaks

borkdude 2023-01-28T09:41:49.632319Z

push it with [skip ci] and I'll have a look locally

lispyclouds 2023-01-28T09:44:21.348759Z

pushed

borkdude 2023-01-28T09:47:23.684219Z

I'm getting:

lein test babashka.bb-edn-test
=== deps-root-tests

Error building classpath. Local lib local/dep not found: /Users/borkdude/dev/babashka/local-dep

lispyclouds 2023-01-28T09:51:42.687749Z

that's weird, is the deps-root in the temp dir for you in https://github.com/babashka/babashka/blob/rel-deps/src/babashka/impl/deps.clj#L96 ?

lispyclouds 2023-01-28T09:52:04.299049Z

this error should come without my changes

borkdude 2023-01-28T10:00:54.709049Z

the issue is that the tests set a default config and deps-root so I made this change in the test code:

args (cond-> args
               (and *bb-edn-path* (not (some #(= "--config" %) args)))
               (->> (list* "--config" *bb-edn-path*))
               (and *bb-edn-path* (not (some #(= "--deps-root" %) args)))
               (->> (list* "--deps-root" ".")))

πŸ‘πŸΎ 1
borkdude 2023-01-28T10:02:16.056479Z

but in the normal bb runs the deps-root is the parent dir of the config

lispyclouds 2023-01-28T10:04:01.076879Z

which should be okay right? as long as the deps root is passed to the deps/dir with my changes?

borkdude 2023-01-28T10:09:28.200019Z

I pushed a wip commit and commented out the tests that don't yet work

borkdude 2023-01-28T10:09:53.302199Z

You can run that test with: lein do clean, test :only babashka.bb-edn-test/unix-task-test

borkdude 2023-01-28T10:10:13.422639Z

sorry, this one: lein do clean, test :only babashka.bb-edn-test/deps-root-test

borkdude 2023-01-28T10:11:12.784949Z

Now I'm also getting:

Error building classpath. Can't create directory: /private/Users/borkdude/.clojure/.cpcache
Ah, this might make sense now, maybe a thing in deps.clj where it tries to write the cache directory but it shouldn't take *dir* into account here

lispyclouds 2023-01-28T10:12:26.566209Z

yeah i suppose theres gonna be differing behaviour due to this

borkdude 2023-01-28T10:12:56.598869Z

I don't see any reference to *dir* here in deps.clj:

config-dir
        (or (*getenv-fn* "CLJ_CONFIG")
            (when-let [xdg-config-home (*getenv-fn* "XDG_CONFIG_HOME")]
              (.getPath (io/file xdg-config-home "clojure")))
            (.getPath (io/file (home-dir) ".clojure")))

borkdude 2023-01-28T10:13:06.630139Z

oh I see

borkdude 2023-01-28T10:13:16.712879Z

no, I don't

borkdude 2023-01-28T10:13:23.068029Z

user-cache-dir
          (or (*getenv-fn* "CLJ_CACHE")
              (when-let [xdg-config-home (*getenv-fn* "XDG_CACHE_HOME")]
                (.getPath (io/file xdg-config-home "clojure")))
              (.getPath (io/file config-dir ".cpcache")))

borkdude 2023-01-28T10:13:58.723199Z

oh I see:

cache-dir
          (if (.exists (io/file deps-edn))
            (.getPath (io/file *dir* ".cpcache"))
            user-cache-dir)

lispyclouds 2023-01-28T10:14:13.363599Z

hehe finally πŸ˜›

borkdude 2023-01-28T10:15:17.719659Z

in bb.edn we set deps-file to ""

borkdude 2023-01-28T10:15:27.200519Z

in order to suppress loading a local deps.edn

borkdude 2023-01-28T10:15:32.749279Z

and this causes that behavior

lispyclouds 2023-01-28T10:17:29.388789Z

there's quite a few knobs to be aware about

borkdude 2023-01-28T10:36:33.807659Z

pushed another fix

borkdude 2023-01-28T10:38:44.063889Z

Can you explain this test to me?

(testing "custom deps-root path"
        (let [out     (bb "--config" config "--deps-root" "/tmp" "cp")
              entries (cp/split-classpath out)]
          (is (= 1 (count entries)))
          (is (= "/tmp/src" (first entries)))))

borkdude 2023-01-28T10:39:44.359069Z

oh I get it yes, but you have to make this more cross platform, "/tmp" doesn't work on Windows I think

borkdude 2023-01-28T10:39:49.575239Z

use another tmp dir

lispyclouds 2023-01-28T10:40:23.068099Z

yeah that was one of my doubts, looking at it now

borkdude 2023-01-28T10:40:54.366719Z

also don't use "/foo/" string comparisons, use babashka.fs

πŸ‘πŸΎ 1
borkdude 2023-01-28T10:41:19.798839Z

lein test :only babashka.bb-edn-test/deps-root-test
FAIL in (deps-root-test) (bb_edn_test.clj:498)
custom deps-root path
expected: (= "/tmp/src" (first entries))
  actual: (not (= "/tmp/src" "C:\\tmp\\src"))
=== deps-race-condition-test

borkdude 2023-01-28T10:43:03.587989Z

I guess my arg fixes weren't necessary since the last --deps-root argument wins

borkdude 2023-01-28T10:43:07.119409Z

I'll remove those

πŸ‘πŸΎ 1
borkdude 2023-01-28T10:43:33.600979Z

pushed

borkdude 2023-01-28T10:44:41.389689Z

but this test:

(testing "default deps-root path is same as bb.edn"
        (let [out     (bb "--config" config "cp")
              entries (cp/split-classpath out)]
          (is (= (fs/parent f) (fs/parent (first entries))))))
succeeds, but in the tests we always add --deps-root "." so this test isn't testing what it's supposed to

borkdude 2023-01-28T10:44:59.413349Z

I would expect it to fail, considering what it's saying

borkdude 2023-01-28T10:45:47.447109Z

so maybe the arg fix is necessary after all

borkdude 2023-01-28T10:47:14.939079Z

oh no, this is good since we don't set *bb-edn-path* in this test, we don't use with-config

borkdude 2023-01-28T10:47:26.981139Z

so these are the printed args :

("--config" "/var/folders/j9/xmjlcym958b1fr0npsp9msvh0000gn/T/4a86539f-dff2-4c9e-8c4d-f8931232a5902671065622392340497/bb.edn" "cp")
:entries ["/var/folders/j9/xmjlcym958b1fr0npsp9msvh0000gn/T/4a86539f-dff2-4c9e-8c4d-f8931232a5902671065622392340497/src"]

borkdude 2023-01-28T10:47:53.615409Z

yep, all good

lispyclouds 2023-01-28T10:47:54.183059Z

looks good to me

borkdude 2023-01-28T10:48:07.930259Z

we could force *bb-edn-path* to nil, just to be sure

lispyclouds 2023-01-28T10:48:37.277689Z

should it be set just for this test right?

borkdude 2023-01-28T10:49:10.698939Z

yes

borkdude 2023-01-28T10:49:30.242119Z

since in this test you're spitting your own bb.edn and setting config + deps-root yourself

borkdude 2023-01-28T10:49:47.695159Z

ok, it all makes sense now. when you fix the windows issue, I'll merge

lispyclouds 2023-01-28T10:49:55.258219Z

yep

lispyclouds 2023-01-28T10:50:08.812139Z

we finally have more tests too

πŸŽ‰ 1
borkdude 2023-01-28T10:57:12.746549Z

Tests are still failing after I removed the arg fixes

lispyclouds 2023-01-28T10:57:33.845749Z

yes the linux error i mentioned above

lispyclouds 2023-01-28T10:57:42.238209Z

you can see it in the CI

borkdude 2023-01-28T10:57:49.490639Z

that's what I meant, CI

lispyclouds 2023-01-28T10:58:28.127559Z

yeah i mean a not my machine specific error πŸ˜…

lispyclouds 2023-01-28T10:58:58.220559Z

does it pass for you?

borkdude 2023-01-28T10:59:34.547359Z

No:

Ran 213 tests containing 567 assertions.
4 failures, 0 errors.

borkdude 2023-01-28T10:59:47.113299Z

ah this is something else

borkdude 2023-01-28T11:00:12.675409Z

some JDK19 issue (because I switched JDK for your issue)

lispyclouds 2023-01-28T11:00:21.511099Z

ahh

borkdude 2023-01-28T11:00:35.741529Z

not a real issue, but error messages being different

borkdude 2023-01-28T11:00:47.660249Z

and then some string comparisons fail, I will test with my regular graalvm

borkdude 2023-01-28T11:01:08.094779Z

Ran 213 tests containing 567 assertions.
0 failures, 0 errors.

lispyclouds 2023-01-28T11:01:09.034569Z

but if you run just this test, does it pass?

borkdude 2023-01-28T11:01:18.013239Z

yes

lispyclouds 2023-01-28T11:01:39.176449Z

interesting, does it only fail on linux somehow then?

borkdude 2023-01-28T11:02:34.639749Z

I'll make another check in deps.clj to not read deps.edn when it's not a file

πŸ‘πŸΎ 1
lispyclouds 2023-01-28T11:04:17.293579Z

but why is it even going to ../../home/circleci/repo?

borkdude 2023-01-28T11:05:44.514809Z

dunno. maybe you can dig into this, I'm going for a run

lispyclouds 2023-01-28T11:06:04.975709Z

yeah, good that i can reproduce this here

borkdude 2023-01-28T11:06:50.115329Z

it might be good to insert some printlns etc in the deps.clj (use the -debug function, as out and err are captured in the tests)

lispyclouds 2023-01-28T11:07:01.206399Z

yep

lispyclouds 2023-01-28T11:07:48.778149Z

i was doing it in places til borkdude.deps/deps is called.

lispyclouds 2023-01-28T11:33:33.052119Z

i'll try to dig in a few hours, need to finish off some stuff!

borkdude 2023-01-28T12:04:47.462449Z

ok, I returned from my run. I can try on my linux machine

lispyclouds 2023-01-28T12:06:23.248959Z

some stuff i found: deps-edn is an empty string in deps clj and its being set to config-project and (relativize config-project) gives that weird path

lispyclouds 2023-01-28T12:07:02.126089Z

due to https://github.com/borkdude/deps.clj/blob/master/src/borkdude/deps.clj#L807 the surrounding shell cmd is failing

borkdude 2023-01-28T12:07:37.090479Z

ah ok

borkdude 2023-01-28T12:07:52.273329Z

I can repro on linux too

lispyclouds 2023-01-28T12:08:51.407649Z

so somehow it cant find the deps.edn in the *dir*?

lispyclouds 2023-01-28T12:11:58.527049Z

ah so *dir* is the dir where the local-dep dir is and that has the deps.edn. so it cant find it

lispyclouds 2023-01-28T12:12:47.880549Z

not sure why its different in mac?

borkdude 2023-01-28T12:13:47.251949Z

setting deps-file to an empty string is a workaround to ignore the local deps.edn

borkdude 2023-01-28T12:13:54.252599Z

which should be the behavior for bb.edn

lispyclouds 2023-01-28T12:14:27.586039Z

brb in some time

borkdude 2023-01-28T12:16:06.705069Z

sure

borkdude 2023-01-28T12:28:51.258509Z

I pushed another "fix"

borkdude 2023-01-28T12:45:31.871529Z

This "fix" seems to work, but it will fail if there is a "nil" file ;)

borkdude 2023-01-28T12:51:11.466899Z

you can repro this with:

bb -Sdeps '{:deps {borkdude/deps.clj {:mvn/version "1.11.1.1208"}}}' -m borkdude.deps -Sdeps-file uuuuxx
vs
bb -Sdeps '{:deps {borkdude/deps.clj {:mvn/version "1.11.1.1208"}}}' -m borkdude.deps -Sdeps-file /tmp

borkdude 2023-01-28T12:59:14.672019Z

I think the -Sdeps-file workaround can be entirely removed now though since we always override deps and paths

borkdude 2023-01-28T13:01:35.534669Z

hmm, that makes a test fail

borkdude 2023-01-28T13:18:48.509309Z

fixed it by using a file name that should not fail ;)

borkdude 2023-01-28T13:28:08.712159Z

merged

lispyclouds 2023-01-28T13:50:08.492099Z

yay! nice!

πŸŽ‰ 1
lispyclouds 2023-01-28T13:50:59.088329Z

checking out the "fixes" in deps

borkdude 2023-01-28T13:51:19.259429Z

it wasn't "fixed" there (the latest change)

lispyclouds 2023-01-28T13:51:29.316059Z

heh

borkdude 2023-01-28T13:51:38.996309Z

I just "fixed" it like this in bb:

"-Sdeps-file" "__babashka_no_deps_file__.edn"

lispyclouds 2023-01-28T13:51:57.368499Z

ah yeah

borkdude 2023-01-28T13:52:26.116719Z

__don_t_create_a_file_with_this_name_or_you_will_be_fired__

lispyclouds 2023-01-28T13:52:26.794529Z

well fun stuff. im happy we found new stuff and had more tests than we started

borkdude 2023-01-28T13:52:50.185059Z

yep, thanks

lispyclouds 2023-01-28T13:53:27.099189Z

definitely makes me more comfortable with the codebase now

borkdude 2023-01-24T09:22:04.411689Z

Hmm interesting issue. Might be solvable in deps.clj perhaps

borkdude 2023-01-24T09:22:38.994329Z

By changing the working dir of the java process

lispyclouds 2023-01-24T09:23:40.468179Z

i can take a stab at it hopefully soon

borkdude 2023-01-24T09:25:36.805549Z

Logging an issue would be a good first step

lispyclouds 2023-01-24T09:26:05.504419Z

i should do it in the bb repo right?

borkdude 2023-01-24T09:26:32.849059Z

I wonder how it interacts with the cache, I don’t think the working dir is reflected in there as the cache is simply a hash of deps.edn

borkdude 2023-01-24T09:26:37.481569Z

Yeah

borkdude 2023-01-24T09:26:58.641259Z

So that would be something to write down in the issue as well

lispyclouds 2023-01-24T10:32:56.302899Z

https://github.com/babashka/babashka/issues/1473

borkdude 2023-01-24T10:34:06.134569Z

deps.clj already has https://github.com/borkdude/deps.clj/blob/e9318a759628221c48b9259bc8885d4aee1d7262/src/borkdude/deps.clj#L41 so I think it would be just a matter or setting that to the correct dir

borkdude 2023-01-24T10:34:19.987919Z

small change probably

borkdude 2023-01-24T10:37:43.931749Z

instead of rewriting the paths after the fact here: https://github.com/babashka/babashka/blob/64dcb3335d6eb35bc8a59e36b5d6104ebd46e1fe/src/babashka/impl/deps.clj#L63 I think we can just bind the *dir* var to the deps-root directory and then it will work for both paths and local/roots

borkdude 2023-01-24T10:38:18.826499Z

o wait, no paths isn't shelling out to deps.clj, so let's not touch that part

borkdude 2023-01-24T10:39:06.277449Z

so use with-bindings + cond-> here and add *dir* when deps-root is there https://github.com/babashka/babashka/blob/64dcb3335d6eb35bc8a59e36b5d6104ebd46e1fe/src/babashka/impl/deps.clj#L93

lispyclouds 2023-01-24T10:46:03.396089Z

got it

lispyclouds 2023-01-24T10:47:35.917769Z

so would the user need to specify the deps-root as well here?

borkdude 2023-01-24T10:50:42.372589Z

the user?

borkdude 2023-01-24T10:50:58.622309Z

no, deps-root is set to --config by default, unless the user sets it otherwise

lispyclouds 2023-01-24T10:51:57.488359Z

got it. yeah i meant should i need to explicitly specify --deps-root

borkdude 2023-01-24T10:52:34.306259Z

no, just use the :deps-root like it's used in the paths handling

πŸ‘πŸΎ 1
lispyclouds 2023-01-27T14:13:55.698689Z

https://github.com/babashka/babashka/pull/1478

lispyclouds 2023-01-27T14:27:58.316309Z

looking into the tests

borkdude 2023-01-27T14:54:56.175809Z

you can run the tests locally before you push with lein do clean, test

borkdude 2023-01-27T14:55:06.462039Z

also you can write a test locally before you push :)

borkdude 2023-01-27T14:55:17.515609Z

you can pull the :deps-root into a let binding maybe

borkdude 2023-01-27T14:59:33.540609Z

I think the problem might be that you need to bind it to an absolutized path

borkdude 2023-01-27T14:59:45.055779Z

or something

lispyclouds 2023-01-27T15:02:55.822539Z

good points, will get back to it soon. now my local stuff is working fine, should be better πŸ˜„

borkdude 2023-01-27T15:03:32.674579Z

I'll take a look at a fix in deps.clj right now

πŸ‘πŸΎ 1
borkdude 2023-01-27T15:16:49.556519Z

I hope absolutizing both files is a good solution

user=> (binding [deps/*exit-fn* identity deps/*dir* ".."] (deps/-main "-M" "-e" "(System/getProperty (str 'user.dir))"))
"/Users/borkdude/dev"
nil
user=> (binding [deps/*exit-fn* identity deps/*dir* "../.."] (deps/-main "-M" "-e" "(System/getProperty (str 'user.dir))"))
"/Users/borkdude"

borkdude 2023-01-27T15:19:32.595849Z

I can think of one other edge case: in Windows when you invoke the script from another disk drive

borkdude 2023-01-27T15:19:36.340959Z

let me also test this...

borkdude 2023-01-27T15:23:27.157209Z

yep, this should work:

user=> (binding [deps/*dir* "/C:/foo"] (deps/relativize "/D:/foo/bar"))
#object[sun.nio.fs.UnixPath 0x1d23ff23 "../../D:/foo/bar"]

borkdude 2023-01-27T15:23:48.892729Z

I'm copying half of babashka.fs in there...

borkdude 2023-01-27T15:26:00.847189Z

ok pushed a commit to deps.clj which should help

lispyclouds 2023-01-27T15:27:18.781699Z

right, will pull in the changes

lispyclouds 2023-01-27T15:32:14.355349Z

tests pass, pushed

borkdude 2023-01-27T16:41:20.596319Z

β€’ [ ] test β€’ [ ] changelogs

lispyclouds 2023-01-27T17:53:43.949889Z

i was using the test-utils/bb for a test like:

(testing "relative paths in :deps are relative to bb.edn"
  (test-utils/with-config '{:deps {babashka/process {:local/root "./process"}}}
    (is (= (str (fs/cwd) "/process/src")
           (first
             (bb "-e" "(do (require '[babashka.classpath :as cp])
                        (cp/split-classpath (cp/get-classpath)))"))))))
but the test utils passes a --deps-root as . in https://github.com/babashka/babashka/blob/master/test/babashka/test_utils.clj#L52 is this test okay as it resolves to the root of the bb repo and not the location of the bb.edn or a different util method without the --deps-root is to be used?

lispyclouds 2023-01-27T17:55:02.396269Z

or i guess there is a better testing suggestion in general? πŸ˜…

lispyclouds 2023-01-27T18:17:24.134049Z

also not sure if that (str (fs/cwd) "/process/src") works as expected on windows

borkdude 2023-01-27T18:46:07.499309Z

this doesn't change the deps-root right, so how does this test the change that the test is for?

borkdude 2023-01-27T18:47:15.974509Z

I'd look for a test that tests the deps-root feature and add another test like that but with a local/root the refers to a relative dir

πŸ‘πŸΎ 1
lispyclouds 2023-01-27T20:26:03.679399Z

cant seem to find a test for deps-root, the only mentions of it in context of tests i can see are: β€’ https://github.com/babashka/babashka/blob/master/test/babashka/test_utils.clj#L52 β€’ https://github.com/babashka/babashka/blob/master/test/babashka/test_utils.clj#L92 any pointers of where could i find it? i thought https://github.com/babashka/babashka/blob/master/test/babashka/bb_edn_test.clj could have it

borkdude 2023-01-27T20:56:34.737789Z

I guess you're right

borkdude 2023-01-27T20:56:54.179539Z

there is no test 😨

lispyclouds 2023-01-27T20:57:10.786399Z

well, adding that too 😎