Compare commits

...

14 Commits

Author SHA1 Message Date
Ethan Paul 0693d19f7a
Update changelog for version 1.2.1 2023-04-13 15:01:13 -04:00
Ethan Paul 2ddf57a73f
Bump version to 1.2.1 2023-04-13 15:00:02 -04:00
Ethan Paul 1fe2eff40a Update mypy to latest version 2023-04-13 14:59:28 -04:00
Ethan Paul 5df974faa5 Update tests for calc batch size to accomodate new sqlite logic 2023-04-13 14:59:28 -04:00
Ethan Paul 0d1a142e43 Update docs to point to new line numbers
There's gotta be a better way to do this
2023-04-13 14:59:28 -04:00
Ethan Paul 5e68ee3055 Add logic for using updated sqlite3 default var limit
See here for details: https://www.sqlite.org/limits.html#max_variable_number
2023-04-13 14:59:28 -04:00
Ethan Paul f9d1f9ecd2 Pin virtualenv to bypass python-poetry/poetry-plugin-export#176 2023-04-13 14:41:13 -04:00
Ethan Paul d5899d61c7 Rename CI check stage to just 'check' 2023-04-13 14:41:13 -04:00
Ethan Paul 750d3c07b6 Update CI and toxfile to use new group structure 2023-04-13 14:41:13 -04:00
Ethan Paul ac342d4dc6 Update pyproject to use dep groups 2023-04-13 14:41:13 -04:00
Ethan Paul 6e3c9e8139 Remove deprecated option from pylintrc 2023-04-13 14:41:13 -04:00
Ethan Paul 23b6359d86 Add python 3.11 pypi classifier
Add python3.11 to tox CI
2023-04-13 14:41:13 -04:00
Ethan Paul 7ecd592ae0 Update developer docs to specify poetry 1.2 and python 3.10 2023-04-13 14:41:13 -04:00
Ethan Paul 6f97ff74e0 Fix documentation errors
Add more links to external docs where appropriate
Fix readme links hardcoded to github and 1.0.0 tag
Clarify intended usage of the calc_batch_size function
2023-04-13 14:41:13 -04:00
11 changed files with 2376 additions and 2012 deletions

View File

@ -8,7 +8,7 @@
set -e;
CI_CACHE=$HOME/.cache;
POETRY_VERSION=1.2.2;
INSTALL_POETRY_VERSION="${POETRY_VERSION:-1.4.1}";
mkdir --parents "$CI_CACHE";
@ -26,9 +26,10 @@ poetry --version --no-ansi;
poetry run pip --version;
poetry install \
--quiet \
--remove-untracked \
--no-ansi;
--sync \
--no-ansi \
--no-root \
--only ci;
poetry env info;
poetry run tox --version;

View File

@ -5,9 +5,11 @@ on:
types: ["opened", "synchronize"]
push:
branches: ["devel"]
env:
POETRY_VERSION: 1.4.1
jobs:
Test:
name: Test with Python ${{ matrix.python.version }}
name: Python ${{ matrix.python.version }}
runs-on: ubuntu-latest
strategy:
matrix:
@ -20,6 +22,8 @@ jobs:
toxenv: py39
- version: "3.10"
toxenv: py310
- version: "3.11"
toxenv: py311
fail-fast: true
steps:
- name: Checkout
@ -51,7 +55,6 @@ jobs:
- name: Run Toxenv ${{ matrix.python.toxenv }}
run: poetry run tox -e ${{ matrix.python.toxenv }}
Check:
name: Security, Linting, Formatting, Typing
runs-on: ubuntu-latest
steps:
- name: Checkout

View File

@ -11,7 +11,6 @@
# --disable=W"
disable=logging-fstring-interpolation
,logging-format-interpolation
,bad-continuation
,line-too-long
,ungrouped-imports
,typecheck

View File

