From 15ee665226c968d2acda209e8da73b365bd502b1 Mon Sep 17 00:00:00 2001 From: Henry Cooksley Date: Fri, 21 Jun 2024 14:00:27 +0100 Subject: [PATCH 1/2] Add ruff unused import check to pre-commit and CI --- .circleci/config.yml | 27 ++++++++++++++++++--------- .pre-commit-config.yaml | 7 +++++++ pyproject.toml | 5 ++++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c70ee481..0fbde60c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: - save_cache: paths: - - ./venv + - ./.venv key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} - run: @@ -60,7 +60,7 @@ jobs: - run: name: Upload code coverage command: ./codecov - + tests_postgres13: docker: - image: cimg/python:3.8.17 @@ -105,7 +105,7 @@ jobs: - save_cache: paths: - - ./venv + - ./.venv key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} - run: @@ -127,18 +127,15 @@ jobs: steps: - checkout + - run: pipenv install pre-commit + - restore_cache: - key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} + key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum ".pre-commit-config.yaml" }} - run: name: Install Dependencies command: pipenv sync --dev - - save_cache: - paths: - - ./venv - key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} - - run: name: Prospector command: pipenv run prospector -W pylint -W pep257 @@ -156,6 +153,18 @@ jobs: command: | pipenv run bandit -c bandit.yaml -r . + - run: + name: Ruff + command: pipenv run pre-commit run ruff --from-ref origin/HEAD --to-ref HEAD + + - save_cache: + paths: + - ./.venv + - ~/.cache/pre-commit + # the cache key changes whenever any of the branch name, Pipfile.lock checksum, or .pre-commit-config.yaml checksum change + key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum ".pre-commit-config.yaml" }} + + workflows: version: 2 test: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bae5439b..50c81b1b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,12 @@ exclude: (exporter/assets/built/|caseworker/assets/built/) repos: + # ruff-pre-commit docs recommend running ruff before black + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.4 + hooks: + # Config for ruff lives in pyproject.toml + - id: ruff + args: [ --fix ] - repo: https://github.com/psf/black rev: 22.3.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 54fd24a7..7877461a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [tool.black] line-length = 120 -target-version = ['py36', 'py37', 'py38'] +target-version = ['py38'] include = '\.pyi?$' exclude = ''' /( @@ -27,3 +27,6 @@ exclude = ''' [tool.isort] profile = 'black' line_length = 120 # To match Black's line-length above. + +[tool.ruff.lint] +select = ["F401"] From 8706c8a31638a15b96c7081b06f58be62ab96718 Mon Sep 17 00:00:00 2001 From: Henry Cooksley Date: Fri, 21 Jun 2024 14:11:00 +0100 Subject: [PATCH 2/2] Check that caching is working correctly --- .circleci/config.yml | 6 +++--- .pre-commit-config.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0fbde60c..54cce876 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: - save_cache: paths: - - ./.venv + - ./venv key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} - run: @@ -105,7 +105,7 @@ jobs: - save_cache: paths: - - ./.venv + - ./venv key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }} - run: @@ -159,7 +159,7 @@ jobs: - save_cache: paths: - - ./.venv + - ./venv - ~/.cache/pre-commit # the cache key changes whenever any of the branch name, Pipfile.lock checksum, or .pre-commit-config.yaml checksum change key: dependencies-{{ .Branch }}-{{ checksum "Pipfile.lock" }}-{{ checksum ".pre-commit-config.yaml" }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50c81b1b..c001ff39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ exclude: (exporter/assets/built/|caseworker/assets/built/) repos: - # ruff-pre-commit docs recommend running ruff before black + # ruff-pre-commit docs recommend running ruff before black - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.4 hooks: