From 4fe1a996135a5ac9283b0e6a0a5b2df164242893 Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Tue, 5 Sep 2023 12:38:56 +0200 Subject: [PATCH] chore: Update CI configs to use pre-commit (#22) * ci: Install libsnappy-dev in test workflows --- .github/workflows/default.yml | 110 ++-------------------------------- .pre-commit-config.yaml | 22 +++++++ requirements/dev.txt | 2 +- setup.py | 1 + 4 files changed, 30 insertions(+), 105 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index b164a51..85ee718 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -3,106 +3,6 @@ name: default on: [push, pull_request] jobs: - lint-flake8: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10.8" - cache: pip - cache-dependency-path: | - setup.py - requirements/lint.txt - - name: Install dependencies - run: | - python -m pip install -U pip setuptools wheel - python -m pip install -U -r requirements/lint.txt - - name: Lint with flake8 - run: | - if [ "$GITHUB_EVENT_NAME" == "pull_request" -a -n "$GITHUB_HEAD_REF" ]; then - echo "(skipping matchers for pull request from local branches)" - else - echo "::add-matcher::.github/workflows/flake8-matcher.json" - fi - python -m flake8 src tests setup.py - - lint-black: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10.8" - cache: pip - cache-dependency-path: | - setup.py - requirements/lint.txt - - name: Install dependencies - run: | - python -m pip install -U pip setuptools wheel - python -m pip install -U -r requirements/lint.txt - - name: Lint with black - run: | - python -m black --check src tests setup.py - - lint-isort: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10.8" - cache: pip - cache-dependency-path: | - setup.py - requirements/lint.txt - - name: Install dependencies - run: | - python -m pip install -U pip setuptools wheel - python -m pip install -U -r requirements/lint.txt - - name: Lint with isort - run: | - python -m isort --check src tests setup.py - - typecheck-mypy: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.10.8" - cache: pip - cache-dependency-path: | - setup.py - requirements/typecheck.txt - - name: Install dependencies - run: | - python -m pip install -U pip setuptools wheel - python -m pip install -U -r requirements/typecheck.txt - - name: Type check with mypy - run: | - if [ "$GITHUB_EVENT_NAME" == "pull_request" -a -n "$GITHUB_HEAD_REF" ]; then - echo "(skipping matchers for pull request from local branches)" - else - echo "::add-matcher::.github/workflows/mypy-matcher.json" - fi - python -m mypy --no-color-output src/callosum test-unit: @@ -124,13 +24,14 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10.8" + python-version: "3.11.4" cache: pip cache-dependency-path: | setup.py requirements/test.txt - name: Install dependencies run: | + sudo apt install -y libsnappy-dev python -m pip install -U pip setuptools wheel python -m pip install -U -e ".[build,test,zeromq,redis,thrift,snappy]" - name: Run unit tests @@ -162,13 +63,14 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10.8" + python-version: "3.11.4" cache: pip cache-dependency-path: | setup.py requirements/test.txt - name: Install dependencies run: | + sudo apt install -y libsnappy-dev python -m pip install -U pip setuptools wheel python -m pip install -U -e ".[build,test,zeromq,redis,thrift,snappy]" - name: Run integration tests @@ -179,7 +81,7 @@ jobs: ./scripts/run-integration-tests.sh deploy-to-pypi: - needs: [lint-flake8, lint-black, lint-isort, typecheck-mypy, test-unit, test-integration] + needs: [test-unit, test-integration] if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') runs-on: ubuntu-latest @@ -191,7 +93,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10.8" + python-version: "3.11.4" cache: pip cache-dependency-path: | setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d47fef2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +ci: + autoupdate_schedule: quarterly +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy diff --git a/requirements/dev.txt b/requirements/dev.txt index 55cca3b..880389e 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1 +1 @@ --e .[build,lint,typecheck,test] +-e .[build,dev,lint,typecheck,test] diff --git a/setup.py b/setup.py index ab58366..85002e7 100644 --- a/setup.py +++ b/setup.py @@ -41,6 +41,7 @@ def read_src_version(): dev_requires: List[str] = [ # 'pytest-sugar', + "pre-commit", ] lint_requires = [