synapse-alpha / mirror-neuron

Experiments on bittensor reward models to find exploits
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

Add pre-commit hooks #47

Open steffencruz opened 1 year ago

steffencruz commented 1 year ago

Because you know you should

steffencruz commented 1 year ago

Pre-push hooks are another option

steffencruz commented 1 year ago
  1. Black
  2. Pylint
  3. mypy/pydantic
  4. trailing whitespace
ifrit98 commented 1 year ago

RE: 4.

function remove_trailing_whitespace() {
    if [ -d "$1" ]; then
        find "$1" -type f -name "*.py" -exec sed -i 's/[ \t]*$//' {} \;
        echo "Trailing whitespace removed from all Python files in the directory: $1"
    else
        echo "Directory not found: $1"
    fi
}

Add to ~/.bashrc

Usage:

remove_trailing_whitespace /path/to/your/project
steffencruz commented 1 year ago

Cool solution! There's actually a simple way to do this within the pre-commit hooks

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    -   id: check-yaml
    -   id: end-of-file-fixer
    -   id: trailing-whitespace  # <--------------------THIS BAD BOI
-   repo: https://github.com/psf/black
    rev: 22.3.0
    hooks:
    -   id: black
        args: [-l 120]
        types: [python]
-   repo: https://github.com/PyCQA/flake8
    rev: 5.0.4
    hooks:
    -   id: flake8
        args: [--count, --select=E9, --select=F63, --select=F7, --select=F82, --show-source, --statistics]
        types: [python]