Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff as linter and code formatter #106

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ repos:
hooks:
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.11"
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/psf/black
rev: "23.12.1"
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Test and build](https://github.com/ImperialCollegeLondon/pip-tools-template/actions/workflows/ci.yml/badge.svg)](https://github.com/ImperialCollegeLondon/pip-tools-template/actions/workflows/ci.yml)

This is a minimal Python 3.10 application that uses [`pip-tools`] for packaging and dependency management. It also provides [`pre-commit`](https://pre-commit.com/) hooks (for [`isort`](https://pycqa.github.io/isort/), [`black`](https://black.readthedocs.io/en/stable/), [`flake8`](https://flake8.pycqa.org/en/latest/) and [`mypy`](https://mypy.readthedocs.io/en/stable/)) and automated tests using [`pytest`](https://pytest.org/) and [GitHub Actions](https://github.com/features/actions). Pre-commit hooks are automatically kept updated with a dedicated GitHub Action, this can be removed and replace with [pre-commit.ci](https://pre-commit.ci) if using an public repo. It was developed by the [Imperial College Research Computing Service](https://www.imperial.ac.uk/admin-services/ict/self-service/research-support/rcs/).
This is a minimal Python 3.10 application that uses [`pip-tools`] for packaging and dependency management. It also provides [`pre-commit`](https://pre-commit.com/) hooks (for for [ruff](https://pypi.org/project/ruff/) and [`mypy`](https://mypy.readthedocs.io/en/stable/)) and automated tests using [`pytest`](https://pytest.org/) and [GitHub Actions](https://github.com/features/actions). Pre-commit hooks are automatically kept updated with a dedicated GitHub Action, this can be removed and replace with [pre-commit.ci](https://pre-commit.ci) if using an public repo. It was developed by the [Imperial College Research Computing Service](https://www.imperial.ac.uk/admin-services/ict/self-service/research-support/rcs/).

[`pip-tools`] is chosen as a lightweight dependency manager that adheres to the [latest standards](https://peps.python.org/pep-0621/) using `pyproject.toml`.

Expand Down Expand Up @@ -72,8 +72,7 @@ for this are:
- The build system (change from setuptools to other packaging tools like [Hatch](https://hatch.pypa.io/) or [flit](https://flit.pypa.io/)).
- The python version.
- The project dependencies. Extra optional dependencies can be added by adding another list under `[project.optional-dependencies]` (i.e. `doc = ["mkdocs"]`).
- The `mypy`, `isort` and `pytest` configurations.
- The `.flake8` file for `flake8` configuration.
- The `mypy` and `pytest` configurations.
- The `.pre-commit-config.yaml` for pre-commit settings.
- The `.github` directory for all the CI configuration.
- This repo uses `pre-commit.ci` to update pre-commit package versions and automatically merges those PRs with the `auto-merge.yml` workflow.
Expand Down
54 changes: 7 additions & 47 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,78 +1,49 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=dev --output-file=dev-requirements.txt
#
attrs==23.1.0
# via pytest-mypy
black==23.7.0
# via datahub (pyproject.toml)
build==1.0.3
# via pip-tools
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via
# black
# pip-tools
# via pip-tools
coverage[toml]==7.3.2
# via pytest-cov
distlib==0.3.7
# via virtualenv
exceptiongroup==1.1.3
# via pytest
filelock==3.12.4
# via
# pytest-mypy
# virtualenv
flake8==6.1.0
# via
# datahub (pyproject.toml)
# flake8-docstrings
flake8-docstrings==1.7.0
# via datahub (pyproject.toml)
identify==2.5.27
# via pre-commit
iniconfig==2.0.0
# via pytest
isort==5.13.2
# via datahub (pyproject.toml)
mccabe==0.7.0
# via flake8
mypy==1.8.0
# via
# datahub (pyproject.toml)
# pytest-mypy
mypy-extensions==1.0.0
# via
# black
# mypy
# via mypy
nodeenv==1.8.0
# via pre-commit
packaging==23.2
# via
# black
# build
# pytest
pathspec==0.12.1
# via black
pip-tools==7.3.0
# via datahub (pyproject.toml)
platformdirs==3.11.0
# via
# black
# virtualenv
# via virtualenv
pluggy==1.3.0
# via pytest
pre-commit==3.5.0
# via datahub (pyproject.toml)
pycodestyle==2.11.0
# via flake8
pydocstyle==6.3.0
# via flake8-docstrings
pyflakes==3.1.0
# via flake8
pyproject-hooks==1.0.0
# via build
pytest==7.4.3
Expand All @@ -89,21 +60,10 @@ pytest-mypy==0.10.3
# via datahub (pyproject.toml)
pyyaml==6.0.1
# via pre-commit
snowballstemmer==2.2.0
# via pydocstyle
tomli==2.0.1
# via
# black
# build
# coverage
# mypy
# pip-tools
# pyproject-hooks
# pytest
ruff==0.1.11
# via datahub (pyproject.toml)
typing-extensions==4.9.0
# via
# filelock
# mypy
# via mypy
virtualenv==20.24.5
# via pre-commit
wheel==0.41.3
Expand Down
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ dependencies = []

[project.optional-dependencies]
dev = [
"black",
"flake8",
"flake8-docstrings",
"isort",
"ruff",
"mypy",
"pip-tools",
"pre-commit",
Expand All @@ -42,8 +39,14 @@ exclude = [".venv/"]
module = "tests.*"
disallow_untyped_defs = false

[tool.isort]
profile = "black"

[tool.pytest.ini_options]
addopts = "-v --mypy -p no:warnings --cov=myproject --cov-report=html --doctest-modules --ignore=myproject/__main__.py"

[tool.ruff]
select = ["D", "E", "F", "I"] # pydocstyle, pycodestyle, Pyflakes, isort

[tool.ruff.per-file-ignores]
"tests/*" = ["D100", "D104"]

[tool.ruff.pydocstyle]
convention = "google"
Loading