-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
initial pass at adding spec validation to leiningen #2223
base: master
Are you sure you want to change the base?
Conversation
This is just a proposal and food for thought ahead of the Conj. The hardest part of this is making the schema correct. The way this works is it only validates top level project keys if they are “similar” to keys that are defined in the schema.
Yeah it doesn't pass the tests I wanted to put this out there first. But I am looking at the tests now. |
Woah, this is impressive work and really appreciated. Definitely want something like this in when I've grokked it. I'm packing my bags for my flight tomorrow morning, but I will have two 1.5 hour layovers on the trip to Austin. Will also download dependencies and whatnot for the 11 hour trip over the pond. Looking forward to hear and talk more about it! =) |
Wow, this is beautiful. Well done, @bhauman |
@bhauman is there a difference between |
I played with this some today, mostly with the Seems great so far! I'll try to grab some other libraries and test it with them as well. |
I've tested against:
Things I found:
Otherwise all the projects seemed to work fine! |
@cprice https://github.com/bhauman/strictly-specking/blob/master/scripts/standalone |
@bhauman ah, gotcha. The clojars page for the standalone artifact has a link to a github repo for strictly-specking-standalone that shows up as a 404 for me. Might be worth fixing that link to point to something in the real repo and/or adding a note in the README if this patch is on its way in to leiningen (which I am in favor of!). |
I've tested against all the Clojure toolbox projects, and there are some false positives and a visual (..textual?) bug I've detected. Will write them down on this issue during the weekend. @bhauman: Did you want to verify project names and versions as well, or would you like to leave that to another PR? |
@hypirion yeah let me know what the problems are and I'll fix them in a jiffy. Might be worth it to share the problem projects so that I can reproduce. I will refactor error handling and so that they are exceptions caught in main. I will add validation of the project name and the version while I'm in there. |
Also we can do a simple check on the top level forms to insure its an even number and to maybe check that the keys are distinct. In the future I'd would like to write a more sophisticated reader parser to present helpful errors for arbitrary unbalanced maps and unbalanced parens in all read config files. |
So I made a small script which scrapes the clojure-toolbox projects, downloads them all, then runs deps to fetch dependencies and detect errors in their configuration: #!/usr/bin/env bash
lst="$(curl -s http://www.clojure-toolbox.com/ \
| sed -n 's/.*href="\([^"]*\).*/\1/p' \
| grep -F 'https://github.com' | sort | uniq)"
dir="$PWD"
mkdir -p toolbox-projects
cd toolbox-projects
for p in $lst; do
echo "checking out $p"
pname="$(echo $p | sed 's%.*/%%')"
gitRepo="$(echo $p | sed 's%^https://github\.com/%git@github\.com:%')"
if [ ! -d "$pname" ]; then
git clone --depth=1 "$gitRepo" "$pname"
fi
done
rm -f "$dir/output.txt"
for d in */; do
cd "$d"
if [ -f project.clj ]; then
echo "testing $d" 2>&1 | tee -a "$dir/output.txt"
lein-master deps 2>&1 | tee -a "$dir/output.txt"
fi
cd ..
done It assumes I found some configuration errors in the project themselves, but also found a couple of errors in the code which we may want to fix:
https://github.com/technomancy/leiningen/blob/master/doc/DEPLOY.md#gpg gives some information around the
Vector arguments are allowed and works just like "curried" things. e.g. the entry
Not entirely sure what's going on here – except that
Using Also, for some reason the error message has an off-by-one bug.
It's okay for
IIRC aliases can map to another command, in which case it could be a single string like this. (But I think we could break it for 3.x, as
I think it would be fine to have the licence map open for now.
I am guessing this is related to the one where
I've seen this quite a lot of times, and since All in all, I think this works very well. Since this will likely cause some false positives right after it's shipped, I think we should inform users that there is a way to turn this off. I would suggest commenting that you can turn off project.clj validation by adding Additionally, I think we should have a look at some of the maps. I think that most of the maps should be open in the beginning, to avoid errors like Apart from that, this PR is pretty solid and adds extremely valuable feedback to users IMO. |
This would be extremely cool if it used spec. |
This was introduced with commit 66cef07.
This is the case when Leiningen is used to build Java projects.
It now passes the project.clj of chromex.
…e error from the long is shown first. And since it's much more common that the long version it makes sense to keep it in this order.
This is really interesting work; thanks. Can you explain why an additional dependency is needed? Is it specifically there in order to avoid depending on a prerelease version of Clojure? I am very hesitant to add additional dependencies right now because of the work happening packaging Leiningen: https://wiki.debian.org/Clojure/Leiningen |
Updated your spec branch with master and fixed the remaining issues
@technomancy yeah, well there is are a lot of reasons unfortunately, one is that spec is needed and I'm using a vendored spec so that it's internals are stable bc there is significant functionality layered on top of it so I can search the spec tree. We could theoretically vendor this code inside of lein but ... |
After merging the changes by @Rovanion this PR is in better shape but it still needs a bit of work. |
Thanks. I am not saying we can't pull in a new dependency; just that I want to be sure to weigh the options. |
If we were to push spec validation into a plugin for the time being, would we need to make any changes to Leiningen to expose more things? One thought I had was that while obviously having a specific "look for problems where my project.clj does not conform" task would be helpful, it might also be helpful to run that conformity check whenever there is an error, so that likely configuration problems could be found more easily. What if we added the ability to load error handlers out of plugins just like you can currently do with hooks? |
In order for this to be a plugin we would need a hook to process the
project.clj before anything else happens to it.
In a sense we would need to hook the `defproject` macro the way things are
set up now.
The most interesting point here is that as a plugin it would be of little
use to the people who really need it.
Whereas, I think if this is embedded into Leiningen it might actually make
a really big improvement in the first time Clojure experience.
I'm not of the opinion that there need to be a central hook for
validation... As folks can include the library and validate the data that
gets passed to them.
I'm sorry I haven't pursued this any further. Been pretty busy... And
honestly this code is still a delicate flower that only works well if you
set things up just right. You kinda need to know the underlying
implementation and write the specs in a certain way to get the most helpful
messages out of it.
So for now I'd like to call this a proof of concept. Unless someone really
wants to steward it or if you are really interested in the completion of it.
PS.
BTW I'm sorry I missed you at ClojureWest. Both Tobias and I were pretty
sick for most of it.
…On Mon, May 22, 2017 at 1:11 PM, Phil Hagelberg ***@***.***> wrote:
If we were to push spec validation into a plugin for the time being, would
we need to make any changes to Leiningen to expose more things?
One thought I had was that while obviously having a specific "look for
problems where my project.clj does not conform" task would be helpful, it
might also be helpful to run that conformity check whenever there is an
error, so that likely configuration problems could be found more easily.
What if we added the ability to load error handlers out of plugins just
like you can currently do with hooks?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2223 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAKQMwm5VDkRmvH6PHbu14d8nsjH09Nks5r8evrgaJpZM4K_PFt>
.
|
I have to agree with Bruce. For this work to be useful to those who really need it, those who are new to Clojure as a whole, it has to be included by default in Leiningen. |
Sure--I would like it included in Leiningen eventually. It's just that
in its current state it is unlikely to stabilize in time for inclusion
in the next release, and I want to make sure it can be distributed as a
plugin first. That way we can gather feedback about it and evolve it
independently of the Leiningen release cycle.
|
That makes a lot of sense.
…On Tue, May 23, 2017 at 9:05 AM, Phil Hagelberg ***@***.***> wrote:
Sure--I would like it included in Leiningen eventually. It's just that
in its current state it is unlikely to stabilize in time for inclusion
in the next release, and I want to make sure it can be distributed as a
plugin first. That way we can gather feedback about it and evolve it
independently of the Leiningen release cycle.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2223 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAKQMuCsuaVqwKtqL1OMM-LIssQrVY1ks5r8wPYgaJpZM4K_PFt>
.
|
Leiningen already provides an option for plugins to offer middleware which get passed the project and can make changes to it if desired; I wonder if that would do the job for this to allow it to evolve in a plugin. |
Hello, any news ? |
Since Clojure 1.9 is released now, we are no longer blocked on this if someone wants to take it up. |
So ... The strictly specking library, while it works pretty well for figwheel, is still very very "hacky", meaning that you have to write specs in a "certain way" to have a specific outcome. I.E. you need to understand the internals to get optimal feedback for a particular error. This is why I have stalled on this for so long. The strictly-specking library is pretty much a mess, which is fine for figwheel but not so fine for Leiningen especially since specs have to evolve with the capabilities of Leiningen and if they evolve badly we will have a hard time. So basically, I'm saying that I'm not quite up to spending the 1-2 months time it would take to make this serviceable. Rich mentioned in his last talk that the next version of spec would be more "programmable", I'm wondering if a fresh simpler homegrown approach to this problem that isn't as strong and flawed as One approach that occurred to me is that you could preprocess the config map and prepend all the keys with namespaces that indicate their position in the project map. You could now write specs for these keys:
This could be very serviceable solution because when you are dealing with spec, getting an Also if you keep the predicates simple and bounded your explanations of the predicate failures will also be simple and bounded. You may even write custom specs for each type of predicate and override the explain method so that it includes an explanation string. Basically for feedback simplicity you want a Nested complex specs are very difficult to explain in a human way. Also, if there is a homegrown solution you can balance the simplicity (i.e. maintainability) - feedback trade-off. If anyone is interested in ping-ponging this back and forth with me I'd be happy to. I just don't want to take on this project alone as writing strickly-specking was way too intense of an endeavor. |
@bhauman thanks for the detailed explanation! |
I'd be interested in helping steward some form of this to completion, if you have time to download exactly where we are status wise with the project, @bhauman . |
This is just a proposal and food for thought ahead of the Conj. The
hardest part of this is making the schema correct. The way this works
is it only validates top level project keys if they are “similar” to
keys that are defined in the schema.
The initial schema can be backed off to a small group of keys that are easily defined and validated and then over time expanded to more keys.