From f3ba1a7a84f59f6acbf8d22c17e39e2f34df2ebc Mon Sep 17 00:00:00 2001 From: Kiran Jonnalagadda Date: Tue, 14 May 2024 02:17:10 +0530 Subject: [PATCH] Import markdown from coaster.utils; revise Ruff config --- .pre-commit-config.yaml | 2 +- pyproject.toml | 88 +++++++++++----------------------------- src/baseframe/filters.py | 3 +- 3 files changed, 26 insertions(+), 67 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d30723e4..9b83f66b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: check-pre-commit-ci-config - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.3 + rev: v0.4.4 hooks: - id: ruff args: ['--fix', '--exit-non-zero-on-fix'] diff --git a/pyproject.toml b/pyproject.toml index 32046396..cd9a00bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -173,64 +173,6 @@ exclude_dirs = ['node_modules'] skips = ['*/*_test.py', '*/test_*.py'] [tool.ruff] -# This is a slight customisation of the default rules -# 1. Funnel still targets Python 3.7 pending an upgrade of production environment -# 2. Rule E402 (module-level import not top-level) is disabled as isort handles it -# 3. Rule E501 (line too long) is left to Black; some strings are worse for wrapping - -# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. -lint.select = ["E", "F"] -lint.ignore = ["E402", "E501"] - -# Allow autofix for all enabled rules (when `--fix`) is provided. -lint.fixable = [ - "A", - "B", - "C", - "D", - "E", - "F", - "G", - "I", - "N", - "Q", - "S", - "T", - "W", - "ANN", - "ARG", - "BLE", - "COM", - "DJ", - "DTZ", - "EM", - "ERA", - "EXE", - "FBT", - "ICN", - "INP", - "ISC", - "NPY", - "PD", - "PGH", - "PIE", - "PL", - "PT", - "PTH", - "PYI", - "RET", - "RSE", - "RUF", - "SIM", - "SLF", - "TCH", - "TID", - "TRY", - "UP", - "YTT", -] -lint.unfixable = [] - # Exclude a variety of commonly ignored directories. exclude = [ ".bzr", @@ -258,15 +200,30 @@ exclude = [ # Same as Black. line-length = 88 -# Allow unused variables when underscore-prefixed. -lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" - # Target Python 3.9 target-version = "py39" -[tool.ruff.lint.mccabe] -# Unlike Flake8, default to a complexity level of 10. -max-complexity = 10 +[tool.ruff.format] +docstring-code-format = true +quote-style = "preserve" + +[tool.ruff.lint] +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] +ignore = ["E402", "E501"] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +[tool.ruff.lint.extend-per-file-ignores] +"__init__.py" = ["E402"] # Allow non-top-level imports +"tests/**.py" = [ + "S101", # Allow assert + "ANN001", # Args don't need types (usually fixtures) + "N802", # Fixture returning a class may be named per class name convention + "N803", # Args don't require naming convention (fixture could be a class) +] [tool.ruff.lint.isort] # These config options should match isort config above under [tool.isort] @@ -290,3 +247,6 @@ repo = ['baseframe'] [tool.ruff.lint.flake8-pytest-style] fixture-parentheses = false mark-parentheses = false + +[tool.ruff.lint.pyupgrade] +keep-runtime-typing = true diff --git a/src/baseframe/filters.py b/src/baseframe/filters.py index fb88c1d3..944f5bb3 100644 --- a/src/baseframe/filters.py +++ b/src/baseframe/filters.py @@ -14,8 +14,7 @@ from pytz import utc from wtforms import Field as WTField -from coaster.gfm import markdown -from coaster.utils import compress_whitespace, md5sum, text_blocks +from coaster.utils import compress_whitespace, markdown, md5sum, text_blocks from .blueprint import baseframe from .extensions import DEFAULT_LOCALE, _, cache, get_timezone