Closed borkdude closed 1 year ago
The basic idea sounds good. Don't have any ideas about the convention yet -- will think about it. I do have a question though.
Is the intention to also be able to obtain clj-kondo configurations from within the .jar file for a library?
Would updating an existing config for a specific library A
be a matter of deleting what's currently at configs/A
and then copying a new version in place?
@sogaiu .jars: yes. I think by default this library removes/overwrites existing dirs with the same name.
@borkdude Thanks for the clarification.
A specific scenario I had in mind is:
1) A user creates a project using a template (e.g. using clj-new) that also puts in place some clj-kondo configurations (e.g. there might be a configuration for library A
)
2) Some time later the user updates library A
and the corresponding clj-kondo configuration within the project directory becomes out of date
3) The user updates the clj-kondo configuration using an appropriate alias command -- up-to-date clj-kondo configuration bits are copied from the .jar to appropriate locations in the project directory
Does that seem reasonable?
Yes
Thanks for the heads up!
@borkdude TLDR; it seems to work :+1:
Below are some notes for future reference.
Here's an attempt at following them for libpython-clj: https://github.com/sogaiu/libpython-clj/tree/clj-kondo-hooks/resources/clj-kondo.exports/clj_python/libpython-clj
When I build a jar, I end up with the following top-level content:
In a project that had the modified libpython-clj as a dependency:
$ clj-kondo --no-warnings --lint "$(clojure -Spath)"
gave output like:
Copied config to .clj-kondo/clj_python/libpython-clj. Consider adding clj_python/libpython-clj to :config-paths in .clj-kondo/config.edn.
This worked via :local/root
as well as via .jar
:+1:
As expected, subsequently editing .clj-kondo/config.edn
to contain essentially:
{:config-paths ["clj_python/libpython-clj"]}
was sufficient for the hooks to be enabled.
One thing that had me stumped initially was that I had erased the .clj-kondo
directory for testing purposes. Under such conditions invoking the aforementioned command gave blank output -- perhaps not surprising as no copying took place.
Update (2021-03-19):
Note that --no-warnings
has been deprecated in favor of --dependencies
, see https://github.com/clj-kondo/clj-kondo/pull/1221#issuecomment-802331558
I also tested this:
$ bb -cp src:resources --uberjar /tmp/libpython-clj.jar
$ cd /tmp
$ mkdir -p proj/.clj-kondo
$ cd proj
$ clojure -M:kondo-local --no-warnings --lint /tmp/libpython-clj.jar
Copied config to .clj-kondo/clj_python/libpython-clj. Consider adding clj_python/libpython-clj to :config-paths in .clj-kondo/config.edn.
$ tree .clj-kondo/clj_python/libpython-clj/hooks
.clj-kondo/clj_python/libpython-clj/hooks
└── libpython_clj
├── jna
│ └── base
│ └── def_pylib_fn.clj
└── require
└── import_python.clj
Note that in clj_python/libpython-clj
you can use a normal hyphen in clj-python
if you want. Only in hook code you have to use underscores because that's where namespaces are going to be resolved.
Thanks for testing and the tip about the hyphen.
Do you think it would make sense to note somewhere that the .clj-kondo
directory must exist before the invocation for this to work?
@sogaiu Added it to the docs.
TYVM!
This config tool can inspect the classpath for clj-kondo configurations from libraries and spit them out to
<project>/.clj-kondo/configs
. The tool should then also print a list of directories the user should add to:config-paths
to enable these configs.TBD: