-
Notifications
You must be signed in to change notification settings - Fork 46
Implement a YAML linter hook #358
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
Conversation
db44a1f
to
dec9d6d
Compare
dec9d6d
to
cedc758
Compare
the linter can be very useful. The main downside is that we don't have a way to install external dependencies for hooks... Anyway, if this is going to check the conandata.yml only I'd probably change the name to explicit this or make the hook more generic to check all YAML files exported alongside the recipe. Another question: Should this be part of the conan-center hook or better keep it as a different hook for wider use rather than ConanCenter only? |
I just added some code that made it explicit what has to be done if yamllint is not installed.
As it has an external requirement, I think we cannot include it in conan-center hooks. That said we can still run the hook in Conan-center-index CI, as demonstrated in ericLemanissier/cocorepo#5
ok, I guess that would make the check a post_export instead of pre_export |
@danimtb it's ready for review |
@ericLemanissier Is yaml lint recursive? If yes, I would suggest looking one level above to check |
How do we know If it is cci's structure ? We could end up scanning the full disk. EDIT: I'll simply scan ../config.yml if it exists |
Smart! |
Well, it will be funny once merged. Not in Conan Center by default, but still has a big potential:
|
Co-authored-by: Uilian Ries <[email protected]>
These are warnings which can be disabled if you prefer. That said, this hook is not part of conan-center hooks, so it will never be reported by c3i. This is why I intend to make it run in a dedicated github action,: nobody will look at the log, except if the status is failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add more hooks other that conan-center
to CCI (in fact I think some of those check should be extracted from conan-center
into their own hook). And we will, probably this will be one of them.
Besides that, I have some concerns with this idiom (not first time here):
try:
import yamllint
except ImportError as e:
sys.stderr.write("Install yamllint to use 'yaml_linter' hook: 'pip install yamllint'")
sys.exit(1)
I think Conan client will exit with the sys.exit
, it is unconditional, no exception to catch. I would prefer just an error: "Hook XXX cannot be loaded because of ...". I'm not sure if this is something already working if we let the ImportError
to propagate, or it's better right now to capture the exception and noop
if the hook cannot run:
try:
import yamllint
def pre_export(...):
...
except ImportError as e:
sys.stderr.write("...")
Maybe, for some other plugins it makes sense to raise and stop Conan execution, but for most of them an error while loading the hook should be enough. wdyt?
I agree ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to add an entry to README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, thank you!
fixes #308