Skip to content

Commit

Permalink
Migrate to Ruff (#21)
Browse files Browse the repository at this point in the history
* Migrate to pyproject.toml

* Migrate to pyproject.toml

* Migrate to pyproject.toml

* Migrate to pyproject.toml

* Migrate to pyproject.toml

* Migrate to pyproject.toml

* Migrate to ruff

* Migrate to ruff

* Correct delta and improve type hints

* Fix validate flow

* Formatting

* more typing

* pylint

* pylint

* pytest

* Update dev requirements

* Update build action and poetry

---------

Co-authored-by: jbouwh <[email protected]>
  • Loading branch information
joostlek and jbouwh authored Jan 4, 2025
1 parent 4abe876 commit 6c99a8c
Show file tree
Hide file tree
Showing 20 changed files with 2,223 additions and 251 deletions.
6 changes: 1 addition & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
# CircleCI 2.1 configuration file for https://github.com/zxdavb/geniushub-client
# Check https://circleci.com/docs/2.0/language-python/ for more details

version: 2.1


jobs:

check_version:
Expand All @@ -17,7 +17,6 @@ jobs:
name: Verify git tag vs. package version
command: python setup.py verify # NOTE: $CIRCLE_TAG is not available to su


check_lint:
docker: *docker_config

Expand All @@ -39,7 +38,6 @@ jobs:
isort --check --diff *client.py
isort --check --diff incomfort*
run_tests:
docker: *docker_config

Expand All @@ -55,7 +53,6 @@ jobs:
- run:
command: pytest tests -v


deploy_package:
docker: *docker_config

Expand All @@ -79,7 +76,6 @@ jobs:
twine upload -r pypi dist/*
workflows:
version: 2

Expand Down
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

155 changes: 155 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
name: Linting

# yamllint disable-line rule:truthy
on:
push:
branches:
- master
pull_request:
workflow_dispatch:

env:
DEFAULT_PYTHON: "3.9"

jobs:
codespell:
name: codespell
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"
- name: 🏗 Install workflow dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install Python dependencies
run: poetry install --no-interaction
- name: 🚀 Check code for common misspellings
run: poetry run pre-commit run codespell --all-files

ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"
- name: 🏗 Install workflow dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install Python dependencies
run: poetry install --no-interaction
- name: 🚀 Run ruff linter
run: poetry run ruff check --output-format=github .
- name: 🚀 Run ruff formatter
run: poetry run ruff format --check .

pre-commit-hooks:
name: pre-commit-hooks
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"
- name: 🏗 Install workflow dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install Python dependencies
run: poetry install --no-interaction
- name: 🚀 Check Python AST
run: poetry run pre-commit run check-ast --all-files
- name: 🚀 Check for case conflicts
run: poetry run pre-commit run check-case-conflict --all-files
- name: 🚀 Check docstring is first
run: poetry run pre-commit run check-docstring-first --all-files
- name: 🚀 Check that executables have shebangs
run: poetry run pre-commit run check-executables-have-shebangs --all-files
- name: 🚀 Check JSON files
run: poetry run pre-commit run check-json --all-files
- name: 🚀 Check for merge conflicts
run: poetry run pre-commit run check-merge-conflict --all-files
- name: 🚀 Check for broken symlinks
run: poetry run pre-commit run check-symlinks --all-files
- name: 🚀 Check TOML files
run: poetry run pre-commit run check-toml --all-files
- name: 🚀 Check XML files
run: poetry run pre-commit run check-xml --all-files
- name: 🚀 Check YAML files
run: poetry run pre-commit run check-yaml --all-files
- name: 🚀 Detect Private Keys
run: poetry run pre-commit run detect-private-key --all-files
- name: 🚀 Check End of Files
run: poetry run pre-commit run end-of-file-fixer --all-files
- name: 🚀 Trim Trailing Whitespace
run: poetry run pre-commit run trailing-whitespace --all-files

pylint:
name: pylint
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"
- name: 🏗 Install workflow dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install Python dependencies
run: poetry install --no-interaction
- name: 🚀 Run pylint
run: poetry run pre-commit run pylint --all-files

yamllint:
name: yamllint
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"
- name: 🏗 Install workflow dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install Python dependencies
run: poetry install --no-interaction
- name: 🚀 Run yamllint
run: poetry run yamllint .
10 changes: 7 additions & 3 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
# This workflow will upload a Python Package using Twine when a release is created
# yamllint disable-line rule:line-length
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
Expand All @@ -8,9 +10,11 @@

name: Upload Python Package incomfort-client

# yamllint disable-line rule:truthy
on:
release:
types: [published]
types:
- published
branches:
- master

Expand All @@ -28,9 +32,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install build poetry-core
- name: Build package
run: python setup.py sdist bdist_wheel
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
Expand Down
67 changes: 35 additions & 32 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
---
name: Python application validation

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application validation

# yamllint disable-line rule:truthy
on:
push:
branches: [ "master" ]
branches:
- master
pull_request:
branches: [ "master" ]
branches:
- master

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=C,E,F,W,B,B950 --ignore=E203,E501,W503 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
- name: "Check formatting 1: black"
run: |
black --diff --check *client.py
black --diff --check incomfort*
- name: "Check formatting 2: isort"
run: |
isort --check --diff *client.py
isort --check --diff incomfort*
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=C,E,F,W,B,B950 --ignore=E203,E501,W503 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
- name: "Check formatting 1: black"
run: |
black --diff --check *client.py
black --diff --check src/incomfort*
- name: "Check formatting 2: isort"
run: |
isort --check --diff *client.py
isort --check --diff src/incomfort*
- name: Test with pytest
run: |
pytest
5 changes: 0 additions & 5 deletions .hound.yml

This file was deleted.

Loading

0 comments on commit 6c99a8c

Please sign in to comment.