-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add .pre-commit-hooks.yaml configurations #7558
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
This change allows to easily configure sphinx as a git hook over the pre-commit framework, so as to: - Ensure the documentation is building for each commit - Automatically keep the local documentation up to date References: - https://pre-commit.com/ - https://pre-commit.com/#new-hooks Example for a .pre-commit-config.yaml configuration: repos: - repo: https://github.com/sphinx-doc/sphinx rev: 3.x hooks: - id: docs args: [-W, ./docs/source, ./docs/build] additional_dependencies: - sphinx_rtd_theme always_run: true files: ".^"
|
-1: most of the commits are not related to changes with the document. And we've already build our document on the CI service. So I feel this is too much. |
|
Thanks for the feedback @tk0miya. I agree that this may not be a fitting tool for every project and may represent an unnecessary overhead for non-documentation related commits on large projects (although I was under the impression that sphinx makes use of caching before deciding whether to rebuild part of the docs). I thought it wouldn't come at any harm and might offer quite handy solutions in particular for small projects using sphinx with autodoc for instance. |
|
If my understanding is correct, what you should do is add a tip page to the Sphinx document. I suppose users of Sphinx does not read the dotfile on the repository. I think this PR effects to developers of Sphinx only. |
|
Well, this addition is meant for the general user, but you’re right that he would probably not be aware of this possibili.y without looking at the dotfiles. If you’re keen, I would be happy to further submit an update to the documentation along with the change. I had a look at the contents and haven’t found an existing section that would fit. It might be worth adding an Integrations section that could also include documentation on integration with other tools. I am thinking something along those lines: Sphinx documentation contents
├── Introduction
├── Installing Sphinx
┆
├── Integrations
├── Git Hooks
├── pre-commit
├── Editor Integrations
├── Read the Docs IntegrationNote that |
|
As @tk0miya mentioned, the location of the file is not good and could adversely affect those that clone the Sphinx repo. How about adding it as an option to sphinx-quickstart, similar to how it asks about Makefile generation? |
|
Okay, I understand how pre-commit works. It just reads BTW, is pre-commit able to change the command by the version of the installed package? We have a plan to change the form of sphinx-build command (maybe in the future, refs: #6938). At that time, we will change the recipe script to the new one. But I worried the change will break the users who uses pre-commit and old Sphinx. Is there any idea? |
LGTM. At first, I thought it is better to add it to the FAQ page https://www.sphinx-doc.org/en/master/faq.html. But I prefer your idea. |
|
I'm definitely a fan of this idea and would love to see it. However, we need docs. I'd suggest putting it into |
|
I have been quite busy lately, but I am happy to take care of the documentation for this. Will propose something in the next 2 weeks. @tk0miya concerning changes to the @stephenfin thanks for the feedback. Not entirely sure what your concerns were with the configurations, but my understanding is that the |
I have only used existing pre-commit hooks and not written my own, so apologies if I'm misunderstanding things (feel free to link docs proving me wrong), however, you can't just call |
|
Yes you're right. You can easily set all those parameters in your project's repos:
- repo: https://github.com/sphinx-doc/sphinx
rev: 3.x
hooks:
- id: docs
args: [-W, ./docs/source, ./docs/build]
additional_dependencies:
- sphinx_rtd_theme
always_run: true
files: ".^"The upcoming documentation should be able to clarify all this... |
|
I'm closing this because of not updated long. In my understanding, a new documentation entry is needed to merge this. Please resend a new one if it will be ready for review. Thanks, |
Feature or Bugfix
Purpose
This change allows to easily configure sphinx as a git hook over the pre-commit framework, so as to:
Detail
To use sphinx as a git hook over pre-commit with this change, you may follow the steps below:
pre-commitin you project.pre-commit-config.yamlfile at your project root. Example:NB 1: The
filesandalways_runkeys are set so that the build runs exactly once without matching any files.NB 2: My fork can be used for testing by setting
repo: https://github.com/OliverSieweke/sphinxBelow are examples of passing and failing documentation builds:
References: