From a091d5bf40cd5b250752d3efcc52d4c678094e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Sun, 13 Oct 2024 15:56:23 +0200 Subject: [PATCH] chore: mega-cleanup - move the project to pallets-eco organization - move from `master` branch to `main` - move to pyproject.toml - move to src directory - remove python 3.8 support - use pre-commit configuration from flask --- .github/workflows/tests.yaml | 5 +- .pre-commit-config.yaml | 29 ++----- CHANGES.rst | 12 +++ examples/flask/basic.py | 1 + pyproject.toml | 80 +++++++++++++++++++ setup.cfg | 61 -------------- setup.py | 4 - .../wtforms_sqlalchemy}/__init__.py | 0 .../wtforms_sqlalchemy}/fields.py | 6 +- .../wtforms_sqlalchemy}/orm.py | 6 +- tests/common.py | 4 +- tests/test_main.py | 1 + tox.ini | 9 ++- 13 files changed, 118 insertions(+), 100 deletions(-) delete mode 100644 setup.cfg delete mode 100755 setup.py rename {wtforms_sqlalchemy => src/wtforms_sqlalchemy}/__init__.py (100%) rename {wtforms_sqlalchemy => src/wtforms_sqlalchemy}/fields.py (99%) rename {wtforms_sqlalchemy => src/wtforms_sqlalchemy}/orm.py (98%) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1338c26..74fb6c9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -3,11 +3,11 @@ name: tests on: push: branches: - - master + - main - '*.x' pull_request: branches: - - master + - main - '*.x' jobs: tests: @@ -21,7 +21,6 @@ jobs: - '3.11' - '3.10' - '3.9' - - '3.8' - pypy-3.10 steps: - uses: actions/checkout@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 359c993..1cddf08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,31 +1,14 @@ ---- repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: ["--py38-plus"] - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.12.0 - hooks: - - id: reorder-python-imports - args: ["--application-directories", "src"] - - repo: https://github.com/psf/black - rev: 23.12.1 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.1.11' + rev: v0.6.9 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix] - - repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 - hooks: - - id: docformatter + - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - - id: check-byte-order-marker + - id: check-merge-conflict + - id: debug-statements + - id: fix-byte-order-marker - id: trailing-whitespace - id: end-of-file-fixer diff --git a/CHANGES.rst b/CHANGES.rst index e6ab0ee..6b8ad92 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,15 @@ +Version 0.x.x +------------- + +Unreleased + +- move the project to pallets-eco organization +- move from `master` branch to `main` +- move to pyproject.toml +- move to src directory +- remove python 3.8 support +- use pre-commit configuration from flask + Version 0.4.1 ------------- diff --git a/examples/flask/basic.py b/examples/flask/basic.py index 4dc1b15..4e45e5d 100644 --- a/examples/flask/basic.py +++ b/examples/flask/basic.py @@ -2,6 +2,7 @@ from flask import render_template from flask import request from flask_sqlalchemy import SQLAlchemy + from wtforms_sqlalchemy.orm import model_form app = Flask(__name__) diff --git a/pyproject.toml b/pyproject.toml index 6d504bc..125e6a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,63 @@ +[project] +name = "WTForms-SQLAlchemy" +description = "SQLAlchemy tools for WTForms" +readme = "README.rst" +license = {file = "LICENSE.txt"} +maintainers = [{name = "WTForms"}] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Internet :: WWW/HTTP :: WSGI", + "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", + "Topic :: Software Development :: Libraries :: Application Frameworks", +] +requires-python = ">=3.9" +dependencies = [ + "WTForms>=3.1", + "SQLAlchemy>=1.4", +] +dynamic = ["version"] + +[project.urls] +Documentation = "https://wtforms-sqlalchemy.readthedocs.io/" +Changes = "https://wtforms-sqlalchemy.readthedocs.io/changes/" +"Source Code" = "https://github.com/pallets-eco/wtforms-sqlalchemy/" +"Issue Tracker" = "https://github.com/pallets-eco/wtforms-sqlalchemy/issues/" +Chat = "https://discord.gg/pallets" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["src/wtforms_sqlalchemy"] + +[tool.hatch.version] +path = "src/wtforms_sqlalchemy/__init__.py" + +[tool.hatch.build] +include = [ + "src/", + "docs/", + "tests/", + "CHANGES.rst", + "tox.ini", +] +exclude = [ + "docs/_build/", +] + +[tool.pytest.ini_options] +testpaths = ["tests"] +filterwarnings = [ + "error", +] + [tool.coverage.run] branch = true source = ["wtforms_sqlalchemy", "tests"] @@ -10,3 +70,23 @@ exclude_lines = [ "pragma: no cover", "except ImportError:", ] + +[tool.ruff] +src = ["src"] +fix = true +show-fixes = true +output-format = "full" + +[tool.ruff.lint] +select = [ + "B", # flake8-bugbear + "E", # pycodestyle error + "F", # pyflakes + "I", # isort + "UP", # pyupgrade + "W", # pycodestyle warning +] + +[tool.ruff.lint.isort] +force-single-line = true +order-by-type = false diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 32032a8..0000000 --- a/setup.cfg +++ /dev/null @@ -1,61 +0,0 @@ -[metadata] -name = WTForms-SQLAlchemy -version = 0.4.1 -url = http://github.com/wtforms/wtforms-sqlalchemy/ -project_urls = - Documentation = https://wtforms-sqlalchemy.readthedocs.io/ - Code = https://github.com/wtforms/wtforms-sqlalchemy - Issue Tracker = https://github.com/wtforms/wtforms-sqlalchemy/issues -license = BSD -license_files = LICENSE.txt -maintainer = Thomas Johansson, James Crasta -maintainer_email = wtforms@simplecodes.com -description = SQLAlchemy tools for WTForms -long_description = file: README.rst -long_description_content_type = text/x-rst -classifiers = - Development Status :: 5 - Production/Stable - Environment :: Web Environment - Intended Audience :: Developers - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Topic :: Internet :: WWW/HTTP :: Dynamic Content - Topic :: Software Development :: Libraries :: Python Modules - -[options] -packages = wtforms_sqlalchemy -include_package_data = true -python_requires = >= 3.8 -install_requires = - WTForms>=3.1 - SQLAlchemy>=1.4 - -[flake8] -# B = bugbear -# E = pycodestyle errors -# F = flake8 pyflakes -# W = pycodestyle warnings -# B9 = bugbear opinions -# ISC = implicit-str-concat -select = B, E, F, W, B9, ISC -ignore = - # slice notation whitespace, invalid - E203 - # line length, handled by bugbear B950 - E501 - # bare except, handled by bugbear B001 - E722 - # bin op line break, invalid - W503 -# up to 88 allowed by bugbear B950 -max-line-length = 80 -per-file-ignores = - # __init__ modules export names - **/__init__.py: F401, F403 diff --git a/setup.py b/setup.py deleted file mode 100755 index c823345..0000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python -from setuptools import setup - -setup() diff --git a/wtforms_sqlalchemy/__init__.py b/src/wtforms_sqlalchemy/__init__.py similarity index 100% rename from wtforms_sqlalchemy/__init__.py rename to src/wtforms_sqlalchemy/__init__.py diff --git a/wtforms_sqlalchemy/fields.py b/src/wtforms_sqlalchemy/fields.py similarity index 99% rename from wtforms_sqlalchemy/fields.py rename to src/wtforms_sqlalchemy/fields.py index 186fa7f..b23099c 100644 --- a/wtforms_sqlalchemy/fields.py +++ b/src/wtforms_sqlalchemy/fields.py @@ -1,4 +1,5 @@ """Useful form fields for use with SQLAlchemy ORM.""" + import operator from collections import defaultdict @@ -82,7 +83,7 @@ def __init__( allow_blank=False, blank_text="", blank_value="__None", - **kwargs + **kwargs, ): super().__init__(label, validators, **kwargs) self.query_factory = query_factory @@ -212,7 +213,8 @@ def __init__(self, label=None, validators=None, default=None, **kwargs): import warnings warnings.warn( - "allow_blank=True does not do anything for QuerySelectMultipleField." + "allow_blank=True does not do anything for QuerySelectMultipleField.", + stacklevel=2, ) self._invalid_formdata = False diff --git a/wtforms_sqlalchemy/orm.py b/src/wtforms_sqlalchemy/orm.py similarity index 98% rename from wtforms_sqlalchemy/orm.py rename to src/wtforms_sqlalchemy/orm.py index e5c3a51..4c054e0 100644 --- a/wtforms_sqlalchemy/orm.py +++ b/src/wtforms_sqlalchemy/orm.py @@ -1,4 +1,5 @@ """Tools for generating forms based on SQLAlchemy models.""" + import inspect from sqlalchemy import inspect as sainspect @@ -68,8 +69,7 @@ def get_converter(self, column): return self.converters[col_type.__name__] raise ModelConversionError( - "Could not find field converter for column %s (%r)." - % (column.name, types[0]) + f"Could not find field converter for column {column.name} ({types[0]!r})." ) def convert(self, model, mapper, prop, field_args, db_session=None): @@ -130,7 +130,7 @@ def convert(self, model, mapper, prop, field_args, db_session=None): # We have a property with a direction. if db_session is None: raise ModelConversionError( - "Cannot convert field %s, need DB session." % prop.key + f"Cannot convert field {prop.key}, need DB session." ) foreign_model = prop.mapper.class_ diff --git a/tests/common.py b/tests/common.py index ab71101..64e80bd 100644 --- a/tests/common.py +++ b/tests/common.py @@ -68,8 +68,8 @@ def assert_raises_text(e_type, text): except e_type as e: if not re.match(text, e.args[0]): raise AssertionError( - "Exception raised: %r but text %r did not match pattern %r" - % (e, e.args[0], text) + f"Exception raised: {e!r} but text {e.args[0]!r} " + f"did not match pattern {text!r}" ) from e else: raise AssertionError(f"Expected Exception {e_type!r}, did not get it") diff --git a/tests/test_main.py b/tests/test_main.py index 9172337..20e99f3 100755 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,6 +21,7 @@ from wtforms.validators import InputRequired from wtforms.validators import Optional from wtforms.validators import Regexp + from wtforms_sqlalchemy.fields import QuerySelectField from wtforms_sqlalchemy.fields import QuerySelectMultipleField from wtforms_sqlalchemy.orm import model_form diff --git a/tox.ini b/tox.ini index 9bcf578..0241d07 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,13 @@ [tox] -envlist = style, py312, py311, py310, py39, py38, coverage, docs +envlist = + py3{12,11,10,9},pypy3{10,9} + style + docs [testenv] deps = - pytest + -e . + pytest commands = pytest {posargs} [testenv:style] @@ -17,6 +21,7 @@ commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html [testenv:coverage] deps = + -e . pytest coverage commands =