From 12e87f5322f9f5ca8fec1692dc255966c079d46f Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 3 Jul 2023 09:01:40 +0200 Subject: [PATCH 1/5] feat: allow automatic inference of ruff version Signed-off-by: burgholzer --- src/sp_repo_review/checks/ruff.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sp_repo_review/checks/ruff.py b/src/sp_repo_review/checks/ruff.py index fb1e0b6c..1ac24a2f 100644 --- a/src/sp_repo_review/checks/ruff.py +++ b/src/sp_repo_review/checks/ruff.py @@ -40,12 +40,14 @@ class RF002(Ruff): def check(pyproject: dict[str, Any]) -> bool: """ Must select a minimum version to target. Affects pyupgrade, - isort, and others. + isort, and others. Can be inferred from `project.requires-python`. """ match pyproject: case {"tool": {"ruff": {"target-version": str()}}}: return True + case {"project": {"requires-python": str()}}: + return True case _: return False From b4faba563269ec299aa7531f97b09d96fcab6828 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 3 Jul 2023 09:08:33 +0200 Subject: [PATCH 2/5] chore: update template for automatic ruff target-version inference Signed-off-by: burgholzer --- {{cookiecutter.project_name}}/pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 6f819915..52e0dbd8 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -284,7 +284,6 @@ extend-ignore = [ "PLR", # Design related pylint codes "E501", # Line too long ] -target-version = "py38" typing-modules = ["{{ cookiecutter.__project_slug }}._compat.typing"] src = ["src"] unfixable = [ From 0ac9a082faf69b50caff743780ff01d87c4fde3d Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 3 Jul 2023 09:10:21 +0200 Subject: [PATCH 3/5] chore: update project for automatic ruff target-version inference Signed-off-by: burgholzer --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6e53c085..e19f54c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -160,7 +160,6 @@ extend-ignore = [ "E501", # Line too long "PT004", # Incorrect check, usefixtures is the correct way to do this ] -target-version = "py310" src = ["src"] unfixable = [ "T20", # Removes print statements From 0c2ddd6dc6c04510f8075af98f14866c0bdfd004 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Mon, 3 Jul 2023 09:35:37 +0200 Subject: [PATCH 4/5] fix: include target-version where requires-python is not specified in pyproject.toml Signed-off-by: burgholzer --- {{cookiecutter.project_name}}/pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 52e0dbd8..441f1554 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -284,6 +284,9 @@ extend-ignore = [ "PLR", # Design related pylint codes "E501", # Line too long ] +{%- if cookiecutter.backend in ["setuptools", "pybind11", "poetry"] %} +target-version = "py38" +{%- endif %} typing-modules = ["{{ cookiecutter.__project_slug }}._compat.typing"] src = ["src"] unfixable = [ From 933938dd3de14774b6e7f01177e2202bd54be8ee Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 3 Jul 2023 08:35:00 -0400 Subject: [PATCH 5/5] docs: update guidelines too Signed-off-by: Henry Schreiner --- docs/pages/guides/style.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/pages/guides/style.md b/docs/pages/guides/style.md index 9c83dd3a..82748606 100644 --- a/docs/pages/guides/style.md +++ b/docs/pages/guides/style.md @@ -205,7 +205,6 @@ extend-ignore = [ "E501", # Line too long "PT004", # Use underscore for non-returning fixture (use usefixture instead) ] -target-version = "py38" typing-modules = ["mypackage._compat.typing"] src = ["src"] unfixable = [ @@ -229,16 +228,27 @@ ignore certain error codes via `extend-ignore`. You can also set codes per paths to ignore in `per-file-ignores`. If you don't like certain auto-fixes, you can disable auto-fixing for specific error codes via `unfixable`. -There are other configuration options, such as `target-version`, which selects -the minimum version you want to target (primarily for `"UP"` and `"I"`) -{% rr RF002 %}, the `src` list which tells it where to look for top level -packages (mostly for "I" codes, which also have a lot of custom configuration -options) {% rr RF003 %}, `typing-modules`, which helps apply typing-specific -rules to a re-exported typing module (a common practice for unifying typing and -`typing_extensions` based on Python version). There's also a file `exclude` set, -which you can override if you are running this entirely from pre-commit (default -excludes include "build", so if you have a `build` module or file named -`build.py`, it would get skipped by default without this). +There are other configuration options, such as the `src` list which tells it +where to look for top level packages (mostly for "I" codes, which also have a +lot of custom configuration options) {% rr RF003 %}, `typing-modules`, which +helps apply typing-specific rules to a re-exported typing module (a common +practice for unifying typing and `typing_extensions` based on Python version). +There's also a file `exclude` set, which you can override if you are running +this entirely from pre-commit (default excludes include "build", so if you have +a `build` module or file named `build.py`, it would get skipped by default +without this). + +{: .warning } + +> If you don't use a `[project]` table (older setuptools or Poetry), then you +> should also set: +> +> ```toml +> target-version = "py38" +> ``` +> +> This selects the minimum version you want to target (primarily for `"UP"` and +> `"I"`) {% rr RF002 %}, Here are some good error codes to enable on most (but not all!) projects: