From 2c29aea9f181783e884ea1df89840bc72be04a5e Mon Sep 17 00:00:00 2001 From: Ross Smith Date: Thu, 1 Feb 2024 14:25:18 +0000 Subject: [PATCH] Add Pre-commit hook (#244) * Move tests to root * Pre-Commit Hook * remove pytest.ini * Add dev requirements to build * Add contributing guide --- .devcontainer/devcontainer.json | 2 +- .devcontainer/postCreate.sh | 9 +++++++++ .github/workflows/unittests.yml | 2 +- .pre-commit-config.yaml | 12 ++++++++++++ CONTRIBUTING.md | 1 + code/dev-requirements.txt | 5 +++++ code/requirements.txt | 3 --- 7 files changed, 29 insertions(+), 5 deletions(-) create mode 100755 .devcontainer/postCreate.sh create mode 100644 .pre-commit-config.yaml create mode 100644 code/dev-requirements.txt diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 041452c0f..6e66ca3a3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,7 +12,7 @@ } }, - "postCreateCommand": "pip install -r code/requirements.txt -r code/app/requirements.txt -r extensions/backend/requirements.txt", + "postCreateCommand": "./.devcontainer/postCreate.sh", "customizations": { "vscode": { diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100755 index 000000000..7ddfb824f --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +pip install --upgrade pip + +pip install -r code/requirements.txt -r code/app/requirements.txt -r extensions/backend/requirements.txt + +pip install -r code/dev-requirements.txt + +pre-commit install \ No newline at end of file diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index ef153c6ba..eb0cefec8 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -20,6 +20,6 @@ jobs: architecture: x64 - name: Install dependencies run: | - pip install -r code/requirements.txt + pip install -r code/requirements.txt -r code/dev-requirements.txt - name: Run Python tests run: python -m pytest --rootdir=code -m "not azure" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bc2f44220 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +repos: + - repo: https://github.com/psf/black + rev: 23.12.1 + hooks: + - id: black + language_version: python3 + + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + args: [--extend-ignore=E501] \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bdc1de933..4f2294404 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,6 +62,7 @@ Before you submit your Pull Request (PR) consider the following guidelines: * Make your changes in a new git fork: * Commit your changes using a descriptive commit message +* If you are using the devcontainer, committing code will run black and flake8 to lint python code. You can run `black .` or `flake8 .` at anytime. * Push your fork to GitHub: * In GitHub, create a pull request * If we suggest changes then: diff --git a/code/dev-requirements.txt b/code/dev-requirements.txt new file mode 100644 index 000000000..4f41e9faf --- /dev/null +++ b/code/dev-requirements.txt @@ -0,0 +1,5 @@ +pytest==8.0.0 +pytest-cov==4.1.0 +flake8==7.0.0 +pre-commit==3.5.0 +black==23.12.1 diff --git a/code/requirements.txt b/code/requirements.txt index a8bde1266..d8dee40b9 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -23,6 +23,3 @@ azure-search-documents==11.4.0b8 opencensus-ext-azure==1.1.13 pandas==2.2.0 python-docx==1.1.0 - -# Add dev dependencies here - this will be refactored out by Poetry -pytest==8.0.0