Fork me on GitHub
#polylith
<
2024-02-14
>
namenu08:02:15

This may not be about polylith rather tools.deps, but how do you run :deps/prep-lib for bricks? I have a base named core-api and it depends on Java mixed library that need to be prepared. I couldn't prep it via clj -X:deps prep :project '"base/core-api/deps.edn"' so I ended up change my working dir before run.

Mark Sto11:02:19

Is it something akin of Lein’s prep-tasks, which pre-compile some Clojure code to be able to use it in Java? Didn’t realize this exists in Deps. =/

Mark Sto21:02:43

Hmm… Nice one. So far I deal with it in my single component with a single shared utility Java class with the help of compile-java function in the ws-level build script. The function contract is simple, it expects a single argument — the brick name. Then I call it like this: clojure -T:build:dev compile-java :brick components/utils.

Mark Sto22:02:42

IIUC, ultimately this can be simplified and kinda idiot-proofed with clj -X:deps prep (as per https://clojure.org/reference/clojure_cli#deps_prep). The problem with :deps/prep-lib approach in my case, though, is that if I want to make clj -X:deps prep to work (at the top level, i.e. for the development project), I need to somehow point it to the build script.

Mark Sto22:02:41

If my build script is at scripts/build.clj, then how can I reference it within a components/utils’s deps.edn alias extra-paths/-deps?

Mark Sto09:02:53

Ok, so I was able to reach the point where I get Error building classpath. The following libs must be prepared before use: [platform/utils] error for the clj -X:dev:deps prep (from the ws level, i.e. for the development project), after I converted my scripts subdir into a Deps project and making the utils component depend on it via a :local/root. And I now get the same error for the clojure -T:build:dev compile-java :brick components/utils command. Now I’m stuck.

Mark Sto10:02:51

If I comment-out the :deps/prep-lib in my utils component’s deps.edn I at least am able to run previous command (from the root) that compiles Java sources in it.

namenu11:02:48

Oh now you are on the same page with me 😅

🥲 1
Mark Sto18:02:22

Yeap. Maybe this is a real deal, i.e. issue with nested Deps projects that were not accounted for in Deps? I wish @U04V70XH6 could advise here, but he already mentioned a while ago that WS doesn’t use pre-compiled Java (apart from libs). Out of luck here. =/

seancorfield19:02:55

I've been summoned! So... there's a lot to unpack here but I'll start by saying that the bricks' deps.edn are not "complete" deps files in the sense that the Clojure CLI expects -- because bricks don't declare dependencies on other bricks, only on third-party libraries.

😄 2
❤️ 1
seancorfield19:02:02

Only projects have "complete" deps.edn files, so that's the only place you can hang -X:deps prep -- and :deps/prep-lib is designed to be used for a complete library (which bricks are not).

seancorfield19:02:19

So... You could use it at the top-level (i.e., the development project) and it could rely on your :build alias (or some other alias) and some function and :ensure some specific directory.

seancorfield19:02:59

However! Think about what the whole prep-lib concept is about: it is for a one-time preparation step for a (third-party) library you are using.

seancorfield19:02:02

So... I'll ask @U7JHWBCS0 the question: is this mixed Clojure/Java library external to your Polylith project or is it part of your project? I'm reading your question as the latter -- which is not a use case for prep-lib because you would presumably be changing your Java code and needing to recompile it each time, rather than a one-shot preparation. In which case, just putting something in your build.clj script to recompile the Java whenever you need/want to is the right approach here.

👍 1
Mark Sto19:02:44

Damn, it makes a lot of sense now! The CLI simply can’t see the dependency between the two bricks (there is none), consumes the list of deps from the development project, and then traverses it in some specific order that cannot be changed (or, at least, I don’t know how — simply swapping items in the :extra-deps vector doesn’t change anything).

seancorfield19:02:38

:extra-deps takes a hash map and they are inherent unordered.

Mark Sto19:02:12

Yeah, I meant :extra-paths vector, of course. Pesky typo.

Mark Sto19:02:24

So, yeah, it looks like my previous approach is the single feasible one. Just use a compile-java step in your build.clj script or bb task, do it once, and that’s it. Thank you, Sean!

seancorfield19:02:27

I only use :extra-paths for test folders. I use :extra-deps for bricks. But, yeah, build.clj and compile-java whenever the Java code changes (again, assuming the Java code is in the Polylith project?).

Mark Sto19:02:52

I tend to use both :extra-paths and :extra-deps in non-`:test` profiles for IDEs/editors compatibility. It shouldn’t hurt anyway. The classpath will be the same.

Mark Sto19:02:11

> assuming the Java code is in the Polylith project? Correct, sir.

seancorfield19:02:19

Even Cursive supports :extra-deps in Polylith now. Pretty sure that was the only hold-out previously.

👍 1
Mark Sto19:02:50

I’m still on 2020.1.3 though. 😑cursive

Mark Sto19:02:19

Probably will update soon and get rid of this “extras”.

Aviv Kotek15:02:06

hi guys, we'd like to use Polylith on our Python new project. we have been using it on our Clojure services for few years and happy with it. was wondering if there's any template / example projects out there ? is there anything else I need to do ? I've seen @david043 work and wondering if that's the direction I should go with ? thanks

tengstrand16:02:37

If you want tooling support with Python, that should be your best option right now as far as I know.

👍 1
David Vujic17:02:43

I might be a bit biased, but: Yes 😄 Some differences from Clojure are that the Polylith tooling is built on top of package & dependency management tools like Poetry, Hatch or PDM. Also, there is a python-specific "theme" that is recommended to use. It will organize the bricks a bit differently. This is because Python tooling in general has poor support for the dynamic kind of folder structure that we have in Clojure. If you haven't already, have a look at the Python Polylith docs: https://davidvujic.github.io/python-polylith-docs/ And I'm here if there is any questions or feedback.

🚀 2
🔥 1
David Vujic17:02:57

I have also helped out some Python teams via zoom/meet to get things started quickly and resolving any issues.

👍 1
Joel04:02:53

Can a polylith repo have and share dependencies between Clojure/Python?

tengstrand05:02:17

Clojure runs on the JVM and if you want to share code from another language (as a library) then it must be compiled to Java bytecode. Another option is to use https://www.graalvm.org to share code between languages. I don't know, but maybe you can use https://www.jython.org to generate bytecode.

✔️ 1
Joel05:02:53

Interesting,https://github.com/clj-python/libpython-clj, but I don’t know what “magic” it uses.