Skip to content

Commit

Permalink
Add pre-commit hook following icefall convention (#72)
Browse files Browse the repository at this point in the history
* Add pre-commit hook following icefall convention

* Add style check CI from icefall

* Add python style check
  • Loading branch information
ezerhouni authored Jul 22, 2022
1 parent f70613e commit 85ad46e
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/python_style_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2021 Fangjun Kuang (csukuangfj@gmail.com)

# See ../../LICENSE for clarification regarding multiple authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: python_style_check

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
style_check:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, macos-10.15]
python-version: [3.7, 3.9]
fail-fast: false

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip black==21.6b0 flake8==3.9.2 click==8.0.4
# See https://github.com/psf/black/issues/2964
# The version of click should be selected from 8.0.0, 8.0.1, 8.0.2, 8.0.3, and 8.0.4
- name: Run flake8
shell: bash
working-directory: ${{github.workspace}}
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --show-source --statistics
flake8 .
- name: Run black
shell: bash
working-directory: ${{github.workspace}}
run: |
black --check --diff .
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: https://github.com/psf/black
rev: 21.6b0
hooks:
- id: black
args: [--line-length=80]
additional_dependencies: ['click==8.0.1']
exclude: icefall\/__init__\.py

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
args: [--max-line-length=80]

- repo: https://github.com/pycqa/isort
rev: 5.9.2
hooks:
- id: isort
args: [--profile=black, --line-length=80]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-executables-have-shebangs
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,30 @@ Errors: 112 insertions, 93 deletions, 876 substitutions, over 52576 reference wo
If you have a GPU with a larger RAM (e.g., 32 GB), you can get an even **lower** RTF.

[icefall]: https://github.com/k2-fsa/icefall/


### Contributing

Contributions to ```sherpa``` are very welcomed. There are many possible ways to make contributions
and two of them are:
- To write documentation
- To write code:
- To follow the code style in the repository
- To write a new features (support new architectures, new beam search, etc)

### Follow the code style

We use the following tools to make the code style to be as consistent as possible:

- [black](https://github.com/psf/black), to format the code
- [flake8](https://github.com/PyCQA/flake8), to check the style and quality of the code
- [isort](https://github.com/PyCQA/isort), to sort ``imports``

After running the following commands:

$ git clone https://github.com/k2-fsa/sherpa
$ cd sherpa
$ pip install pre-commit
$ pre-commit install

it will run the checks whenever you run ``git commit`` **automatically**

0 comments on commit 85ad46e

Please sign in to comment.