clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
seancorfield 2021-03-31T00:06:52.135800Z

So… you’d either want a way to specify additional items for the compilation classpath, or a way to exclude JAR files (currently the regex-based exclude operates only at the file level, not on the JAR or its contents)…

seancorfield 2021-03-31T00:07:26.136300Z

Open an issue on the depstar GH and I’ll have a think about it…

🙌 1
agentfunk 2021-03-31T00:08:07.136900Z

@seancorfield will do. Thanks for the great tool and your answer.

seancorfield 2021-03-31T00:11:42.139100Z

I suspect a reasonable way to approach it is to provide an option to specify :compile-aliases so you can tell depstar to calculate a different basis for AOT compilation than for the JAR building part. Then you could have a :storm alias that adds that JAR via :extra-deps (and you’d have to use it for developing with). But “additive” is better.

agentfunk 2021-03-31T14:54:58.148600Z

works perfectly!

agentfunk 2021-03-31T14:55:19.148800Z

thank you so much

agentfunk 2021-03-31T15:07:20.149Z

I haven't figured out how to make cursive resolve linter dependencies from aliases. But that's ok for storm since it can't resolve a lot of things from storm.

seancorfield 2021-03-31T16:47:37.150100Z

I released it as com.github.seancorfield/depstar {:mvn/version "2.0.211"}.

🚀 1
seancorfield 2021-03-31T01:37:14.139600Z

My suggestion was: add a :storm alias that has just that storm-client dependency — and remove it from your “normal” list of dependencies. Then you use that alias (along with whatever you normally use) for dev/test — and if I add a :compile-aliases option you would also pass it to that, since it’s needed for the compile part but not the main JAR-build part.

seancorfield 2021-03-31T01:40:43.139800Z

At work, we have a somewhat similar situation where we have a process that needs the standard root-level :deps alias (as in tools.deps.alpha) for a couple of actions but we don’t want it in the JAR version of that process, so we just specify -M:deps:other:aliases when we run those particular actions and -M:other:aliases when we run other stuff or build the JAR. That code doesn’t need it statically for compilation, only dynamically to run certain actions. Hence, I haven’t needed the :compile-aliases option at work yet.

seancorfield 2021-03-31T01:40:50.140Z

Does that help @sammerat?

seancorfield 2021-03-31T01:41:37.140200Z

And to be clear :compile-aliases would be a new exec arg that you pass to depstar — a variant of the existing :aliases exec arg.

agentfunk 2021-03-31T01:49:35.140400Z

@seancorfield yeah that would work great

seancorfield 2021-03-31T02:04:21.140600Z

https://github.com/seancorfield/depstar/issues/75

seancorfield 2021-03-31T02:56:18.140900Z

@sammerat A first cut of the implementation can be tested via

seancorfield/depstar {:git/url "<https://github.com/seancorfield/depstar>" :sha "39d234b9bce94ff8f51e0660f9db8bf475618e23"}
Needs tests and documentation but I figured you might be able to take it for a spin and let me know it works for you? (edited to update the SHA)

agentfunk 2021-03-31T03:02:17.141600Z

@seancorfield thank you so much. I’ll report back tomorrow morning

seancorfield 2021-03-31T04:47:30.142100Z

@sammerat FYI -- once I added tests, I found a bug, so I updated the SHA above to reflect the correction.

🙌 1
onetom 2021-03-31T06:38:26.143900Z

Does anyone know about a generic OAuth client, which supports the PKCE flow (as defined in https://tools.ietf.org/html/rfc7636)? I'm not even sure what should I use as a generic OAuth client...

onetom 2021-03-31T06:51:54.147100Z

I forgot to search clojars. There are a few libs there which have oauth in their name. I've also looked into specifically Xero API related libs and I found that the https://bitbucket.org/icm-consulting/clj-xero/src/develop/ project for example is using the https://github.com/eraf2135/clj-oauth fork of https://github.com/mattrepl/clj-oauth Then there is https://github.com/r0man/oauth-clj from the prolific r0man or https://clojars.org/oauth/oauth.two from the very official-sounding oauth clojars org. So my question more precisely is: which one of these libraries have you used and what was your experience like?

emccue 2021-03-31T13:33:44.148300Z

@onetom Sometimes I feel like the only clojure dev that uses https://github.com/spring-projects/spring-security

👍 1
onetom 2021-04-02T14:19:37.219600Z

thanks for the extensive discussion!

onetom 2021-03-31T16:01:07.149500Z

thx for the link. i will probably use it to see how they named certain things, but i definitely won't unleash such a monstrous class hierarchy on my colleagues. imean, we are using clojure to avoid things like: OAuth2AccessTokenResponseHttpMessageConverter.setTokenResponseConverter() (i've found this on https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2client)

