Fork me on GitHub
#polylith
<
2022-11-07
>
licht1stein10:11:51

Does anybody have experience integrating biffweb as a base into polylith?

Daniel Shriki14:11:30

I have this error when I’m running poly check: Warning 205: Non top namespace resources was found in pdf. does someone has an idea what that means? I do have a resources folder in a pdf component (fonts), but what does it means non top namespace? Also, not related to that- What is your preferred way of sending states down to their components? associating them on middleware and extracting them on the interface’s component? or extracting it at the end file where it actually going to be in use? something else? Thanks a lot 🙂 happy to hear any idea/comment.

Teemu Kaukoranta14:11:57

Do you have a user.clj ? That might be the cause of that error

Daniel Shriki14:11:18

no.. I don’t have it. pure polylith project 🙂

Teemu Kaukoranta14:11:25

oh, now that I properly read that error message, it says you have a resources namespace

Teemu Kaukoranta14:11:47

but it's just a folder?

Daniel Shriki14:11:05

exactly, just a folder with fonts (no clj file in it)

Teemu Kaukoranta14:11:32

.. is it in a source folder?

Daniel Shriki14:11:09

sorry confused, it is used for src.

Teemu Kaukoranta14:11:30

Can you move it so that it's on the same level as the src/ folder?

Teemu Kaukoranta14:11:53

So you have src/, test/, resources/, test-resources/ etc.

Daniel Shriki14:11:48

this is the hierarchy

Daniel Shriki14:11:03

{:paths   ["src" "resources" "test"]
 :deps    {org.apache.pdfbox/pdfbox {:mvn/version "2.0.22"}}
 :aliases {:test {:extra-paths ["test"]
                  :extra-deps  {}}}}
deps.edn on the same level ^

Teemu Kaukoranta14:11:45

you might want to remove "resources" and "test" from the the :paths by the way Edit: and add "resources" to :test :extra-paths

Jungin Kwon14:11:27

Make ‘pdf’ directory under the resources

Jungin Kwon14:11:33

and move ‘fonts’ to that directory

Jungin Kwon14:11:42

Did you use ‘poly’ tool when you created the pdf component?

Daniel Shriki14:11:49

it didn’t solve it /:

1
Daniel Shriki14:11:57

and yes, I did use poly tool

Daniel Shriki14:11:27

@UCQGNA673 what’s the idea of moving it to :extra-path?

Teemu Kaukoranta14:11:05

You only need the resources/ and test/ folders in the classpath when running tests. Now they're both included always

Teemu Kaukoranta14:11:26

You can run your REPL with the test (and dev) alias both enabled

Daniel Shriki14:11:55

I confused for a sec, the resources/ folder is actually not for testing but part of the source.

Daniel Shriki14:11:27

(creating pdfs in running time with specific fonts)

Teemu Kaukoranta14:11:47

well, you should at least be able to remove test/ from the :paths then 🙂

👍 1
Daniel Shriki14:11:31

true 🙂 but could it be the reason of the warning? because it’s not under src/ ?

Jungin Kwon14:11:13

What is your top level namespace?

Daniel Shriki14:11:44

hmm my top namespace is indeed does not appear there, but it’s because its a folder with no clj files

1
tengstrand16:11:03

Type poly ws get:components:pdf:non-top-namespaces and it will list the namespaces that are not top namespaces @daniels.

furkan3ayraktar16:11:47

I think the issue is what @U027B5AEPCG mentioned: if your component is named pdf, then you should have the following directory hierarchy: • resources ◦ pdf ▪︎ fonts And as @UCQGNA673 mentioned, it is a good idea to remove test directory from paths; you already have it in your :test alias and you don’t want to include tests in your production code.

seancorfield17:11:42

I ran into this at work last week when refactoring legacy code to Polylith. We had some photo handling test code and a JPG in the top-level of test and I copied all of that into a new components tree and got the warning... and stared at it for a while before I realized why it was complaining... so I think the wording of the message could be improved (found <brick>/<filename>; expected <brick>/<filename-with-top-ns-added> perhaps?). I moved bases/admin/test/test_file.jpg to bases/admin/test/ws/admin/test_file.jpg and updated the io/resource that referred to it, and poly check was happy.

licht1stein22:11:29

I had that problem. It's fixed by moving stuff from your pdf/resources folder into pdf/resources/pdf folder. It makes practical sense too — if you have files with the same names in different componenets they don't get confused in the resulting jar. For example, if you have several config.edn files for different systems, putting them in a subfolder and referring to them as (io/resource "pdf/config.edn") solves all kinds of headaches.

