Skip to content

Commit 146885c

Browse files
authored
Adding Pre commit hook (#1257)
* first try * first try * no blank line * contribution * normalizing pre-commit configuration to a top-level map * updated CONTRIBUTING.md * pull hooks from official codestyle repo * pin to v21.06rc1
1 parent a238ed4 commit 146885c

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/catalyst-team/codestyle
3+
rev: 'v21.06rc1'
4+
hooks:
5+
- id: catalyst-make-codestyle

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
88

99
### Added
1010

11-
-
11+
- added `pre-commit` hook to run codestyle checker on commit ([#1257](https://github.com/catalyst-team/catalyst/pull/1257))
1212

1313
### Changed
1414

CONTRIBUTING.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ It's much harder to merge in a large change with a lot of disjoint features.
9696
3. Submit the update as a GitHub pull request against the `master` branch.
9797
4. Make sure that you provide docstrings for all your new methods and classes.
9898
5. Add new unit tests for your code ([PR examples](#pr-examples)).
99-
6. Check the [codestyle](#codestyle)
99+
6. (Optional) Check the [codestyle](#codestyle). We use a pre-commit hook that runs the formatting on commit, so you don't have to.
100100
7. Make sure that your code [passes the Github CI](#github-ci)
101101

102102

@@ -115,19 +115,33 @@ Please use it as a collaborative platform, if you have any issues during the PR.
115115
### Codestyle
116116

117117
We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle)
118-
package to help with code formatting issues.
118+
package to help with code formatting issues, and a corresponding pre-commit hook installed.
119119

120-
You could check the codestyle for your PR with:
120+
To set the hook, please run (this requires `pre-commit` package, pinned in the `requirements-dev.txt`):
121+
```bash
122+
pre-commit install
123+
```
124+
Once the installation is done, all the files that are changed will be formatted automatically (and commit halted if something goes wrong, e.g there is a syntactic error). You can also run the formatting manually:
125+
```bash
126+
pre-commit run
127+
```
121128

129+
If for some reason you'll want to turn the hook off temporarily, you can do that with:
122130
```bash
123-
catalyst-make-codestyle && catalyst-check-codestyle
131+
SKIP=catalyst-make-codestyle git commit -m "foo"
132+
```
133+
Or you can uninstall it completely with:
134+
```bash
135+
pre-commit uninstall
124136
```
125137
126-
Once again, make sure that your python packages complied with `requirements/requirements.txt` and `requirements/requirements-dev.txt` to get codestyle run clean:
138+
Once again, make sure that your python packages complied with `requirements/requirements.txt` and `requirements/requirements-dev.txt` to get codestyle and pre-commit run clean:
127139
```bash
128140
pip install -r requirements/requirements.txt -r requirements/requirements-dev.txt
129141
```
130142
143+
For more information on pre-commit, please refer to [pre-commit documentation](https://pre-commit.com/).
144+
131145
### Documentation
132146
133147
Catalyst uses [Google style](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) for formatting [docstrings](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings).

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,32 @@ utils.onnx_export(model=runner.model, batch=features_batch, file="./logs/mnist.o
141141

142142

143143
## Table of Contents
144+
- [Getting started](#getting-started)
145+
- [Step-by-step Guide](#step-by-step-guide)
146+
- [Table of Contents](#table-of-contents)
144147
- [Overview](#overview)
145-
* [Installation](#installation)
146-
* [Minimal examples](#minimal-examples)
147-
* [Features](#features)
148-
* [Tests](#tests)
148+
- [Installation](#installation)
149+
- [Minimal Examples](#minimal-examples)
150+
- [Features](#features)
151+
- [Tests](#tests)
149152
- [Catalyst](#catalyst)
150-
* [Documentation](#documentation)
151-
* [Notebooks](#notebooks)
152-
* [Blog Posts](#notable-blog-posts)
153-
* [Talks](#talks)
154-
* [Projects](#projects)
153+
- [Documentation](#documentation)
154+
- [Notebooks](#notebooks)
155+
- [Notable Blog Posts](#notable-blog-posts)
156+
- [Talks](#talks)
157+
- [Projects](#projects)
158+
- [Examples, Notebooks, and Starter Kits](#examples-notebooks-and-starter-kits)
159+
- [Competitions](#competitions)
160+
- [Research Papers](#research-papers)
161+
- [Toolkits](#toolkits)
155162
- [Community](#community)
156-
* [Contribution Guide](#contribution-guide)
157-
* [User Feedback](#user-feedback)
158-
* [Acknowledgments](#acknowledgments)
159-
* [Trusted by](#trusted-by)
160-
* [Supported by](#supported-by)
161-
* [Citation](#citation)
163+
- [Contribution Guide](#contribution-guide)
164+
- [User Feedback](#user-feedback)
165+
- [Acknowledgments](#acknowledgments)
166+
- [Catalyst.Team](#catalystteam)
167+
- [Catalyst.Contributors](#catalystcontributors)
168+
- [Trusted by](#trusted-by)
169+
- [Citation](#citation)
162170

163171

164172
## Overview
@@ -1559,7 +1567,7 @@ runner.run()
15591567

15601568
### Tests
15611569
All Catalyst code, features, and pipelines [are fully tested](./catalyst/tests).
1562-
We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle).
1570+
We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle) and a corresponding pre-commit hook.
15631571

15641572
During testing, we train a variety of different models: image classification,
15651573
image segmentation, text classification, GANs, and much more.

requirements/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ mock==3.0.5
77
catalyst-codestyle==21.03rc2
88
catalyst-sphinx-theme==1.1.2
99
toml==0.10.0
10+
pre-commit==2.13.0

0 commit comments

Comments
 (0)