-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow removing dirs from classpath during runs #330
Comments
It sounds like in the REPL situation, you already have the right paths in your classpath, so maybe setting
|
@alysbrooks the problem is |
That's not correct. We add to the classpath, afterwards these directories stay on the classpath.
This is not possible in the JVM, the classpath that the JVM started with is inaccessible/immutable, you can't remove entries from it. You can install a child classloader that searches additional paths, but the application class loader is fixed. There are probably ways to make this work if you try hard enough, eg by injecting a java agent at startup, but that's beyond what kaocha is willing to do I think. However you don't necessarily need to remove entries in your case, all you need is that env/test is searched before env/dev. The priority-classloader in lambdaisland/classpath can do this, I would suggest playing around with that and disabling kaocha 's classpath manipulation. |
Perhaps I'm still misunderstanding, but if you need |
@plexus If I can change the order they are searched (and change it back afterwards) that would probably be enough. The Thanks also @alysbrooks, "env/dev for the majority of the REPL work and env/test for running tests" is what I'm after, yes. |
Yes, So you can use See https://lambdaisland.com/blog/2021-08-25-classpath-is-a-lie for a write-up of this stuff. |
Hi @plexus, thanks for the detailed writeup! I might be misunderstanding, but based on that blog post, I'd expect The actual behaviour I'm observing is that Based on
from your previous response, I'm guessing that I misunderstood the blog post and |
Can you please be concrete about how you come to this conclusion? What's the output of |
I tried calling
Before:
After:
It looks like the issue is the updater expects a .jar, not a dir of source code?
I'm not sure I understand this question, do you want me do call |
@AlexChalk I've created a demo repo, please check that out locally and go through the provided repl sessions. Hopefully that clears things up.
classpath entries can be either jars or directories, so you're good. That output looks good,
#object[java.net.URL 0x5c3a1d17 "file:env/test/my_app/env_config.clj"] See the examples in the demo repo. |
@plexus Thanks for this! I was using Thanks also for the |
Happy to help!
c.t.n keeps a map of last-modified timestamps for each file, and |
Context
My application includes something like the following structure:
I have a place to put environment-specific code, and I can then modify the classpath to include the correct code depending on the context in which I'm running the app. (I lifted this pattern from the luminus micro-framework.)
For example, for development I include
:extra-paths ["env/development"]
in mydeps.edn
:development
alias, and I call(b/copy-dir {:src-dirs [... "env/production" ...]
in my productionbuild.clj
script.Problem
I know kaocha includes
:kaocha/test-paths
intests.edn
, and this is a great place to add["env/test"]
to the classpath when running tests from the command line.The problem is that this doesn't work when running tests in the repl. I need to start my repl in development with the
development
alias included, and this meansenv/dev
has already been added to the classpath andenv/test
is ignored when I callk/run
.Feature Request
I'm guessing that
k/run
has some way of modifying the context in which it's called to include:kaocha/test-paths
in the classpath with no trace of this in the repl afterwards.What I'd like is a similar config option, maybe
:kaocha/excluded-paths
, that removes dirs from the classpath in the context ofk/run
, with no trace of this afterwards.Would you be open to this feature? I can try adding this myself, with the disclaimer that I'm pretty new to clojure (and completely new to kaocha) so I'd probably need some help. Thanks!
The text was updated successfully, but these errors were encountered: