diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..7af03d0a20 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- repo: https://github.com/catalyst-team/codestyle + rev: 'v21.06rc1' + hooks: + - id: catalyst-make-codestyle \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 194ccc85b8..d42510f190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added -- +- added `pre-commit` hook to run codestyle checker on commit ([#1257](https://github.com/catalyst-team/catalyst/pull/1257)) ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3085fb59a0..407c729acc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,7 +96,7 @@ It's much harder to merge in a large change with a lot of disjoint features. 3. Submit the update as a GitHub pull request against the `master` branch. 4. Make sure that you provide docstrings for all your new methods and classes. 5. Add new unit tests for your code ([PR examples](#pr-examples)). -6. Check the [codestyle](#codestyle) +6. (Optional) Check the [codestyle](#codestyle). We use a pre-commit hook that runs the formatting on commit, so you don't have to. 7. Make sure that your code [passes the Github CI](#github-ci) @@ -115,19 +115,33 @@ Please use it as a collaborative platform, if you have any issues during the PR. ### Codestyle We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle) -package to help with code formatting issues. +package to help with code formatting issues, and a corresponding pre-commit hook installed. -You could check the codestyle for your PR with: +To set the hook, please run (this requires `pre-commit` package, pinned in the `requirements-dev.txt`): +```bash +pre-commit install +``` +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: +```bash +pre-commit run +``` +If for some reason you'll want to turn the hook off temporarily, you can do that with: ```bash -catalyst-make-codestyle && catalyst-check-codestyle +SKIP=catalyst-make-codestyle git commit -m "foo" +``` +Or you can uninstall it completely with: +```bash +pre-commit uninstall ``` -Once again, make sure that your python packages complied with `requirements/requirements.txt` and `requirements/requirements-dev.txt` to get codestyle run clean: +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: ```bash pip install -r requirements/requirements.txt -r requirements/requirements-dev.txt ``` +For more information on pre-commit, please refer to [pre-commit documentation](https://pre-commit.com/). + ### Documentation 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). diff --git a/README.md b/README.md index cba55d913b..fa1eb4d08f 100644 --- a/README.md +++ b/README.md @@ -141,24 +141,32 @@ utils.onnx_export(model=runner.model, batch=features_batch, file="./logs/mnist.o ## Table of Contents +- [Getting started](#getting-started) + - [Step-by-step Guide](#step-by-step-guide) +- [Table of Contents](#table-of-contents) - [Overview](#overview) - * [Installation](#installation) - * [Minimal examples](#minimal-examples) - * [Features](#features) - * [Tests](#tests) + - [Installation](#installation) + - [Minimal Examples](#minimal-examples) + - [Features](#features) + - [Tests](#tests) - [Catalyst](#catalyst) - * [Documentation](#documentation) - * [Notebooks](#notebooks) - * [Blog Posts](#notable-blog-posts) - * [Talks](#talks) - * [Projects](#projects) + - [Documentation](#documentation) + - [Notebooks](#notebooks) + - [Notable Blog Posts](#notable-blog-posts) + - [Talks](#talks) + - [Projects](#projects) + - [Examples, Notebooks, and Starter Kits](#examples-notebooks-and-starter-kits) + - [Competitions](#competitions) + - [Research Papers](#research-papers) + - [Toolkits](#toolkits) - [Community](#community) - * [Contribution Guide](#contribution-guide) - * [User Feedback](#user-feedback) - * [Acknowledgments](#acknowledgments) - * [Trusted by](#trusted-by) - * [Supported by](#supported-by) - * [Citation](#citation) + - [Contribution Guide](#contribution-guide) + - [User Feedback](#user-feedback) + - [Acknowledgments](#acknowledgments) + - [Catalyst.Team](#catalystteam) + - [Catalyst.Contributors](#catalystcontributors) + - [Trusted by](#trusted-by) + - [Citation](#citation) ## Overview @@ -1559,7 +1567,7 @@ runner.run() ### Tests All Catalyst code, features, and pipelines [are fully tested](./catalyst/tests). -We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle). +We also have our own [catalyst-codestyle](https://github.com/catalyst-team/codestyle) and a corresponding pre-commit hook. During testing, we train a variety of different models: image classification, image segmentation, text classification, GANs, and much more. diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index 48c6114ca2..bc573266ff 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -7,3 +7,4 @@ mock==3.0.5 catalyst-codestyle==21.03rc2 catalyst-sphinx-theme==1.1.2 toml==0.10.0 +pre-commit==2.13.0