Fork me on GitHub
#clojure
<
2022-03-06
>
skiggz07:03:31

I’m trying to convert to deps.edn from a lein project. So far I have most things working except java compilation for tests. Any test that includes a java file or references one fails with filenotfound (not on classpath). How do I tell deps.edn test runner to run a compile command and then use the java+clj classpath / output for tests? deps.edn:

:paths   ["src" "java"]
:deps    {org.clojure/clojure {:mvn/version "1.10.3"}}
:test  {:extra-paths ["test"]
                   :extra-deps  {io.github.cognitect-labs/test-runner
                                 {:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
                   :main-opts   ["-m" "cognitect.test-runner"]
                   :exec-fn     cognitect.test-runner.api/test}
I have a build.clj file that can create an uberjar which files reference java source and it works fine when I run it, it’s just the tests that can’t find those java classes on the classpath (using the cognitect test-runner clj -A:test) . If I don’t reference any java classes or clojure files that reference java, tests run fine.

hiredman07:03:33

You'll have a build.clj thing that calls javac and writes class files to disk somewhere (prior to uber jarring) you need to call that before running your tests and add the output directory to paths when running your tests

hiredman07:03:12

You'll likely want to write a build.clj function that bundles that up

skiggz07:03:19

Like pass a command into :main-opts or something ?

skiggz07:03:42

I have a function that just compiles java to target as a separate step much like the example on http://clojure.org deps page

hiredman07:03:56

Sure yeah, that

hiredman07:03:18

It writes the classfiles to disk somewhere

hiredman07:03:21

So to run your tests you call that first, then have some alias which adds the classfiles output directory to your paths, and use that alias for running tests

skiggz07:03:48

Can an alias call an alias so I can put it in a single clj command, or are you suggesting a bash script or something that runs multiple commands? I can try the latter, straightforward enough. thanks!

hiredman07:03:24

No, you shell out, start a new jvm running your tests

hiredman07:03:46

Has a function for that

hiredman07:03:04

You can also search for test in #tools-build

skiggz07:03:20

cool, thanks!

Adam Helins08:03:17

Dear friends, I am once again having an inner struggle about licenses. With respect to Clojure, there is this [interesting article from Juxt](https://www.juxt.pro/blog/prefer-mit), but there does not seem to be a lot more intel available. I'd be grateful if you could share more resources like that, should they exist. Personally, I've always been drawn to copyleft-ish licenses. While full GPL is always controversial, there are more sensible options. Notably, MPL 2.0 have often seemed quite reasonable to me, although my legal expertise is noob-worthy. Hence, for your professional endaveours, related to the usage of Clojure in any nature, what is your stance on MPL 2.0 or other similar copyleft-ish licenses? Is is a no-go like GPL often is for a lot of companies? If so, is it a preventive measure or are you aware of obvious compatibility issues, especially with respect to the overall Clojure ecosystem?

Ben Sless09:03:34

I tried to figure it out once and just got more confused because GPL also effects your linked / built code

Ben Sless09:03:05

So following this thread hoping someone will explain how I can use agpl 🙂

lilactown16:03:51

I like the EPL 2.0 (similar to what clojure is distributed under) since I mostly write open source libraries, and it ensures that people who use my libraries 1. can write closed source proprietary software using them (i.e. their day job) 2. ought to contribute code back to the public if they make any modifications IANAL but that is my understanding of the license. GPL with class path exception I think is similar but seems more dicey and confusing last I read into it

lilactown16:03:09

IME companies I've worked at who use clojure already are also open to using libraries that fall under it, but not GPL

lilactown17:03:21

I'd use an MPL 2.0 lib. I'd probably have to check with legal at work before using it though

lilactown17:03:10

for my own personal libs, the patent stuff has no bearing on me but if you're releasing source code as part of your business then you might care more

Adam Helins08:03:11

Thanks for your feedback! Too bad the post didn't get more love, I find it to be a very important topic, clearly overlooked. @U4YGF4NGM Those are 2 aspects I also care about and if I'm not mistaken, the MPL 2.0 covers them as well

lilactown15:03:32

yeah looks like it

Casey14:03:42

I'm using Selmer to template out some plain text reports. One unfortunate thing is that the lines that contain only Selmer tags (e.g., {% for thing in things %} end up in the rendered output as blank lines. I realize for HTML this doesn't matter, but for plain text it does indeed. Does anyone know of a workaround for this, or perhaps another similar library without this limitation?

Casey14:03:24

Switched from diving in the code to looking at existing issues in Selmer.. and it looks like this addressed with this (open) issue https://github.com/yogthos/Selmer/issues/115

Casey14:03:19

And the related thread https://clojurians.slack.com/archives/C06MAR553/p1620329458137300 (wow it's nice having history going back so far)

mx200015:03:43

I am developing a game in clojure and the entities are stored in atom’s. Each entity holds a map as value when deref’ed. Now entities are referred to as ‘entity’ in function arguments and local variables. Some functions like ‘get-position’ are looking up values in the nested entity-hashmap. Now the question is how to name the entity when dereferenced in the function args / local variables? -> Maybe entity-hash, entity-value, entityv, entityval … Is there anyone who was experienced this issue?

mx200015:03:52

Also I am not sure where to call deref on an entity. For example I have a function

(defn get-position [entity] (:value (:position @entity)))
which returns the current position value in the :position component … or should the entity be deref’ed before calling get-position and look like this?:
(defn get-position [entity-hash] (:value (:position entity-hash)))
I am favoring the second variant right now, although a lot of deref’s will be everywhere in the codebase then.

solf15:03:18

I'm not sure I understand the name issue, but for your second question, you should 100% pass the already deref'd value. There should only be a few places where you need to deref your atom, not far from 1. I think seeing more of the code would be helpful

mx200016:03:21

The name issue is - some functions work on the atom (checking something, swap!-ing something ,… ) and some functions work on the internal map data structure. - and I have to find two different names.

mx200016:03:41

I also agree that get-position for example should just work on plain map data structure, it makes it much simpler and straightforward.

mx200016:03:01

I think I am going for ‘entity’ and ‘entitv’.

Alex Miller (Clojure team)16:03:34

It is far better to make as many pure functions as you can - they are easier to write, easier to test, and composable. I generally try to avoid making a function that manipulates the atom at all and favor writing that inline at the place of use, using swap! to apply a pure function there, thus keeping all stateful ops as close to the state as possible

👍 2
mx200016:03:05

Thank you Alex. But what do you think about the naming?

Sam Ritchie16:03:18

@mx2000 I would recommend privileging the immutable version, keeping those called entity and not derefing inside your functions, but calling the ATOM something special, like !entity (I forget where I first saw the exclamation point form). Then push calls like (get-position @!entity) up as high as possible in your stack.

Sam Ritchie16:03:15

Then you can test almost everything as @alexmiller says without any atoms at all, but with maps you build in your tests. here is an immutable blackjack game I built long ago… https://github.com/sritchie/blackjack/blob/develop/src/blackjack/core.clj I think I actually avoided ANY state by cheating and calling prompt inside one of the functions (https://github.com/sritchie/blackjack/blob/develop/src/blackjack/core.clj#L377-L393), then pushing everything for the full game-loop into a loop-recur. But I was proud at the time that all functions except for the one with prompt operated on immutable maps. much easier to test: https://github.com/sritchie/blackjack/blob/develop/test/blackjack/core_test.clj

Alex Miller (Clojure team)16:03:01

If you avoid passing atoms into functions at all, there's nothing to name :)