Daniel Shriki10:11:59

So I tried that too, and also tried pdf/resources/pdf/fonts, both of them made no difference \:

Daniel Shriki11:11:35

could be related to local cache somehow?

Jungin Kwon14:11:41

I had similar issue when working with intelliJ, the problem was IDE combine folders like ‘bean_counter.backend.pdf’ and I solve the issue by deleting and creating the component again.

seancorfield18:11:33

According to your screenshot, you have test/resources which will not work. You also have test/bean_counter.backend.pdf as a folder which will not work properly. If your top-ns is bean-counter.backend, that should be test/bean_counter/backend/pdf -- test/<top-ns as path>/<brick-name>. The part that will work there is pdf/resources/*.ttf since Polylith doesn't care about the structure of the resources folder (although it is better practice to use a path there to avoid potential conflicts between various resources files across multiple bricks).

seancorfield18:11:53

If you have resources that are just for testing, they need to be in test/<top-ns as path>/<brick-name>/<something> because Polylith cares about the file structure in src and test.

Daniel Shriki08:11:52

You right, after moving test/resources folder to test/<top-ns as path>/<brick-name>/<something> the warning disappeared! The problem now is that the files in there can’t be loaded now with io/resource (`Cannot open <nil> as an InputStream.`) . It happens when I try to reach the files using bean_counter/backend/pdf/resources/share.pdf or just resources/share.pdf (as it was before, and the test passed)

seancorfield18:11:09

@daniels What is the exact path to that PDF file now? The path in io/resource needs to be relative to the test folder -- so I'm not sure why you have resources in it...

Daniel Shriki19:11:35

bean_counter/backend/pdf/test/reaources/share.pdf This file is used for tests, isnt it counted as a resource?

seancorfield19:11:15

io/resource finds things relative to the classpath. So in Polylith, bean_counter/backend/pdf/test should be on the classpath (that's how the various test files are found), so io/resource should find resources/share.pdf (assuming reaources is a typo from copy'n'paste and it should really be resources)

seancorfield19:11:50

src test resources is just a convention for names. What's important is the classpath.

Daniel Shriki08:11:04

ohh ok, every sub-directory of any component, that has <top-ns> in it is considered a root for classpath and (io/resource) trying to resolve to the most specific dir he has, that’s why the <brick-name> is also important. I think that I understand it now, and also the problem solved. Thanks a lot! 🙂 🙏

seancorfield18:11:18

I'm pulling this into a separate thread for @daniels since only the warning got addressed in the earlier thread: What is your preferred way of sending states down to their components? associating them on middleware and extracting them on the interface’s component? or extracting it at the end file where it actually going to be in use? something else?

👀 2
seancorfield18:11:12

Could you give an example of what you're asking about? I'm not sure what the context is since "middleware" isn't a Polylith concept but "component" and "interface" are.

seancorfield18:11:28

Also what do you mean by "sending states down..." here?

Teemu Kaukoranta20:11:46

I'm guessing he means dependency injection

Daniel Shriki16:11:05

Tnx @U04V70XH6 🙏 sorry for the delay, yes- dependency injection. so let’s say I have a clients component that has a store.clj ns that uses DB, and I have core.clj & interface.clj in the same component to. The function get_client can be like get_client(db, client_id) or it can be without the ‘db’ instance if I’m requiring it in the same ns. if I do inject it earlier, where would be the best option? We were thinking of injecting all of our states on a middleware. but than the interface function would be get_client(states, client_id) . and the store function would be get_client({:keys [db]} client_id) . the downside is that I’m sending all the states (which most of them not relevant to the component) to the component. so I’m looking for a better idea. I hope that I explain it right 😅

seancorfield17:11:22

Even in the same ns, I would always pass the db into the function call. "Globals are bad" 🙂

seancorfield17:11:00

Are you using Sierra's Component library or something else? (we use Component very heavily at work)

Daniel Shriki17:11:00

you mean for the state management? we use Mount. it manages the global states

seancorfield17:11:46

Mount uses namespace-level globals. I think that's bad.

Daniel Shriki19:11:32

Any chance you know an open source that uses Sierra with polylith so I can borrow some insperation? 🙂

seancorfield20:11:50

https://github.com/seancorfield/usermanager-example/tree/polylith -- there's also a regular branch without Polylith -- and the README links to a version built with reitit and Integrant instead of Compojure and Component respectively.

🙏 1