The galois library uses Ruff for static analysis, linting, and code formatting.


First, ruff needs to be installed on your system. Easily install it by installing the development dependencies.

$ python3 -m pip install -r requirements-dev.txt


The ruff configuration is provided in pyproject.toml.

src = ["src"]
extend-include = ["*.ipynb"]
extend-exclude = ["build", "dist", "docs", "src/galois/"]
line-length = 120

select = [
    "E",  # pycodestyle
    "F",  # Pyflakes
    "UP", # pyupgrade
    "B",  # flake8-bugbear
    # "SIM",# flake8-simplify
    "I",  # isort
    "PL", # pylint
ignore = [
    "E501",    # line-too-long
    "E713",    # not-in-test
    "E714",    # not-is-test
    "E741",    # ambiguous-variable-name
    "PLR0911", # too-many-return-statements
    "PLR0912", # too-many-branches
    "PLR0913", # too-many-arguments
    "PLR0915", # too-many-statements
    "PLR2004", # magic-value-comparison
    "PLR5501", # collapsible-else-if
    "PLW0603", # global-statement
    "PLW2901", # redefined-loop-name

"" = ["F401", "F403"]

Run the linter

Run the Ruff linter manually from the command line.

$ python3 -m ruff check .

Run the formatter

Run the Ruff formatter manually from the command line.

$ python3 -m ruff format --check .


A pre-commit configuration file with various hooks is provided in .pre-commit-config.yaml.

- repo:
  rev: v2.3.0
  - id: check-added-large-files
  - id: check-yaml
  - id: check-toml
  - id: end-of-file-fixer
  - id: trailing-whitespace
- repo:
  rev: v0.1.15
  - id: ruff
  - id: ruff-format

Enable pre-commit by installing the pre-commit hooks.

$ pre-commit install

Run pre-commit on all files.

$ pre-commit run --all-files

Disable pre-commit by uninstalling the pre-commit hooks.

$ pre-commit uninstall

Run from VS Code

Install the Ruff extension for VS Code. Included is a VS Code configuration file .vscode/settings.json. VS Code will run the linter and formatter as you view and edit files.

Last update: Feb 01, 2024