@ -2,6 +2,14 @@
See also: [Github Release Page](https://github.com/enpaul/peewee-plus/releases).
## Version 1.2.1
View this release on: [Github](https://github.com/enpaul/peewee-plus/releases/tag/1.2.1),
[PyPI](https://pypi.org/project/peewee-plus/1.2.1/)
- Add PyPI classifier for Python 3.11
- Fix SQLite variable limit determination to account for changes in SQLite 3.32
## Version 1.2.0
View this release on: [Github](https://github.com/enpaul/peewee-plus/releases/tag/1.2.0),

View File

@ -39,5 +39,5 @@ publish: clean test build ## Build and upload to pypi (requires $PYPI_API_KEY be
@poetry publish --username __token__ --password $(PYPI_API_KEY)
dev: ## Create local dev environment
poetry install --sync
poetry install --sync --with dev --with ci --with test --with security --with static
poetry run pre-commit install

View File

@ -22,7 +22,7 @@ release history.
## Installing
Peewee+ is [available on PyPI](https://pypi.org/project/peewee-plus/) and can be installed
peewee+ is [available on PyPI](https://pypi.org/project/peewee-plus/) and can be installed
using Poetry, Pipenv, or Pip:
```bash
@ -57,30 +57,29 @@ when using SQLite
### Functions
[`calc_batch_size`](https://github.com/enpaul/peewee-plus/blob/1.0.0/peewee_plus.py#L71) -
Helper function for determining how to batch a create/update query with SQLite
[`calc_batch_size`](blob/devel/peewee_plus.py#L93) - Helper function for writing
backend-agnostic batch queries while accounting for the
[SQLite max variable limit](https://www.sqlite.org/limits.html#max_variable_number).
[`flat_transaction`](https://github.com/enpaul/peewee-plus/blob/devel/peewee_plus.py#L137)
\- Decorator function for wrapping callables in a database transaction without creating
nested transactions
[`flat_transaction`](blob/devel/peewee_plus.py#L159) - Decorator function for wrapping
callables in a database transaction without creating nested transactions
### Classes
[`PathField`](https://github.com/enpaul/peewee-plus/blob/1.0.0/peewee_plus.py#179) - A
Peewee database field for storing
[`PathField`](blob/devel/peewee_plus.py#204) - A Peewee database field for storing
[Pathlib](https://docs.python.org/3/library/pathlib.html) objects, optionally relative to
a runtime value.
[`PrecisionFloatField`](https://github.com/enpaul/peewee-plus/blob/1.0.0/peewee_plus.py#L237)
\- A Peewee database field for storing floats while specifying the
[`PrecisionFloatField`](blob/devel/peewee_plus.py#L262) - A Peewee database field for
storing floats while specifying the
[MySQL precision parameters](https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html)
`M` and `D`
[`JSONField`](https://github.com/enpaul/peewee-plus/blob/1.0.0/peewee_plus.py#L267) - A
Peewee database field for storing arbitrary JSON-serializable data
[`JSONField`](blob/devel/peewee_plus.py#L293) - A Peewee database field for storing
arbitrary JSON-serializable data
[`EnumField`](https://github.com/enpaul/peewee-plus/blob/1.0.0/peewee_plus.py#L322) - A
Peewee database field for storing Enums by name
[`EnumField`](blob/devel/peewee_plus.py#L348) - A Peewee database field for storing Enums
by name
## For Developers
@ -100,8 +99,8 @@ are tracked on [Github](https://github.com/enpaul/peewee-plus/releases),
[fork the repository](https://docs.github.com/en/enterprise/2.20/user/github/getting-started-with-github/fork-a-repo)
and [open a pull request](https://github.com/enpaul/peewee-plus/compare).
Developing this project requires at least [Python 3.7](https://www.python.org/downloads/)
and at least [Poetry 1.0](https://python-poetry.org/docs/#installation). GNU Make can
Developing this project requires [Python 3.10](https://www.python.org/downloads/) or later
and [Poetry 1.2](https://python-poetry.org/docs/#installation) or later. GNU Make can
optionally be used to quickly setup a local development environment, but this is not
required.

View File

@ -1,4 +1,6 @@
"""Peewee+
"""peewee+
Various extensions, helpers, and utilities for `Peewee`_
:constant SQLITE_DEFAULT_VARIABLE_LIMIT: The default number of variables that a single SQL query
can contain when interfacing with SQLite. The actual
@ -10,7 +12,9 @@
SQLite database connection. The value for this constant is taken
directly from the `Peewee documentation`_
.. _`Peewee documentation`: http://docs.peewee-orm.com/en/latest/peewee/database.html#recommended-settings
.. _`Peewee`: https://docs.peewee-orm.com/en/latest/
.. _`Peewee documentation`: https://docs.peewee-orm.com/en/latest/peewee/database.html#recommended-settings
"""
import contextlib
import enum
@ -28,7 +32,7 @@ import peewee
__title__ = "peewee-plus"
__version__ = "1.2.0"
__version__ = "1.2.1"
__license__ = "MIT"
__summary__ = "Various extensions, helpers, and utilities for Peewee"
__url__ = "https://github.com/enpaul/peewee-plus/"
@ -62,7 +66,25 @@ SQLITE_DEFAULT_PRAGMAS: Dict[str, Any] = {
}
SQLITE_DEFAULT_VARIABLE_LIMIT: int = 999
SQLITE_DEFAULT_VARIABLE_LIMIT: int
# With SQLite 3.32 (2020-05-22) the devs bumped the default variable limit to
# 32766. This logic attemps to import the sqlite3 bindings and determine whether
# the version of the installed SQLite version is greater or equal to 3.32. If
# the sqlite3 bindings cannot be imported (either because they aren't installed)
# or because the platform is using SQLite 1 or 2 then it falls back to the
# 999 value.
try:
import sqlite3
except ImportError:
SQLITE_DEFAULT_VARIABLE_LIMIT = 999
else:
if sqlite3.sqlite_version_info[0] >= 3 or (
sqlite3.sqlite_version_info[0] == 3 and sqlite3.sqlite_version_info[1] >= 32
):
SQLITE_DEFAULT_VARIABLE_LIMIT = 32766
else:
SQLITE_DEFAULT_VARIABLE_LIMIT = 999
T = TypeVar("T", bound=peewee.Model)
@ -254,8 +276,9 @@ class PrecisionFloatField(peewee.FloatField): # pylint: disable=abstract-method
.. _here: https://stackoverflow.com/a/67476045/5361209
:param max_digits: Maximum number of digits, combined from left and right of the decimal place,
to store for the value.
:param decimal_places: Maximum number of digits that will be stored after the decimal place
to store for the value; corresponds to the ``M`` MySQL precision parameter.
:param decimal_places: Maximum number of digits that will be stored after the decimal place;
corresponds to the ``D`` MySQL precision parameter.
"""
def __init__(self, *args, max_digits: int = 10, decimal_places: int = 4, **kwargs):
@ -270,7 +293,7 @@ class PrecisionFloatField(peewee.FloatField): # pylint: disable=abstract-method
class JSONField(peewee.TextField): # pylint: disable=abstract-method
"""Field class for storing JSON-serializable data
This field can be used to store a dictionary of data directly in the database without needing
This field can be used to store a dictionary of data directly in the database
without needing to call :func:`json.dumps` and :func:`json.loads` directly.
::

4190
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "peewee-plus"
version = "1.2.0"
version = "1.2.1"
description = "Various extensions, helpers, and utilities for Peewee"
authors = ["Ethan Paul <24588726+enpaul@users.noreply.github.com>"]
repository = "https://github.com/enpaul/peewee-plus/"
@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Database",
"Typing :: Typed"
@ -30,25 +31,42 @@ classifiers = [
python = "^3.7.1"
peewee = "^3.14.8"
[tool.poetry.dev-dependencies]
bandit = "^1.7.1"
black = "^22.8.0"
blacken-docs = "^1.12.0"
ipython = "^7.29.0"
mdformat = "^0.6.4"
mdformat-gfm = "^0.2"
mypy = "^0.910"
pre-commit = "^2.15.0"
pre-commit-hooks = "^4.0.1"
pylint = "^2.13.0"
[tool.poetry.group.test.dependencies]
pytest = "^6.2.5"
pytest-cov = "^3.0.0"
reorder-python-imports = "^2.6.0"
safety = "^2.2.0"
toml = "^0.10.2"
ruamel-yaml = {version = "^0.17.21", python = "^3.10"}
# This is a workaround for this issue with the Poetry export
# plugin which was blocking the 'security' CI check:
#
# https://github.com/python-poetry/poetry-plugin-export/issues/176
virtualenv = ">=20.15,<20.16"
[tool.poetry.group.ci.dependencies]
poetry = "^1.4.2"
tox = "^3.24.4"
tox-poetry-installer = {extras = ["poetry"], version = "^0.10.0"}
types-toml = "^0.10.1"
tox-poetry-installer = {version = "^0.10.0", extras = ["poetry"]}
[tool.poetry.group.security.dependencies]
bandit = {version = "^1.7.1", python = "^3.10"}
poetry = {version = "^1.4.2", python = "^3.10"}
safety = {version = "^2.2.0", python = "^3.10"}
[tool.poetry.group.static.dependencies]
black = {version = "^22.8.0", python = "^3.10"}
blacken-docs = {version = "^1.12.0", python = "^3.10"}
mdformat = {version = "^0.6.4", python = "^3.10"}
mdformat-gfm = {version = "^0.2", python = "^3.10"}
mypy = {version = "^1.2.0", python = "^3.10"}
pre-commit = {version = "^2.15.0", python = "^3.10"}
pre-commit-hooks = {version = "^4.0.1", python = "^3.10"}
pylint = {version = "^2.13.0", python = "^3.10"}
reorder-python-imports = {version = "^2.6.0", python = "^3.10"}
toml = {version = "^0.10.2", python = "^3.10"}
types-toml = {version = "^0.10.1", python = "^3.10"}
[tool.poetry.group.dev.dependencies]
ipython = {version = "^8.10.0", python = "^3.10"}
[build-system]
requires = ["poetry-core>=1.1.0"]

View File

@ -17,7 +17,11 @@ def test_sqlite(fakedb):
data = peewee.IntegerField()
models = [TestModel(item) for item in range(500)]
# Three is just chosen as an arbitrary multiplier to ensure the value is larger than the
# sqlite variable limit
models = [
TestModel(item) for item in range(peewee_plus.SQLITE_DEFAULT_VARIABLE_LIMIT * 3)
]
assert (
peewee_plus.calc_batch_size(models) <= peewee_plus.SQLITE_DEFAULT_VARIABLE_LIMIT
)

47
tox.ini
View File

@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39,310}
py{37,38,39,310,311}
static
static-tests
security
@ -11,11 +11,8 @@ skip_missing_interpreters = true
description = Run the tests
require_locked_deps = true
require_poetry = true
locked_deps =
pytest
pytest-cov
ruamel.yaml
toml
poetry_dep_groups =
test
commands =
pytest {toxinidir}/tests/ \
--cov peewee_plus \
@ -26,16 +23,8 @@ commands =
description = Static formatting and quality enforcement
basepython = python3.10
ignore_errors = true
locked_deps =
black
blacken-docs
mdformat
mdformat-gfm
mypy
reorder-python-imports
pre-commit
pre-commit-hooks
pylint
poetry_dep_groups =
static
commands =
pre-commit run \
--all-files
@ -49,11 +38,9 @@ commands =
description = Static formatting and quality enforcement for the tests
basepython = python3.10
ignore_errors = true
locked_deps =
mypy
pylint
pytest
types-toml
poetry_dep_groups =
static
test
commands =
pylint {toxinidir}/tests/ \
--rcfile {toxinidir}/.pylintrc
@ -66,10 +53,8 @@ description = Security checks
basepython = python3.10
skip_install = true
ignore_errors = true
locked_deps =
bandit
safety
poetry
poetry_dep_groups =
security
commands =
bandit {toxinidir}/peewee_plus.py \
--recursive \
@ -82,7 +67,13 @@ commands =
--format requirements.txt \
--output {envtmpdir}/requirements.txt \
--without-hashes \
--dev
--with ci \
--with test \
--with security \
--with static \
--with dev
safety check \
--json \
--file {envtmpdir}/requirements.txt
--file {envtmpdir}/requirements.txt \
--output text \
# https://github.com/pytest-dev/py/issues/287
--ignore 51457