Skip to content

Commit

Permalink
Add Python 3.8-3.10 support (#42)
Browse files Browse the repository at this point in the history
* bump python to 3.8/3.9/3.10 and test requirements, fix pytest command in makefile, fix tests

* tox 4, isort + ruff + mypy instead of flake8 + pylint

* move project config from setup.py to pyproject.toml, move CI from travis to github actions

---------

Co-authored-by: aras2137 <[email protected]>
  • Loading branch information
5362396 and aras2137 committed Feb 2, 2024
1 parent e426fe2 commit e737349
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 156 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: nameko-sqlalchemy CI build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 2
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
- name: Upgrade pip
run: pip install pip setuptools wheel --upgrade
- name: Install tox
run: pip install tox tox-gh-actions
- name: Run tox
run: python -m tox
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.coverage
*.pyc
.venv
.idea

## Packages
*.egg-info
dist
.tox
.tox
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Release Notes
=============

Version 2.0.0
-------------

Released 2023-12-11

* Updated project to modern standards and reformatted code
* Dropped support for Python 2.7, 3.4, 3.5, 3.6, 3.7
* Added support for Python 3.8, 3.9, 3.10
* Switched from flake8 + pylint to isort + ruff + mypy
* Updated tox to 4+
* Moved package config from setup.py to pyproject.toml
* Moved CI from travis to github actions


Version 1.5.0
-------------

Expand Down
21 changes: 5 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
test: flake8 pylint pytest

flake8:
flake8 nameko_sqlalchemy test setup.py

pylint:
pylint nameko_sqlalchemy -E

pytest: test-deps
test: test-deps
coverage run --concurrency=eventlet --source nameko_sqlalchemy --branch -m \
pytest test \
--test-db-url="mysql+pymysql://test_user:password@$(shell docker port nameko_sqlalchemy_test_mysql 3306)/nameko_sqlalchemy_test" \
--toxiproxy-api-url=$(shell docker port nameko_sqlalchemy_test_toxiproxy 8474) \
--toxiproxy-db-url="mysql+pymysql://test_user:password@$(shell docker port nameko_sqlalchemy_test_toxiproxy 3307)/nameko_sqlalchemy_test"
--test-db-url="mysql+pymysql://test_user:password@$(shell docker port nameko_sqlalchemy_test_mysql 3306 | grep -v '::')/nameko_sqlalchemy_test" \
--toxiproxy-api-url=$(shell docker port nameko_sqlalchemy_test_toxiproxy 8474 | grep -v '::') \
--toxiproxy-db-url="mysql+pymysql://test_user:password@$(shell docker port nameko_sqlalchemy_test_toxiproxy 3307 | grep -v '::')/nameko_sqlalchemy_test"
coverage report --show-missing --fail-under=100

test-deps: container-cleanup mysql-setup toxiproxy-setup

start-containers:
@echo Starting docker containers...

toxiproxy-container:
docker run --rm -d -p 8474 -p 3307 --name=nameko_sqlalchemy_test_toxiproxy shopify/toxiproxy

Expand All @@ -27,7 +16,7 @@ mysql-container:

toxiproxy-setup: toxiproxy-container
@echo Setting up toxiproxy to mysql
docker exec -it nameko_sqlalchemy_test_toxiproxy /go/bin/toxiproxy-cli \
docker exec nameko_sqlalchemy_test_toxiproxy /go/bin/toxiproxy-cli \
create nameko_sqlalchemy_test_mysql \
--listen=0.0.0.0:3307 \
--upstream=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nameko_sqlalchemy_test_mysql`:3306
Expand Down
4 changes: 2 additions & 2 deletions nameko_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from nameko_sqlalchemy.database import ( # noqa: F401
Database,
DB_URIS_KEY,
DB_ENGINE_OPTIONS_KEY,
DB_SESSION_OPTIONS_KEY,
DB_URIS_KEY,
Database,
)
from nameko_sqlalchemy.database_session import DatabaseSession # noqa: F401
from nameko_sqlalchemy.transaction_retry import transaction_retry # noqa: F401
1 change: 0 additions & 1 deletion nameko_sqlalchemy/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sqlalchemy.orm import Session as BaseSession
from sqlalchemy.orm import sessionmaker


DB_URIS_KEY = 'DB_URIS'
DB_ENGINE_OPTIONS_KEY = 'DB_ENGINE_OPTIONS'
DB_SESSION_OPTIONS_KEY = 'DB_SESSION_OPTIONS'
Expand Down
2 changes: 1 addition & 1 deletion nameko_sqlalchemy/database_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from nameko_sqlalchemy import DB_URIS_KEY
from nameko_sqlalchemy.database import DB_URIS_KEY


class DatabaseSession(DependencyProvider):
Expand Down
1 change: 0 additions & 1 deletion nameko_sqlalchemy/pytest_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

Expand Down
2 changes: 1 addition & 1 deletion nameko_sqlalchemy/transaction_retry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep
import functools
import operator
from time import sleep

import wrapt
from sqlalchemy import exc
Expand Down
92 changes: 92 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[build-system]
requires = ["setuptools>=68.0"]
build-backend = "setuptools.build_meta"

[project]
name = "nameko-sqlalchemy"
version = "2.0.0"
description = "SQLAlchemy dependency for nameko services"
license = {file = "LICENSE.txt"}
readme = "README.rst"
requires-python = ">=3.8"
authors = [{name="onefinestay", email="[email protected]"}]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Internet",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"nameko>=2.0.0",
"sqlalchemy>=1.4,<2"
]

[project.urls]
Homepage = "https://github.com/onefinestay/nameko-sqlalchemy"

[project.optional-dependencies]
dev = [
"coverage==7.3.2",
"isort==5.12.0",
"mypy==1.7.1",
"pytest==7.4.3",
"requests==2.31.0",
"ruff==0.1.6",
"PyMySQL==1.1.0",
"types-mock==5.1.0.3",
"types-requests==2.31.0.10",
]

[project.entry-points."pytest11"]
nameko_sqlalchemy = "nameko_sqlalchemy.pytest_fixtures"

[tool.setuptools]
include-package-data = true
zip-safe = true

[tool.isort]
profile = "black"
multi_line_output = 3
src_paths = [
"nameko_sqlalchemy/",
"test/",
]
known_first_party = "nameko_chassis"

[tool.ruff]
extend-exclude = [
".venv",
"migrations",
]
ignore = [
"E402",
"E501",
]
select = [
"E",
"F",
"W",
]

[tool.mypy]
python_version = "3.10"
plugins = "sqlalchemy.ext.mypy.plugin"
mypy_path = "nameko_sqlalchemy/"
namespace_packages = true
no_implicit_optional = true
no_implicit_reexport = true
strict_equality = true
warn_redundant_casts = true

ignore_missing_imports = true

[tool.pytest.ini_options]
norecursedirs = [".git", ".tox", "dist", "build"]
testpaths = ["test"]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nameko>=2.0.0
sqlalchemy>=1.4,<2
50 changes: 0 additions & 50 deletions setup.py

This file was deleted.

9 changes: 4 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# You should monkey patch the standard library as early as possible to avoid
# importing anything before the patch is applied.
# See http://eventlet.net/doc/patching.html#monkeypatching-the-standard-library
import eventlet
import json

import eventlet

eventlet.monkey_patch() # noqa (code before rest of imports)

import pytest
import requests
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base


TOXIPROXY_PROXY_NAME = 'nameko_sqlalchemy_test_mysql'


Expand All @@ -32,9 +33,7 @@ def __init__(self, api_url):
self.api_url = api_url

def enable(self):
resource = 'http://{}/reset'.format(
self.api_url, TOXIPROXY_PROXY_NAME
)
resource = 'http://{}/reset'.format(self.api_url)
requests.post(resource)

def disable(self):
Expand Down
6 changes: 1 addition & 5 deletions test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
from mock import Mock, patch
from nameko.containers import ServiceContainer, WorkerContext
from nameko.testing.services import dummy, entrypoint_hook
from nameko_sqlalchemy.database import (
DB_URIS_KEY,
Database,
Session,
)
from sqlalchemy import Column, String, create_engine
from sqlalchemy.engine import Engine
from sqlalchemy.ext.declarative import declarative_base

from nameko_sqlalchemy.database import DB_URIS_KEY, Database, Session

DeclBase = declarative_base(name='examplebase')

Expand Down
7 changes: 2 additions & 5 deletions test/test_database_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import Session

from nameko_sqlalchemy import (
DatabaseSession,
DB_URIS_KEY,
)

from nameko_sqlalchemy.database import DB_URIS_KEY
from nameko_sqlalchemy.database_session import DatabaseSession

DeclBase = declarative_base(name='examplebase')

Expand Down
4 changes: 1 addition & 3 deletions test/test_pytest_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import pytest

from nameko.testing.services import dummy, worker_factory
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

from nameko_sqlalchemy import Database

from nameko_sqlalchemy.database import Database

pytest_plugins = "pytester"

Expand Down
Loading

0 comments on commit e737349

Please sign in to comment.