Fork me on GitHub
#clojure
<
2021-05-09
>
suren00:05:06

Hi guys, I am trying to use cljfmt. When I execute

clojure -Sdeps '{:deps {cljfmt/cljfmt {:mvn/version "0.6.4"}}}' -M cljfmt.main fix
I get following error
Exception in thread "main" java.io.FileNotFoundException: cljfmt.main (No such file or directory)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:153)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:108)
	at clojure.lang.Compiler.loadFile(Compiler.java:7449)
	at clojure.main$load_script.invokeStatic(main.clj:278)
	at clojure.main$script_opt.invokeStatic(main.clj:338)
	at clojure.main$script_opt.invoke(main.clj:333)
	at clojure.main$main.invokeStatic(main.clj:424)
	at clojure.main$main.doInvoke(main.clj:387)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:702)
	at clojure.main.main(main.java:37)
make: [format] Error 1 (ignored)

seancorfield00:05:24

@suren You are missing -m

seancorfield00:05:24

The README for cljfmt says:

clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.6.4"}}}' \
  -m cljfmt.main check \
  --indents indentation.clj
which is “old” and you’ll get a warning about using -M but the warning means in addition or instead of -A so you need:
clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.6.4"}}}' \
  -M -m cljfmt.main check \
  --indents indentation.clj

suren00:05:02

Turns out check works but fix does not work. I got following error

clojure -Sdeps '{:deps {cljfmt {:mvn/version "0.6.4"}}}' \
		-m cljfmt.main fix
WARNING: When invoking clojure.main, use -M
No such file: project.clj

seancorfield00:05:42

-M is an option for the clojure script that says “run clojure.main“, -m is an option for clojure.main that says “run this namespace’s -main function”

seancorfield00:05:25

That error sounds like cljfmt only works with Leiningen projects? Weird since it gives the CLI example — albeit for check.

suren01:05:02

Yep weird.

suren01:05:23

I have logged an issue in the repo.

seancorfield01:05:26

Hmm, it shouldn’t be looking for project.clj if it doesn’t exist, according to the code.

suren01:05:14

Do you happen to know any way to install deps.edn based package locally so that I can import it in another project using lein?

suren01:05:01

Lein based project can be install locally installed through lein pom; lein jar; lein install I was hoping we have something similar for deps.edn

seancorfield01:05:22

@suren 0.6.4 is an old version. I tried 0.7.0 and it works without that error.

suren01:05:36

Yep I can confirm it works. Thanks.

seancorfield01:05:26

I added a comment to your issue. James will update the README I expect.

suren01:05:01

I have submitted the PR.

3
seancorfield01:05:45

@suren You are using depstar to build the JAR?

suren01:05:23

Checking it out. Thanks @U04V70XH6

seancorfield01:05:22

depstar’s readme talks about deps-deploy which has both :remote and :local options for :installer.

seancorfield01:05:47

If you had created your project initially using clj-new, the generated deps.edn would already have all these tools in place.

seancorfield01:05:33

(! 1435)-> clojure -X:new :template lib :name suren/example
Generating a project called example based on the 'lib' template.
The lib template is intended for library projects, not applications.
(! 1436)-> cat example/deps.edn 
{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}}
 :aliases
 {:test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}
  :runner
  {:extra-deps {com.cognitect/test-runner
                {:git/url ""
                 :sha "b6b3193fcc42659d7e46ecd1884a228993441182"}}
   :main-opts ["-m" "cognitect.test-runner"
               "-d" "test"]}
  :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.211"}}
        :exec-fn hf.depstar/jar
        :exec-args {:jar "example.jar" :sync-pom true}}
  :install {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
            :exec-fn deps-deploy.deps-deploy/deploy
            :exec-args {:installer :local :artifact "example.jar"}}
  :deploy {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}}
           :exec-fn deps-deploy.deps-deploy/deploy
           :exec-args {:installer :remote :artifact "example.jar"}}}}

seancorfield01:05:17

It also has a fully-populated pom.xml file which I think you will need for deploying locally anyway.

suren03:05:37

It worked thanks @U04V70XH6

dvingo01:05:18

can I have one git repo that deploys multiple maven artifacts by using separate pom.xml files?

andy.fingerhut02:05:18

git repos are just a tree of directories containing files, with no restrictions on the directory structure. You could easily have multiple "projects" inside of that git repo with pom.xml files in as many or few (or none) of those directories as you wish.

seancorfield02:05:51

@danvingo At work we have a "monorepo" that produces 14 different artifacts, from just over 40 subprojects.

dvingo11:05:26

ah I see - yea subdirectories would work - I currently have one directly of code - so to produce multiple artifacts I'd have to have multiple subdirectories, each with it's own pom.xml file?

seancorfield16:05:24

I’ve posted about our monorepo setup a couple of times recently at https://corfield.org/ and the Polylith book talks about this too but, yes, the core concept is having a subproject for each artifact you want to produce so you can control the “environment” needed for those artifacts, separate from each other.

seancorfield02:05:20

You might also be interested in Polylith as a way to organize a repo that produces multiple artifacts: https://polylith.gitbook.io/

pinkfrog02:05:25

Suppose I am in namespace a, I would like to know the aboslute path of that name space, e.g., /share/local/clojure/a.clj, how to know that?

seancorfield04:05:14

A namespace a.b corresponds to one of a/b.clj, a/b.cljc, or a/b.cljs relative to a directory on the classpath -- so you'd have to search for a matching file the same what Clojure does.

seancorfield04:05:25

If you have a Var, you can do (:file (meta #'some-var)) and you will at least get the relative filename (so you won't have to do the .clj/`.cljc`/`.cljs` dance, but you'll still have search the classpath).

pinkfrog04:05:42

Yup. That’s only that far.

λmmij03:05:39

(zipmap [:a :b :c :d :e] (range)) => {:a 0, :b 1, :c 2, :d 3, :e 4} (zipmap (range) [:a :b :c :d :e]) => {0 :a, 1 :b, 2 :c, 3 :d, 4 :e} (zipmap [:a :b :c :d :e] (repeat 1)) => {:a 1, :b 1, :c 1, :d 1, :e 1} (zipmap (repeat 1) [:a :b :c :d :e]) => {1 :e}

λmmij03:05:16

Is that normal behavior for the last zipmap?

λmmij03:05:30

Just curious.

λmmij03:05:42

I just realize this is a silly question. Nevermind. I already get it.

anonimitoraf04:05:33

Haha took me a while to realize too. It's because of duplicated keys (i.e. 1)

pinkfrog05:05:49

Pressing ctrl-d won’t quit the rebel repl. Not sure if its’ something related to agent not being shutdown or whatever. How to debug this?

p-himik06:05:28

If calling (shutdown-agents) before that solves the problem, then it's probably that. :) If you want to find what thread exactly does that, probably dumping threads can help.

pinkfrog06:05:07

doesn’t solve though.

p-himik06:05:10

When you press Ctrl+d, what exactly does it do?

p-himik06:05:28

If nothing happens and it keeps responding to input, then it just doesn't handle or doesn't receive Ctrl+d. If it stops responding, then there are probably other threads that prevent the shutdown that have nothing to do with Clojure agents. A thread dump would still help. Also, I just tried running rebel without anything else. On my end Ctrl+d worked just fine. If you're trying it within some project or if you have something rebel-related in your ~/.clojure/deps.edn, maybe it affects rebel so that it behaves the way you see.

pinkfrog08:05:22

Thanks. For thread-dump, how to perform that?

p-himik08:05:21

Dunno, I'd have to look it up myself.

p-himik08:05:42

But it has nothing to do with Clojure - it's just a JVM thread dump.

pinkfrog08:05:36

The phenomenon is after pressing Ctrl-D, after some minutes, the process will eventually quit.

p-himik08:05:51

That doesn't really add any useful information. Just do a thread dump after hitting Ctrl+d and see what it has.

Alex Miller (Clojure team)13:05:20

Sorry, that was debugging left in accidentally, will remove

Alex Miller (Clojure team)17:05:06

removed, released 0.2.1 version, see readme for sha etc

pinkfrog10:05:37

How can I run test-runner in a repl?

borkdude10:05:46

The way I do this in babashka is if there is an ex-info with an :exit value, I exit the process with that exit code, if nobody else caught the exception. This still allows you to use those functions in the REPL without losing the REPL.

borkdude10:05:04

I guess you can just use the cognitect.test-runner ns from the REPL or use clojure.test directly

pinkfrog10:05:59

Yes. I am now directly using this function: test

pinkfrog10:05:25

I find the user.clj namespace a little bit weird. If I do a

(:refer-clojure :exclude [test])
in (ns user). The test symbol still got included.

Alex Miller (Clojure team)14:05:07

user is loaded by Clojure very early in the runtime. I’m not sure if you even have the opportunity to do refer-clojure that way there