clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
suren 2021-05-09T00:39:06.222900Z

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)

seancorfield 2021-05-09T00:52:24.223600Z

@suren You are missing -m

seancorfield 2021-05-09T00:53:24.224600Z

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

suren 2021-05-09T00:58:02.225300Z

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

seancorfield 2021-05-09T00:58:42.225900Z

-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”

seancorfield 2021-05-09T00:59:25.226800Z

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

suren 2021-05-09T01:01:02.227100Z

Yep weird.

suren 2021-05-09T01:03:23.227800Z

I have logged an issue in the repo.

seancorfield 2021-05-09T01:03:26.227900Z

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

suren 2021-05-09T01:05:14.228700Z

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?

suren 2021-05-09T01:06:01.229500Z

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

seancorfield 2021-05-09T01:07:22.230Z

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

seancorfield 2021-05-09T01:07:45.230400Z

@suren You are using depstar to build the JAR?

suren 2021-05-09T01:08:36.230500Z

Yep I can confirm it works. Thanks.

suren 2021-05-09T01:09:23.230700Z

Checking it out. Thanks @seancorfield

seancorfield 2021-05-09T01:09:26.230900Z

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

seancorfield 2021-05-09T01:10:22.231100Z

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

seancorfield 2021-05-09T01:10:47.231300Z

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

seancorfield 2021-05-09T01:11:33.231500Z

(! 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 "<https://github.com/cognitect-labs/test-runner>"
                 :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"}}}}

seancorfield 2021-05-09T01:12:17.231700Z

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

2021-05-09T01:15:18.232300Z

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

suren 2021-05-09T01:24:01.232400Z

I have submitted the PR.

1
2021-05-09T02:29:18.238200Z

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.

seancorfield 2021-05-09T02:35:51.239100Z

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

2021-05-09T11:52:26.252100Z

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?

seancorfield 2021-05-09T16:33:24.254800Z

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.

seancorfield 2021-05-09T02:38:20.239700Z

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

2021-05-09T02:44:25.240400Z

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?

suren 2021-05-09T03:16:37.241300Z

It worked thanks @seancorfield

λmmij 2021-05-09T03:31:39.241600Z

(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}

λmmij 2021-05-09T03:32:16.242300Z

Is that normal behavior for the last zipmap?

λmmij 2021-05-09T03:32:30.242600Z

Just curious.

λmmij 2021-05-09T03:41:42.243600Z

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

seancorfield 2021-05-09T04:09:14.243700Z

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.

seancorfield 2021-05-09T04:10:25.243900Z

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).

anonimitoraf 2021-05-09T04:50:33.244100Z

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

2021-05-09T04:58:42.244400Z

Yup. That’s only that far.

2021-05-09T05:13:49.245300Z

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?

2021-05-09T08:35:22.246300Z

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

p-himik 2021-05-09T08:36:21.246500Z

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

p-himik 2021-05-09T08:36:42.246700Z

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

2021-05-09T08:39:36.246900Z

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

p-himik 2021-05-09T08:40:51.247100Z

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

p-himik 2021-05-09T06:34:28.245400Z

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.

2021-05-09T06:48:07.245600Z

doesn’t solve though.

p-himik 2021-05-09T06:50:10.245800Z

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

p-himik 2021-05-09T06:55:28.246Z

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.

2021-05-09T10:42:37.248300Z

How can I run test-runner in a repl?

2021-05-09T10:42:52.248600Z

Currently, it directly terminates the system after finishing: https://github.com/cognitect-labs/test-runner/blob/6323e6b09e086e1b98682c4bcf6ef9702254b285/src/cognitect/test_runner/api.clj#L30

borkdude 2021-05-09T10:48:46.249700Z

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.

borkdude 2021-05-09T10:50:04.250300Z

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

2021-05-09T10:54:59.250600Z

Yes. I am now directly using this function: test

2021-05-09T10:56:25.251600Z

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.

alexmiller 2021-05-09T13:49:20.252900Z

Sorry, that was debugging left in accidentally, will remove

alexmiller 2021-05-09T14:10:07.254600Z

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

alexmiller 2021-05-09T17:56:06.255200Z

removed, released 0.2.1 version, see readme for sha etc