From a223622a44dd760a76ae545303bdf518bc6e2c47 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 13:27:28 +0100 Subject: [PATCH 1/9] Add multiple SQLAlchemy versions support --- .travis.yml | 62 ++++++++++++++++++++++++++++++++++++++++++----------- README.rst | 22 +++++++++++++------ tox.ini | 6 +++++- 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd118b2..abdb64f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,23 +19,59 @@ matrix: include: - stage: test python: 2.7 - env: TOX_ENV=py27 + env: TOX_ENV="py27-sqlalchemy1.0" + - python: 2.7 + env: TOX_ENV="py27-sqlalchemy1.1" + - python: 2.7 + env: TOX_ENV="py27-sqlalchemy1.2" + - python: 2.7 + env: TOX_ENV="py27-sqlalchemy1.3" + - python: 2.7 + env: TOX_ENV="py27-sqlalchemylatest" - - stage: test - python: 3.4 - env: TOX_ENV=py34 + - python: 3.4 + env: TOX_ENV="py34-sqlalchemy1.0" + - python: 3.4 + env: TOX_ENV="py34-sqlalchemy1.1" + - python: 3.4 + env: TOX_ENV="py34-sqlalchemy1.2" + - python: 3.4 + env: TOX_ENV="py34-sqlalchemy1.3" + - python: 3.4 + env: TOX_ENV="py34-sqlalchemylatest" - - stage: test - python: 3.5 - env: TOX_ENV=py35 + - python: 3.5 + env: TOX_ENV="py35-sqlalchemy1.0" + - python: 3.5 + env: TOX_ENV="py35-sqlalchemy1.1" + - python: 3.5 + env: TOX_ENV="py35-sqlalchemy1.2" + - python: 3.5 + env: TOX_ENV="py35-sqlalchemy1.3" + - python: 3.5 + env: TOX_ENV="py35-sqlalchemylatest" - - stage: test - python: 3.6 - env: TOX_ENV=py36 + - python: 3.6 + env: TOX_ENV="py36-sqlalchemy1.0" + - python: 3.6 + env: TOX_ENV="py36-sqlalchemy1.1" + - python: 3.6 + env: TOX_ENV="py36-sqlalchemy1.2" + - python: 3.6 + env: TOX_ENV="py36-sqlalchemy1.3" + - python: 3.6 + env: TOX_ENV="py36-sqlalchemylatest" - - stage: test - python: 3.7 - env: TOX_ENV=py37 + - python: 3.7 + env: TOX_ENV="py37-sqlalchemy1.0" + - python: 3.7 + env: TOX_ENV="py37-sqlalchemy1.1" + - python: 3.7 + env: TOX_ENV="py37-sqlalchemy1.2" + - python: 3.7 + env: TOX_ENV="py37-sqlalchemy1.3" + - python: 3.7 + env: TOX_ENV="py37-sqlalchemylatest" - stage: deploy script: skip diff --git a/README.rst b/README.rst index e700283..4b58101 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ SQLAlchemy filters .. pull-quote:: - Filter, sort and paginate SQLAlchemy query objects. + Filter, sort and paginate SQLAlchemy_ query objects. Ideal for exposing these actions over a REST API. @@ -23,7 +23,7 @@ SQLAlchemy filters Filtering --------- -Assuming that we have a SQLAlchemy ``query`` object: +Assuming that we have a SQLAlchemy_ ``query`` object: .. code-block:: python @@ -113,7 +113,7 @@ blocks is identical: ] filtered_query = apply_filters(query, filter_spec) -The automatic join is only possible if sqlalchemy can implictly +The automatic join is only possible if SQLAlchemy_ can implictly determine the condition for the join, for example because of a foreign key relationship. @@ -137,7 +137,7 @@ functions: Restricted Loads ---------------- -You can restrict the fields that SQLAlchemy loads from the database by +You can restrict the fields that SQLAlchemy_ loads from the database by using the ``apply_loads`` function: .. code-block:: python @@ -159,7 +159,7 @@ loaded during normal query execution. Effect on joined queries ^^^^^^^^^^^^^^^^^^^^^^^^ -The default SQLAlchemy join is lazy, meaning that columns from the +The default SQLAlchemy_ join is lazy, meaning that columns from the joined table are loaded only when required. Therefore ``apply_loads`` has limited effect in the following scenario: @@ -370,7 +370,7 @@ to the RDBMS being used. SQL defines that ``NULL`` values should be placed together when sorting, but it does not specify whether they should be placed first or last. -Even though both ``nullsfirst`` and ``nullslast`` are part of SQLAlchemy, +Even though both ``nullsfirst`` and ``nullslast`` are part of SQLAlchemy_, they will raise an unexpected exception if the RDBMS that is being used does not support them. @@ -447,6 +447,13 @@ There is no active support for python 2, however it is compatible as of February 2019, if you install ``funcsigs``. +SQLAlchemy support +------------------ + +The following SQLAlchemy_ versions are supported: ``1.0``, ``1.1``, +``1.2``, ``1.3``. + + Changelog --------- @@ -459,3 +466,6 @@ License Apache 2.0. See `LICENSE `_ for details. + + +.. _SQLAlchemy: https://www.sqlalchemy.org/ diff --git a/tox.ini b/tox.ini index 77b829b..9799d0e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27, py34, py35, py36, py37} +envlist = {py27,py34,py35,py36,py37}-sqlalchemy{1.0,1.1,1.2,1.3,latest} skipsdist = True [testenv] @@ -11,5 +11,9 @@ extras = postgresql deps = py27: funcsigs + sqlalchemy1.0: sqlalchemy>=1.0,<1.1 + sqlalchemy1.1: sqlalchemy>=1.1,<1.2 + sqlalchemy1.2: sqlalchemy>=1.2,<1.3 + sqlalchemy1.3: sqlalchemy>=1.3,<1.4 commands = make coverage ARGS='-x -vv' From 74bc8c7c65b0faa7439092971a0e81b2e35796e5 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 13:51:12 +0100 Subject: [PATCH 2/9] Remove Python 3.4 support --- .travis.yml | 11 ----------- setup.py | 1 - tox.ini | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index abdb64f..ec2b9b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,17 +29,6 @@ matrix: - python: 2.7 env: TOX_ENV="py27-sqlalchemylatest" - - python: 3.4 - env: TOX_ENV="py34-sqlalchemy1.0" - - python: 3.4 - env: TOX_ENV="py34-sqlalchemy1.1" - - python: 3.4 - env: TOX_ENV="py34-sqlalchemy1.2" - - python: 3.4 - env: TOX_ENV="py34-sqlalchemy1.3" - - python: 3.4 - env: TOX_ENV="py34-sqlalchemylatest" - - python: 3.5 env: TOX_ENV="py35-sqlalchemy1.0" - python: 3.5 diff --git a/setup.py b/setup.py index 32f3c36..3b9c880 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,6 @@ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", diff --git a/tox.ini b/tox.ini index 9799d0e..cc3140e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27,py34,py35,py36,py37}-sqlalchemy{1.0,1.1,1.2,1.3,latest} +envlist = {py27,py35,py36,py37}-sqlalchemy{1.0,1.1,1.2,1.3,latest} skipsdist = True [testenv] From 161b9a243bdeae2a0975c6a87c5b9170e0bc2320 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 14:12:24 +0100 Subject: [PATCH 3/9] Rename test docker containers --- .travis.yml | 4 ++-- Makefile | 4 ++-- README.rst | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec2b9b1..faf782f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ services: - docker before_install: - - make docker-mysql-run - - make docker-postgres-run + - make mysql-container + - make postgres-container install: - pip install tox diff --git a/Makefile b/Makefile index 10b9e90..ad28c2d 100644 --- a/Makefile +++ b/Makefile @@ -21,12 +21,12 @@ coverage: flake8 rst-lint # Docker test containers -docker-mysql-run: +mysql-container: docker run -d --rm --name mysql-sqlalchemy-filters -p 3306:3306 \ -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ mysql:$(MYSQL_VERSION) -docker-postgres-run: +postgres-container: docker run -d --rm --name postgres-sqlalchemy-filters -p 5432:5432 \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD= \ diff --git a/README.rst b/README.rst index 4b58101..94ec573 100644 --- a/README.rst +++ b/README.rst @@ -402,8 +402,8 @@ There are Makefile targets to run docker containers locally for both .. code-block:: shell - $ make docker-mysql-run - $ make docker-postgres-run + $ make mysql-container + $ make postgres-container To run the tests locally: From 2c5e780e4e1de327849114e8d7fd2215110e2dc3 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 14:33:08 +0100 Subject: [PATCH 4/9] sudo Travis keyword has been fully deprecated --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index faf782f..478f1b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -sudo: false - language: python python: 3.7 From 9180680f57e8fce4dd4eb777b888a3a2523e0a4a Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 14:52:30 +0100 Subject: [PATCH 5/9] Improve coverage report and flake8 coverage --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ad28c2d..27ab662 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,14 @@ rst-lint: rst-lint CHANGELOG.rst flake8: - flake8 sqlalchemy_filters test + flake8 sqlalchemy_filters test setup.py test: flake8 pytest test $(ARGS) coverage: flake8 rst-lint coverage run --source sqlalchemy_filters -m pytest test $(ARGS) - coverage report -m --fail-under 100 + coverage report --show-missing --fail-under 100 # Docker test containers From e9296c4ef7d287a54e086e02a2c909bc29c4437a Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 15:11:07 +0100 Subject: [PATCH 6/9] Upgrade extra requirements --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 3b9c880..977117f 100644 --- a/setup.py +++ b/setup.py @@ -26,18 +26,18 @@ ], extras_require={ 'dev': [ - 'pytest==4.3.0', - 'flake8==3.7.7', + 'pytest==4.4.0', 'coverage==4.5.3', 'sqlalchemy-utils==0.33.11', - 'restructuredtext-lint==1.2.2', + 'flake8==3.7.7', + 'restructuredtext-lint==1.3.0', 'Pygments==2.3.1', ], 'mysql': [ 'mysql-connector-python-rf==2.2.2', ], 'postgresql': [ - 'psycopg2==2.7.7' + 'psycopg2==2.8.1' ], 'python2': [ "funcsigs>=1.0.2" From d22c0cfd2be39d40e79decb7fde93bf7bef7f2e7 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 16:08:42 +0100 Subject: [PATCH 7/9] Improve documentation --- README.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 94ec573..171848a 100644 --- a/README.rst +++ b/README.rst @@ -54,6 +54,7 @@ Then we can apply filters to that ``query`` object (multiple times): from sqlalchemy_filters import apply_filters + # `query` should be a SQLAlchemy query object filter_spec = [{'field': 'name', 'op': '==', 'value': 'name_1'}] @@ -72,6 +73,7 @@ including joins: class Bar(Base): __tablename__ = 'bar' + foo_id = Column(Integer, ForeignKey('foo.id')) @@ -218,6 +220,7 @@ Sort from sqlalchemy_filters import apply_sort + # `query` should be a SQLAlchemy query object sort_spec = [ @@ -244,6 +247,7 @@ Pagination from sqlalchemy_filters import apply_pagination + # `query` should be a SQLAlchemy query object query, pagination = apply_pagination(query, page_number=1, page_size=10) @@ -415,8 +419,12 @@ To run the tests locally: There are some other Makefile targets that can be used to run the tests: +There are other Makefile targets to run the tests, but extra +dependencies will have to be installed: + .. code-block:: shell + $ pip install -U --editable ".[dev,mysql,postgresql]" $ # using default settings $ make test $ make coverage @@ -443,8 +451,9 @@ The following RDBMS are supported (tested): Python 2 -------- -There is no active support for python 2, however it is compatible as of -February 2019, if you install ``funcsigs``. +There is no active support for Python 2. However, it is compatible as of +February 2019, if you install ``funcsigs``, included in the `python2` +extra requirements. SQLAlchemy support From 147be7b25b59cbebe29cabe2f05e66446b6e4c01 Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 17:02:58 +0100 Subject: [PATCH 8/9] Amend reStructuredText syntax --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 171848a..713b3dc 100644 --- a/README.rst +++ b/README.rst @@ -452,7 +452,7 @@ Python 2 -------- There is no active support for Python 2. However, it is compatible as of -February 2019, if you install ``funcsigs``, included in the `python2` +February 2019, if you install ``funcsigs``, included in the ``python2`` extra requirements. From 3fd88791c2a61df7a6d878d5d483820ac4659c1d Mon Sep 17 00:00:00 2001 From: Julio Trigo Date: Sat, 13 Apr 2019 17:55:34 +0100 Subject: [PATCH 9/9] Amend README library quote --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 713b3dc..42e5fb5 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,8 @@ SQLAlchemy filters .. pull-quote:: - Filter, sort and paginate SQLAlchemy_ query objects. - Ideal for exposing these actions over a REST API. + Filter, sort and paginate SQLAlchemy query objects. Ideal for + exposing these actions over a REST API. .. image:: https://img.shields.io/pypi/v/sqlalchemy-filters.svg