Skip to content

Commit

Permalink
Set up pre-commit (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored Oct 16, 2023
1 parent 4c41c10 commit 15ae65e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
args:
- --quiet
files: ^((zwave_js_server|scripts|test)/.+)?[^/]+\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: no-commit-to-branch
args:
- --branch=master
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
files: ^(zwave_js_server|test)/.+\.py$
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
files: ^((zwave_js_server|test)/.+)?[^/]+\.py$
- repo: local
hooks:
- id: mypy
name: mypy
entry: scripts/run-in-env.sh mypy
language: script
types: [python]
require_serial: true
files: ^(zwave_js_server)/.+\.py$
- id: pylint
name: pylint
entry: scripts/run-in-env.sh pylint -j 0 --ignore-missing-annotations=y
language: script
types: [python]
files: ^zwave_js_server/.+\.py$
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Python library for communicating with [zwave-js-server](https://github.com/zwave-js/zwave-js-server/). Goal for this library is to replicate the structure and the events of Z-Wave JS 1:1. So it has a `Driver`, `Controller` and `Node` classes.

## Setup development environment

To setup your development environment, run `scripts/setup`, which will install all requirements and set up pre-commit checks.

## Trying it out

```shell
Expand Down
1 change: 1 addition & 0 deletions requirements_lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mypy==1.5.1
pydocstyle==6.3.0
pylint==3.0.1
pylint-strict-informational==0.1
pre-commit==3.5.0
22 changes: 22 additions & 0 deletions scripts/run-in-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env sh
set -eu

# Activate pyenv and virtualenv if present, then run the specified command

# pyenv, pyenv-virtualenv
if [ -s .python-version ]; then
PYENV_VERSION=$(head -n 1 .python-version)
export PYENV_VERSION
fi

# other common virtualenvs
my_path=$(git rev-parse --show-toplevel)

for venv in venv .venv .; do
if [ -f "${my_path}/${venv}/bin/activate" ]; then
. "${my_path}/${venv}/bin/activate"
break
fi
done

exec "$@"
14 changes: 14 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Setups the repository.

# Stop on errors
set -e

if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ];then
python3 -m venv venv
source venv/bin/activate
fi

python3 -m pip install -r requirements_dev.txt

pre-commit install

0 comments on commit 15ae65e

Please sign in to comment.