From 5c2ae1cdf49a1a2fa574b8e3568b0fbe1a06b1ad Mon Sep 17 00:00:00 2001 From: Janne Vanhala Date: Sun, 17 Nov 2024 10:05:07 +0200 Subject: [PATCH] Use Ruff to lint the Python code Replace flake8 and isort with Ruff. --- .github/workflows/lint.yml | 25 +++++++++++++++++++++++++ .isort.cfg | 6 ------ docs/conf.py | 10 ++++++++-- pyproject.toml | 15 +++++++++++++++ setup.py | 6 ++---- tests/conftest.py | 2 +- tests/test_configuration.py | 2 +- tests/test_i18n_extension.py | 2 +- tests/test_model_form_factory.py | 2 +- tests/test_types.py | 8 ++++---- tests/test_unique_validator.py | 2 +- tests/test_validators.py | 2 +- wtforms_alchemy/__init__.py | 8 ++++---- wtforms_alchemy/generator.py | 10 +++++----- 14 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/lint.yml delete mode 100644 .isort.cfg diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b81c05a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint + +on: + - push + - pull_request + +jobs: + test: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[test] + + - name: Run linting + run: | + ruff check . diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index ddb0afc..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -known_first_party=wtforms_alchemy,tests -line_length=79 -multi_line_output=3 -not_skip=__init__.py -order_by_type=false diff --git a/docs/conf.py b/docs/conf.py index 37455b8..c669e80 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -26,7 +27,12 @@ # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.viewcode'] +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.viewcode' +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/pyproject.toml b/pyproject.toml index 242116f..40ebd52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,18 @@ filterwarnings = [ 'error:.*:sqlalchemy.exc.SAWarning', 'ignore:.*:sqlalchemy.exc.SADeprecationWarning:sqlalchemy_i18n', ] + +[tool.ruff] +target-version = "py39" + +[tool.ruff.lint] +select = [ + "C90", # mccabe + "E", # pycodestyle errors + "F", # Pyflakes + "I", # isort + "W", # pycodestyle warnings +] + +[tool.ruff.lint.isort] +order-by-type = false diff --git a/setup.py b/setup.py index 465b9fc..ea285af 100644 --- a/setup.py +++ b/setup.py @@ -5,11 +5,11 @@ Generates WTForms forms from SQLAlchemy models. """ -from setuptools import setup import os import re import sys +from setuptools import setup HERE = os.path.dirname(os.path.abspath(__file__)) PY3 = sys.version_info[0] == 3 @@ -30,10 +30,8 @@ def get_version(): 'Pygments>=1.2', 'Jinja2>=2.3', 'docutils>=0.10', - 'flake8>=2.4.0', 'flexmock>=0.9.7', - 'isort>=3.9.6', - 'natsort==3.5.6', + 'ruff==0.7.4', 'WTForms-Test>=0.1.1' ], 'babel': ['Babel>=1.3'], diff --git a/tests/conftest.py b/tests/conftest.py index 1748fe1..4df9d8f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,7 @@ from wtforms_alchemy import ( model_form_factory, model_form_meta_factory, - ModelFormMeta + ModelFormMeta, ) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 43264af..59b2503 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -7,7 +7,7 @@ from wtforms_alchemy import ( AttributeTypeException, InvalidAttributeException, - ModelForm + ModelForm, ) diff --git a/tests/test_i18n_extension.py b/tests/test_i18n_extension.py index 2eb4b3e..6e8aa98 100644 --- a/tests/test_i18n_extension.py +++ b/tests/test_i18n_extension.py @@ -1,7 +1,7 @@ import sqlalchemy as sa from packaging.version import Version from pytest import raises, skip -from sqlalchemy_i18n import Translatable, make_translatable, translation_base +from sqlalchemy_i18n import make_translatable, Translatable, translation_base from tests import ModelFormTestCase, MultiDict from wtforms_alchemy import ModelForm diff --git a/tests/test_model_form_factory.py b/tests/test_model_form_factory.py index e2ff535..59d8360 100644 --- a/tests/test_model_form_factory.py +++ b/tests/test_model_form_factory.py @@ -6,7 +6,7 @@ from wtforms_alchemy import ( FormGenerator, model_form_factory, - UnknownConfigurationOption + UnknownConfigurationOption, ) diff --git a/tests/test_types.py b/tests/test_types.py index 04e16cd..15cd811 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -11,14 +11,14 @@ PasswordType, PhoneNumberType, URLType, - UUIDType + UUIDType, ) from sqlalchemy_utils.types import arrow, phone_number, WeekDaysType # noqa from wtforms.fields import ( BooleanField, FloatField, PasswordField, - TextAreaField + TextAreaField, ) from wtforms.validators import Length, URL from wtforms_components import Email @@ -32,7 +32,7 @@ IntIntervalField, SelectField, StringField, - TimeField + TimeField, ) from tests import ModelFormTestCase @@ -42,7 +42,7 @@ null_or_unicode, PhoneNumberField, UnknownTypeException, - WeekDaysField + WeekDaysField, ) from wtforms_alchemy.utils import ClassMap diff --git a/tests/test_unique_validator.py b/tests/test_unique_validator.py index 3e582a9..a8b48b4 100644 --- a/tests/test_unique_validator.py +++ b/tests/test_unique_validator.py @@ -3,10 +3,10 @@ from sqlalchemy.orm import declarative_base, relationship from sqlalchemy.orm.session import close_all_sessions from wtforms import Form +from wtforms.fields import StringField from tests import MultiDict from wtforms_alchemy import ModelForm, QuerySelectField, Unique -from wtforms.fields import StringField base = declarative_base() diff --git a/tests/test_validators.py b/tests/test_validators.py index 389b29a..3e3f5e1 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -8,7 +8,7 @@ InputRequired, Length, NumberRange, - Optional + Optional, ) from wtforms_components import DateRange, TimeRange diff --git a/wtforms_alchemy/__init__.py b/wtforms_alchemy/__init__.py index 3e532d6..a272877 100644 --- a/wtforms_alchemy/__init__.py +++ b/wtforms_alchemy/__init__.py @@ -7,7 +7,7 @@ Length, NumberRange, Optional, - URL + URL, ) from wtforms_components import DateRange, Email, TimeRange @@ -15,7 +15,7 @@ AttributeTypeException, InvalidAttributeException, UnknownConfigurationOption, - UnknownTypeException + UnknownTypeException, ) from .fields import ( # noqa CountryField, @@ -26,7 +26,7 @@ PhoneNumberField, QuerySelectField, QuerySelectMultipleField, - WeekDaysField + WeekDaysField, ) from .generator import FormGenerator from .utils import ( @@ -34,7 +34,7 @@ is_date_column, is_scalar, null_or_int, - null_or_unicode + null_or_unicode, ) from .validators import Unique # noqa diff --git a/wtforms_alchemy/generator.py b/wtforms_alchemy/generator.py index 1b1f2aa..636486b 100644 --- a/wtforms_alchemy/generator.py +++ b/wtforms_alchemy/generator.py @@ -11,7 +11,7 @@ Field, FloatField, PasswordField, - TextAreaField + TextAreaField, ) from wtforms.widgets import CheckboxInput, TextArea from wtforms_components import ( @@ -28,7 +28,7 @@ IntIntervalField, SelectField, StringField, - TimeField + TimeField, ) from wtforms_components.widgets import ( ColorInput, @@ -38,13 +38,13 @@ EmailInput, NumberInput, TextInput, - TimeInput + TimeInput, ) from .exc import ( AttributeTypeException, InvalidAttributeException, - UnknownTypeException + UnknownTypeException, ) from .fields import CountryField, PhoneNumberField, WeekDaysField from .utils import ( @@ -57,7 +57,7 @@ is_scalar, null_or_unicode, strip_string, - translated_attributes + translated_attributes, )