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: 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 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 diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 6f819915..441f1554 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -284,7 +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 = [