Skip to content

Commit

Permalink
Use Ruff to lint the Python code
Browse files Browse the repository at this point in the history
Replace flake8 and isort with Ruff.
  • Loading branch information
jpvanhal committed Nov 17, 2024
1 parent 572c84a commit 5c2ae1c
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 31 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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 .
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

10 changes: 8 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from wtforms_alchemy import (
model_form_factory,
model_form_meta_factory,
ModelFormMeta
ModelFormMeta,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from wtforms_alchemy import (
AttributeTypeException,
InvalidAttributeException,
ModelForm
ModelForm,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_i18n_extension.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_form_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from wtforms_alchemy import (
FormGenerator,
model_form_factory,
UnknownConfigurationOption
UnknownConfigurationOption,
)


Expand Down
8 changes: 4 additions & 4 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +32,7 @@
IntIntervalField,
SelectField,
StringField,
TimeField
TimeField,
)

from tests import ModelFormTestCase
Expand All @@ -42,7 +42,7 @@
null_or_unicode,
PhoneNumberField,
UnknownTypeException,
WeekDaysField
WeekDaysField,
)
from wtforms_alchemy.utils import ClassMap

Expand Down
2 changes: 1 addition & 1 deletion tests/test_unique_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
InputRequired,
Length,
NumberRange,
Optional
Optional,
)
from wtforms_components import DateRange, TimeRange

Expand Down
8 changes: 4 additions & 4 deletions wtforms_alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
Length,
NumberRange,
Optional,
URL
URL,
)
from wtforms_components import DateRange, Email, TimeRange

from .exc import (
AttributeTypeException,
InvalidAttributeException,
UnknownConfigurationOption,
UnknownTypeException
UnknownTypeException,
)
from .fields import ( # noqa
CountryField,
Expand All @@ -26,15 +26,15 @@
PhoneNumberField,
QuerySelectField,
QuerySelectMultipleField,
WeekDaysField
WeekDaysField,
)
from .generator import FormGenerator
from .utils import (
ClassMap,
is_date_column,
is_scalar,
null_or_int,
null_or_unicode
null_or_unicode,
)
from .validators import Unique # noqa

Expand Down
10 changes: 5 additions & 5 deletions wtforms_alchemy/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Field,
FloatField,
PasswordField,
TextAreaField
TextAreaField,
)
from wtforms.widgets import CheckboxInput, TextArea
from wtforms_components import (
Expand All @@ -28,7 +28,7 @@
IntIntervalField,
SelectField,
StringField,
TimeField
TimeField,
)
from wtforms_components.widgets import (
ColorInput,
Expand All @@ -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 (
Expand All @@ -57,7 +57,7 @@
is_scalar,
null_or_unicode,
strip_string,
translated_attributes
translated_attributes,
)


Expand Down

0 comments on commit 5c2ae1c

Please sign in to comment.