Fork me on GitHub
#clojure
<
2021-06-22
>
tengstrand05:06:31

What’s the best way of reading a Clojure source code file (.clj) from disk so that you also get the metadata back?

dpsutton05:06:14

i think i know what you're talking about. have it on the classpath and require it. this lets source, doc, and line numbers work correctly. if it just sends all the forms through the repl you won't have all those goodies

seancorfield06:06:27

Yeah, you pretty much have to execute it (`require`) so that the Vars get all the correctly computed metadata…

tengstrand07:06:41

Okay, thanks!

borkdude09:06:14

@tengstrand if you're not interested in evaluated metadata, then you could just use the reader and no eval

borkdude09:06:37

if you're interested in preserving more information, you could also look at rewrite-clj

tengstrand09:06:53

Okay, thanks for the tip! I need to read an external .clj file and get metadata, like clojure doc strings, back. I guess that library will solve that. I will have a look.

borkdude09:06:59

In this case you can also use clj-kondo

👍 3
borkdude09:06:18

@tengstrand Example:

$ clojure -M:clj-kondo/dev --lint src/babashka/main.clj --config '{:output {:format :edn :analysis true}}' > /tmp/analysis.edn
$ cat /tmp/analysis.edn | jet --pretty --func '(fn [json] (->> json :analysis :var-definitions (filter :doc) (map (juxt :ns :name :doc))))'
([babashka.main
  musl?
  "Captured at compile time, to know if we are running inside a\n  statically compiled executable with musl."])

borkdude09:06:39

(so here it finds only one var with a docstring in the babashka/main.clj file)

borkdude09:06:55

if you have any questions about how to use this, let me know

tengstrand09:06:26

Sure, will have a look at it later. Thanks.

Alys Brooks13:06:00

I'm writing a blog post that touches on how tools like the Clojure CLI and leiningen work and have been looking at some early Clojure documentation to figure out what people did before those tools existed. It looks like you could run a script using java -cp clojure.jar clojure.lang.Script script.clj (this is officially deprecated, but still works as of Clojure 1.10.2). Was this the common approach? I assume people also started applications from the REPL? Leiningen and the first stable release of Clojure came out the same year (2009), so my guess is that people weren't using many dependencies pre-Leiningen.

lukasz13:06:05

I remember using ant back in.... 2010 or 2011? I believe that was the "official" way of managing a clojure project, but how you obtained the dependencies was up to you - mostly by downloading jars and figuring out the classpath

borkdude14:06:26

The common approach is clojure -M foo.clj

Alys Brooks14:06:26

Yeah, looking at some early commits to Compojure, it suggests using ant to install the dependencies: https://github.com/weavejester/compojure/tree/0.3

Alex Miller (Clojure team)14:06:36

I used (and all the contrib libs still use) the clojure-maven-plugin with Maven

Ed16:06:10

I used maven as a build tool / test runner, swank to connect to a repl and some custom shell scripts for some more specialised jobs. It worked great for years, and I didn't actually migrate to lein till something like 2015. I was working at a startup and switching build tools just never got to the top of our priority list. But I came from a java background and was already comfortable with mvn.

Ed16:06:22

We would generally aot the things we wanted to run, and java -jar path-to-uber.jar

hiredman17:06:44

I used a Makefile, but I don't entirely recall the details

Alys Brooks02:06:51

Thank you for all the responses!

The Continium18:06:05

Hi - I have a long running Clojure process running on JVM Java 1.8 and the non heap memory is growing linearly. Has anyone any experience of this and/or methods of finding the culprit ?

ghadi18:06:31

question is about non-heap, not heap

ghadi18:06:54

check for direct buffers being allocated

☝️ 2
ghadi18:06:07

also, how are you determining that non-heap is growing?

hiredman18:06:42

you can use visualvm or https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getAllStackTraces() to get a count of the active threads, the stack of each counts as non-heap memory

The Continium19:06:53

Thanks for the quick replies. https://metrics-clojure.readthedocs.io/en/latest/jvm.html is being used to monitor the memory.

Evgeniy20:06:11

Does anyone here have some experience integrating Okta into a Clojure web-app? Did you use any libraries or wrote your own stuff?

walterl22:06:10

Can't claim much experience, but there's this: https://github.com/metabase/saml20-clj

Greg Reichow22:06:17

Working to deploy our first Datomic Ion based application. It is a continuously running process that ingests information, processes, and stores in Datomic. My understanding is that ion's are typically called via AWS Lambda's on some event. Yet in this case I just want to deploy the application and have it start running (and stay running). (ie. call the run function which runs and sleeps on a 30 min cycle). Tips on the best way to achieve this? Do I need to make a Lambda initial trigger or is there a way to have it launch and run automatically / continuously?

3
seancorfield23:06:58

@U025VPS4R7U If you haven’t already, you might have more chance of an answer in either #datomic or #ions-aws I suspect

seancorfield23:06:38

Also, I believe Cognitect/Nubank do most of their actual support via https://forum.datomic.com/

Greg Reichow23:06:46

Great, thanks for the suggestion! I missed finding those channels when I searched earlier.

Greg Reichow04:06:34

For any others that have this question, ended up using CloudWatch time based triggers to kickoff running the lambda every 30min instead of controlling the timing from within the application.

👍 2