crismc / rpi_i2c_oled

Python library to enable 128x32 pixel OLED for Raspberry Pi (both 32 and 64bit).
MIT License
13 stars 10 forks source link

[Feature]: Run ruff formatter on codebase #15

Open rsnodgrass opened 3 months ago

rsnodgrass commented 3 months ago

Is your feature request related to a problem?

Code quality improvements.

Describe the solution you'd like

Run ruff formatter on all *.py files. Also should set the target Python version for the code repository in pyproject.toml (e.g. 3.10?) so when various code checking and formatting tools run they know what syntax is valid.

Describe alternatives you've considered

Ruff is starting to replace usage of the long-standing black8 and brunette formatters.

Additional context

Recommend adding .pre-commit-config.yaml in project root with the following once ruff has been run, so those that use pre-commit will ensure that new code automatically is formatted to the project's standards as well.

---
# pre-commit autoupdate

fail_fast: true

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer

  # isort - sort import statements
  - repo: https://github.com/pycqa/isort
    rev: 5.13.2
    hooks:
      - id: isort
        files: \.(py)$
        args: [--settings-path=pyproject.toml]  # ["--profile", "black" ]

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.4.4
    hooks:
      - id: ruff
        args: [ --fix ]  # run linter
      - id: ruff-format  # run formatter

  #### OPTIONAL: for keeping syntax more current

  - repo: https://github.com/asottile/pyupgrade
    rev: v3.15.2
    hooks:
      - id: pyupgrade
        args: [--py310-plus] # keep 2 versions behind current

  - repo: https://github.com/dosisod/refurb
    rev: v2.0.0
    hooks:
      - id: refurb
rsnodgrass commented 3 months ago

See more at https://github.com/astral-sh/ruff

Could also add the GitHub workflow https://github.com/chartboost/ruff-action to send warnings on merges of new code that has not been formatted.