tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
golanweiss 2021-04-13T11:47:49.482400Z

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?

borkdude 2021-04-13T12:09:41.483200Z

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

🙏 1
golanweiss 2021-04-13T12:35:36.483400Z

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

borkdude 2021-04-13T12:37:39.483700Z

create a new alias with other main opts?

golanweiss 2021-04-13T13:34:27.483900Z

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…

2021-04-13T13:35:23.485Z

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

alexmiller 2021-04-13T13:35:59.485200Z

isn't that what -M -e does?

alexmiller 2021-04-13T13:36:06.485400Z

if not, what do you mean?

2021-04-13T13:38:54.486200Z

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

borkdude 2021-04-13T13:51:17.486400Z

not possible without scripting

borkdude 2021-04-13T13:51:53.486600Z

maybe possible with -Sdeps

2021-04-13T13:53:34.486700Z

Any scripting example on this subject?

2021-04-13T13:56:33.486900Z

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.

borkdude 2021-04-13T13:57:46.487100Z

Can you accomplish this with -Sdeps perhaps?

alexmiller 2021-04-13T13:58:36.487500Z

can you do it with stdin?

alexmiller 2021-04-13T13:59:23.487900Z

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

alexmiller 2021-04-13T13:59:51.488400Z

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

2021-04-13T14:02:05.489700Z

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

2021-04-13T14:16:39.490Z

Eh.. A little bit complicated.

2021-04-13T14:16:52.490200Z

Use

@npx shadow-cljs watch mobile
shadow will invoke clojure

2021-04-13T14:16:57.490400Z

no way to pass in -Sdeps

2021-04-13T14:53:59.491800Z

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

2021-04-16T06:33:57.007500Z

Is the syntax correct, btw?

golanweiss 2021-04-18T13:01:27.013600Z

I think “-e” should come before. Check out https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn

2021-04-18T17:21:17.015600Z

Thanks 👍

golanweiss 2021-04-13T15:25:33.492100Z

can’t you add it in an additional alias?

golanweiss 2021-04-13T15:53:09.493600Z

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?

alexmiller 2021-04-13T15:55:55.493900Z

there is no way to do so?

2021-04-13T15:55:56.494Z

does maven supports arbitrary path as a dependency?

2021-04-13T15:56:36.494200Z

the same happens with git-based dependencies

2021-04-13T15:58:51.494700Z

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

borkdude 2021-04-13T15:59:32.495200Z

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

alexmiller 2021-04-13T16:00:45.496400Z

why do you want to ignore it?

2021-04-13T16:00:49.496800Z

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

borkdude 2021-04-13T16:00:54.497200Z

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

2021-04-14T12:02:15.000500Z

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

2021-04-13T16:01:12.497600Z

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

2021-04-13T16:01:35.497700Z

#!/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))

2021-04-13T16:01:57.497900Z

bb looks promising

borkdude 2021-04-13T16:02:31.498100Z

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

alexmiller 2021-04-13T16:03:07.498300Z

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

2021-04-13T16:04:03.498500Z

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

alexmiller 2021-04-13T16:05:56.498700Z

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

2021-04-13T16:45:16.498900Z

You are right.

2021-04-13T16:51:53.499100Z

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.

seancorfield 2021-04-13T20:16:55.000100Z

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.

golanweiss 2021-04-13T20:27:40.000300Z

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