Fork me on GitHub
#tools-deps
<
2021-04-13
>
golanweiss11:04:49

I’m moving from a lein project to tools deps.edn and unfortunately I had some “injections” in my project.clj Is there a way to “inject” (i.e. require) some namespace when using the https://github.com/cognitect-labs/test-runner?

borkdude12:04:41

@golan1w you can use -e "(require 'foo.bar)" -m "test-runner.main"

🙏 3
golanweiss12:04:36

thanks, The problem is that when using multiple aliases only the last main-opts in is kept. So I don’t see how can I add this to my deps.edn to be permanent. For example a good place for such thing would have been under alias called :my-lib-test

borkdude12:04:39

create a new alias with other main opts?

golanweiss13:04:27

yeah but then I can’t use my :runner alias for all tests.

:runner {:extra-deps ...
         :main-opts  ["-m" "cognitect.test-runner"]}
and I’ll need to create a different alias for each library that needs this “injection”. This will also be a bit more complicated because I’m also building the CI integration and trying to have some code re-use. Eventually I forkedhttps://github.com/localizedev/test-runner and added support as another command line argument…

pinkfrog13:04:23

I don’t understand why deps.edn doesn’t allow to dynamically evaluate some clj expression. This quite limits the flexibility of deps.

Alex Miller (Clojure team)13:04:59

isn't that what -M -e does?

Alex Miller (Clojure team)13:04:06

if not, what do you mean?

pinkfrog13:04:54

I’ve a deps.edn file, I want to set the :mvn/local-repo to be :mvn/local-repo=$SOMEPATH, where $SOMEPATH is an environment variable

borkdude13:04:17

not possible without scripting

pinkfrog13:04:34

Any scripting example on this subject?

pinkfrog13:04:33

I can do things like reading a template file and output a deps.edn. Just found it is a little bit unnecessary as deps doesn’t support these functionalities.

borkdude13:04:46

Can you accomplish this with -Sdeps perhaps?

pinkfrog14:04:39

Eh.. A little bit complicated.

pinkfrog14:04:52

Use

@npx shadow-cljs watch mobile
shadow will invoke clojure

pinkfrog14:04:57

no way to pass in -Sdeps

borkdude13:04:53

maybe possible with -Sdeps

Alex Miller (Clojure team)13:04:36

can you do it with stdin?

Alex Miller (Clojure team)13:04:23

oh sorry, you're talking about in deps.edn

Alex Miller (Clojure team)13:04:51

you can pass that particular case on the command line with -Sdeps

pinkfrog14:04:05

I think I might hack the PATH and use a wrapped verison of clj which automatically adds -Sdeps.

Ronny Løvtangen14:04:59

Anyone knows if it is possible to add -e "(require 'sc.api)" to IntelliJ’s Run Configuration?

golanweiss15:04:33

can’t you add it in an additional alias?

Ronny Løvtangen16:04:53

Ideally, I would follow scope-capture’s recommendation and keep it outside the project. (https://github.com/vvvvalvalval/scope-capture) But if that’s not possible, I could add an alias. I tried to add it to my server alias, which already has a :main-opts :

:main-opts ["-m" "dvp.clj.server"]
Tried with
:main-opts ["-m" "dvp.clj.server" "-e" "(require 'sc.api)"]
but to no success. But IntelliJ won’t even start the main function with my current alias, so maybe I need to figure out that first.

Ronny Løvtangen06:04:57

Is the syntax correct, btw?

golanweiss15:04:09

It seems clojure -Spom doesn’t add :local/root dependencies to the final pom.xml file. Does anyone knows if this is a known issue?

delaguardo15:04:56

does maven supports arbitrary path as a dependency?

delaguardo15:04:36

the same happens with git-based dependencies

golanweiss20:04:13

I see now.. The behavior I was expecting is to go into the path of the :local/root and check if there’s a pom.xml file and use its version. maybe a feature request? 🙂

seancorfield20:04:55

I’m not sure how that even makes sense? :local/root and :git/url are source-only dependencies that don’t fit Maven’s group/artifact/version world — and pom.xml doesn’t contain any information about transitive dependencies anyway.

golanweiss20:04:40

indeed, my usage is wrong. actually this behavior makes sense. this is not a Spom problem.

Alex Miller (Clojure team)15:04:55

there is no way to do so?

pinkfrog15:04:51

How to tell deps to ignore the deps.edn file?

borkdude15:04:32

You can't. deps.clj (unofficial) does support this: https://github.com/borkdude/deps.clj.

Alex Miller (Clojure team)16:04:45

why do you want to ignore it?

pinkfrog16:04:49

A temporary fix would be -Sdeps {:deps nil}. I will use it for now.

borkdude16:04:31

This still won't ignore your local deps.edn, it will just merge it

borkdude16:04:54

if you have babashka installed, you can invoke it with bb clojure -Sdeps-file=other.edn

pinkfrog16:04:57

bb looks promising

pinkfrog12:04:15

I finally go with bb to preprocess the deps.edn file. Blazingly fast.

pinkfrog16:04:12

I am writing a simple script to transform a deps.edn file, basically add some entries.

pinkfrog16:04:35

#!/bin/sh
#_stub ; -*- mode: clojure; -*-

#_(
   DEPS='
       {:mvn/local-repo "", :deps {}}
   '
   exec clojure -Sdeps "$DEPS" -M "$0" "$@"

   stub)


(require '[clojure.edn :as edn])

(def deps (edn/read-string (slurp "deps.edn")))

(def newdeps (assoc deps :mvn/local-repo "../../.m2"))

(spit "deps.edn" (pr-str newdeps))

Alex Miller (Clojure team)16:04:07

I don't see why that requires you to ignore the deps.edn

pinkfrog16:04:03

because this script doesn’t need to install the dependencies from deps.edn

Alex Miller (Clojure team)16:04:56

I think you'd really want something wonkier like clj -Sdeps '{:aliases {:TMP {:replace-deps {} :replace-paths []}}}' -A:TMP

pinkfrog16:04:16

You are right.

golanweiss20:04:13

I see now.. The behavior I was expecting is to go into the path of the :local/root and check if there’s a pom.xml file and use its version. maybe a feature request? 🙂