onetom 2021-03-31T16:08:43.149700Z

we have a ~200 LoC implementation, using http-kit, clojure.data.json and a hint of buddy-core for the sake of convenience. it's not super generic and some of the names are a bit quirky, but it's rather straightforward...

mjw 2021-03-31T17:36:30.150300Z

I have not even considered that Spring Security could be used effectively from Clojure :thinking_face:

emccue 2021-03-31T18:28:35.150600Z

@matt.wistrand Yeah, the one thing I use it for consistently is DelegatingPasswordEncoder

👍 1
vemv 2021-03-31T19:22:42.151200Z

is there a compelling reason to use Sping Sec? leaving aside its provenance, depending on a monolithic (?) solution doesn't seem very aligned with clojure ideals.

aengelberg 2021-03-31T20:30:09.152600Z

Is there a way to profile namespace loading in Clojure and figure out which namespaces are taking the longest to load? I have a test suite that takes a minute or two just to load all the requisite namespaces before the assertions start happening, and am curious where that time is going and what code / dependencies I should try to get rid of.

2021-03-31T20:31:31.153Z

the ones with the macros

1
2021-03-31T20:33:21.153400Z

what version of clojure?

2021-03-31T20:33:28.153700Z

this quick and dirty might be good enough

(cmd)user=&gt; (alter-var-root #'require #(fn [&amp; args] (println "require" args) (time (apply % args))))
#object[user$eval3$fn__4$fn__140 0x320494b6 "user$eval3$fn__4$fn__140@320494b6"]
(cmd)user=&gt; (require 'clojure.set)
require (clojure.set)
"Elapsed time: 4.618158 msecs"
nil
(ins)user=&gt; (require 'clojure.string)
require (clojure.string)
"Elapsed time: 0.074134 msecs"
nil

aengelberg 2021-03-31T20:33:44.153800Z

1.10.1

2021-03-31T20:34:02.154Z

ah

dpsutton 2021-03-31T20:34:35.154400Z

isn't there a dynamic var that does essentially that?

2021-03-31T20:34:45.154500Z

somewhere around 1.10 there was a change to how user.clj is loaded, where loading code from user.clj could take a long time

2021-03-31T20:34:58.154700Z

(the change fixed it)

2021-03-31T20:35:18.154900Z

basically if you had a user.clj, and it loaded any core.async code it could take minutes

aengelberg 2021-03-31T20:35:23.155100Z

ah

2021-03-31T20:36:04.155800Z

IIRC there's a dynamic var to make it verbose, I didn't recall it printing timings and I am failing to recall the name

borkdude 2021-03-31T20:36:29.156300Z

clojure.core/*loading-verbosely*

alexmiller 2021-03-31T20:36:49.156700Z

^^ or you can put :verbose flag in the first require (which sets that)

👍 1
alexmiller 2021-03-31T20:36:55.156900Z

then you can usually just eyeball it

borkdude 2021-03-31T20:37:10.157300Z

oh I didn't know that one, thanks

2021-03-31T20:37:15.157600Z

oh - it does print the timing, nice

aengelberg 2021-03-31T20:37:19.157800Z

oooh awesome

aengelberg 2021-03-31T20:37:20.158Z

thanks

alexmiller 2021-03-31T20:37:31.158200Z

but the answer is: clojure.core.async

💯 1
😂 3
alexmiller 2021-03-31T20:37:33.158400Z

:)

ghadi 2021-03-31T20:37:42.158900Z

clojure.tools.analyzer 😉

borkdude 2021-03-31T20:38:02.159Z

what prints the timing?

2021-03-31T20:38:39.159200Z

require prints the timing if you set *loading-verbosely*

(ins)user=&gt; (require 'clojure.walk :verbose)
require (clojure.walk :verbose)
"Elapsed time: 0.068989 msecs"
nil

borkdude 2021-03-31T20:38:56.159400Z

no, that's just the side effect of your alter var root

😹 2
2021-03-31T20:39:27.159700Z

yet another alternative: use clojure.tools.namespace

2021-03-31T20:39:45.160Z

topo-sort the namespaces then load them one at a time with a timer

😂 1
richiardiandrea 2021-03-31T21:01:45.161900Z

Hi all, I am a bit stuck on this. How do I tell the compiler that I want the first arity of the following Paths/get? https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html I tried: (Paths/get #^"[S" (into-array [(:path image)])) I might have syntax error - I googled a bunch of stuff...

seancorfield 2021-03-31T21:02:56.162500Z

@richiardiandrea Only the ... part maps to an array, so you want a String followed by an array of String.

richiardiandrea 2021-03-31T21:03:25.163200Z

oh man, that's silly 😄

richiardiandrea 2021-03-31T21:03:43.163500Z

of me

alexmiller 2021-03-31T21:07:34.164100Z

#^ is old school now, just ^ is preferred

👍 1
ghadi 2021-03-31T21:19:17.165400Z

@richiardiandrea you do not need the type hint

user=&gt; (set! *warn-on-reflection* true)
true
user=&gt; (Paths/get "/usr" (into-array ["local"]))
#object[sun.nio.fs.UnixPath 0x1a411233 "/usr/local"]

ghadi 2021-03-31T21:19:47.165900Z

(because the signatures of Paths/get have distinct # of args)

richiardiandrea 2021-03-31T21:20:38.166Z

I am basically parsing only one string though, sorry it was not clear maybe from the example

ghadi 2021-03-31T21:20:54.166200Z

👌:skin-tone-3: that makes sense

richiardiandrea 2021-03-31T21:21:34.166400Z

Still haven't solved though, cause this fails

(Paths/get "/home" ^"[S" (into-array ^String []))

richiardiandrea 2021-03-31T21:22:13.166600Z

ah, ok found out - no type hint in into-array

richiardiandrea 2021-03-31T21:22:33.166900Z

(Paths/get (:path image) ^"[S" (into-array String [])) works

ghadi 2021-03-31T21:26:39.167100Z

[S is not a valid type hint

ghadi 2021-03-31T21:26:55.167300Z

should be [Ljava.lang.String;

ghadi 2021-03-31T21:27:54.167500Z

also into-array takes a class directly -- not a type hinted arg:

(into-array String [.....])
not
(into-array ^String [.....])

2021-03-31T21:28:00.167700Z

tbc — not saying issue individual require commands. Do it in a doseq.

2021-03-31T21:28:27.167900Z

But you can just time each require in the standard way once they’re topo-sorted.

ghadi 2021-03-31T21:29:19.168200Z

user=&gt; (-&gt; (make-array String 0) class .getName)
"[Ljava.lang.String;"

ghadi 2021-03-31T21:35:56.168400Z

1.10.1 was the fix

2021-03-31T21:38:11.168600Z

isn't [S an array of shorts?

2021-03-31T21:38:58.168800Z

user=&gt; (type (make-array Short/TYPE 0))
[S
user=&gt;

ghadi 2021-03-31T21:39:15.169Z

yup

ghadi 2021-03-31T21:39:24.169200Z

only the primitives have single letter abbrevs

borkdude 2021-03-31T21:49:47.169900Z

@richiardiandrea if you're interested in a library around java.nio.file which makes this stuff easier from clojure, check out https://babashka.org/fs/babashka.fs.html

richiardiandrea 2021-03-31T21:52:45.170300Z

Completely misread that S here lol https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.2-200 "Oh it's an S - same as the first letter of String" 😅

richiardiandrea 2021-03-31T21:53:39.170600Z

thank you @ghadi

richiardiandrea 2021-03-31T21:53:57.170800Z

yeah just discovered that thank you

borkdude 2021-03-31T21:54:56.171Z

the array stuff is what bugged me most ;)

richiardiandrea 2021-03-31T21:57:00.171200Z

it took me 30 mins + asking here -> I have just replaced everything we mentioned above with babashka.fs functions now 🤷

2021-03-31T22:15:26.171700Z

d'oh