Skip to content

Commit

Permalink
Document Ruff linting, formatting, and pre-commit
Browse files Browse the repository at this point in the history
Fixes #518
  • Loading branch information
mhostetter committed Nov 4, 2023
1 parent 7157bef commit 68183fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 41 deletions.
77 changes: 77 additions & 0 deletions docs/development/formatting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Formatting
==========

The :obj:`galois` library uses `Ruff <https://docs.astral.sh/ruff/>`_ for static analysis, linting, and code
formatting.

Install
-------

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

.. code-block:: console
$ python3 -m pip install -r requirements-dev.txt
Configuration
-------------

The `ruff` configuration is provided in `pyproject.toml`.

.. literalinclude:: ../../pyproject.toml
:caption: pyproject.toml
:start-at: [tool.ruff]
:end-before: [tool.pytest.ini_options]
:language: toml

Run the linter
--------------

Run the Ruff linter manually from the command line.

.. code-block:: console
$ python3 -m ruff check .
Run the formatter
-----------------

Run the Ruff formatter manually from the command line.

.. code-block:: console
$ python3 -m ruff format --check .
Pre-commit
----------

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

.. literalinclude:: ../../.pre-commit-config.yaml
:caption: .pre-commit-config.yaml
:language: yaml

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

.. code-block:: console
$ pre-commit install
Run `pre-commit` on all files.

.. code-block:: console
$ pre-commit run --all-files
Disable `pre-commit` by uninstalling the pre-commit hooks.

.. code-block:: console
$ pre-commit uninstall
Run from VS Code
----------------

Install the `Ruff extension <https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff>`_ 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.
40 changes: 0 additions & 40 deletions docs/development/linter.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ If this library was useful to you in your research, please cite us. Following th
:hidden:

development/installation.rst
development/linter.rst
development/formatting.rst
development/unit-tests.rst
development/documentation.rst

Expand Down

0 comments on commit 68183fa

Please sign in to comment.