Skip to content

Commit

Permalink
Merge pull request #8 from 72squared/devel
Browse files Browse the repository at this point in the history
Make compatible with python3.7
  • Loading branch information
72squared committed Dec 28, 2022
2 parents ec1577c + cee5ef3 commit 4c93b06
Show file tree
Hide file tree
Showing 23 changed files with 818 additions and 553 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
@@ -1,15 +1,10 @@
sudo: false
language: python
python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "nightly"
- "pypy"
# pypy3 doesn't work with redislite
# redpipe should work with it but it's too much of a pain to test.
# https://bitbucket.org/pypy/pypy/issues/2450/cant-import-psutil-on-pypy3-missing
- "pypy3"

install:
Expand All @@ -26,7 +21,8 @@ env:
script:
- coverage erase
- coverage run --source redpipe -p test.py
- flake8 --exclude="./build,.venv*,.tox,dist"
- flake8 --exclude=./build,.venv*,.tox,dist
- mypy redpipe test.py

after_success:
- coverage combine
Expand All @@ -37,6 +33,8 @@ matrix:
- python: "nightly"
- python: "pypy3"
include:
- python: 3.7
- python: 3.8
- python: 3.9
dist: xenial
sudo: true
9 changes: 4 additions & 5 deletions dev-requirements.txt
@@ -1,10 +1,9 @@
-r requirements.txt
coverage >= 3.7.1
tox
importlib_metadata<5
flake8
python-coveralls
mypy
coveralls
types-redis
redislite>=3.0.271
pytest-benchmark
twine
wheel

3 changes: 2 additions & 1 deletion docs/disclaimer.rst
Expand Up @@ -35,7 +35,8 @@ Character Encoding
------------------
To be honest, I never spent a whole lot of time thinking about character encoding in redis until recently.
Most of the values I manipulate in `redis` are numbers and simple ascii keys.
And python 2 doesn't make you think about character encoding vs bytes much at all.
When I wrote this library originally for python 2, it doesn't make you think about character
encoding vs bytes much at all.
However, I think a good library should fully support proper character encoding.
And since RedPipe is fully tested on python 3, I am making more of an effort to understand the nuances.

Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Expand Up @@ -18,7 +18,7 @@ If you have no idea what Redis is or why you should pipeline commands, `look it
Requirements
------------

The *redpipe* module requires Python 2.7 or higher.
The *redpipe* module requires Python 3 or higher.

It also requires `redis-py`_.

Expand Down Expand Up @@ -153,7 +153,7 @@ You can see everything.
.. |Version| image:: https://badge.fury.io/py/redpipe.svg
:target: https://badge.fury.io/py/redpipe

.. |Python| image:: https://img.shields.io/badge/python-2.7,3.4,pypy-blue.svg
.. |Python| image:: https://img.shields.io/badge/python-3.8,3.9,pypy3-blue.svg
:target: https://pypi.python.org/pypi/redpipe/

.. _report any issues: https://github.com/72squared/redpipe/issues
Expand Down
1 change: 1 addition & 0 deletions docs/redis-cluster.rst
Expand Up @@ -15,3 +15,4 @@ This became even easier now that redis-py supports redis cluster natively.
The reason you can do this is because **RedPipe** wraps the interface.

If it quacks like a duck ...

12 changes: 11 additions & 1 deletion docs/release-notes.rst
@@ -1,6 +1,16 @@
Release Notes
=============

4.0.1 (December 28, 2022)
-------------------------
Modify Protocol import to allow python 3.7 to work.

4.0.0 (December 27, 2022)
-------------------------
Add support for type hints. Remove any python 2 references.
Remove dependency on "six" library now that only python3 is supported.


3.0.1 (December 26, 2022)
-------------------------
Update the docs to reflect deprecation of redis-py-cluster.
Expand Down Expand Up @@ -60,7 +70,7 @@ In python documentation it states:
"Note For new-style classes, if __getstate__() returns a false value,
the __setstate__() method will not be called."

reference: https://docs.python.org/2/library/pickle.html
reference: https://docs.python.org/3/library/pickle.html

The fix is to return a dictionary with the result in __getstate__ and expect one
in __setstate__ so the value never evaluates to false.
Expand Down
5 changes: 0 additions & 5 deletions docs/structs.rst
Expand Up @@ -156,11 +156,6 @@ You can iterate on the object like a dictionary:
assert({k: v for k, v in user.items()} == user)
You can see the user object has an `items` method.
There is also a `iteritems` method for backward compatibility with python 2.
The `iteritems` method is a generator, whereas `items` returns a list of key/value tuples.


You can access an unknown data element like you would a dictionary:

.. code-block:: python
Expand Down
6 changes: 2 additions & 4 deletions docs/testing.rst
Expand Up @@ -56,10 +56,8 @@ To go through a more thorough test suite, run:
This will run tox against a bunch of different python versions and print out coverage.
To run this, you need the following python versions installed and discoverable in your path:

* python2.7
* python3.3
* python3.4
* python3.5
* python3.8
* python3.9

This will also print out code coverage statistics and lint tests.

Expand Down
5 changes: 5 additions & 0 deletions local-dev-requirements.txt
@@ -0,0 +1,5 @@
-r dev-requirements.txt
tox
pytest-benchmark
twine
wheel
3 changes: 2 additions & 1 deletion redpipe/VERSION
@@ -1 +1,2 @@
3.0.1
4.0.1

2 changes: 2 additions & 0 deletions redpipe/__init__.py
Expand Up @@ -85,9 +85,11 @@
from .version import __version__ # noqa
from .pipelines import * # noqa
from .fields import * # noqa
from .fields import (StringListField, TextField, IntegerField, Field) # noqa
from .connections import * # noqa
from .structs import * # noqa
from .keyspaces import * # noqa
from .keyspaces import (String, HashedString, Set, List, SortedSet, Hash, HyperLogLog) # noqa
from .exceptions import * # noqa
from .futures import * # noqa
from .tasks import * # noqa
27 changes: 15 additions & 12 deletions redpipe/connections.py
Expand Up @@ -14,6 +14,8 @@
Everything else is for internal use.
"""
import redis
from typing import (Optional, Callable, Dict)
from .exceptions import AlreadyConnected, InvalidPipeline

__all__ = [
Expand All @@ -35,10 +37,10 @@ class ConnectionManager(object):
* reset
"""
connections = {}
connections: Dict[Optional[str], Callable] = {}

@classmethod
def get(cls, name=None):
def get(cls, name: Optional[str] = None) -> redis.client.Pipeline:
"""
Get a new redis-py pipeline object or similar object.
Called by the redpipe.pipelines module.
Expand All @@ -53,7 +55,8 @@ def get(cls, name=None):
raise InvalidPipeline('%s is not configured' % name)

@classmethod
def connect(cls, pipeline_method, name=None):
def connect(cls, pipeline_method: Callable,
name: Optional[str] = None) -> None:
"""
Low level logic to bind a callable method to a name.
Don't call this directly unless you know what you are doing.
Expand All @@ -72,7 +75,7 @@ def connect(cls, pipeline_method, name=None):
cls.connections[name] = pipeline_method

@classmethod
def connect_redis(cls, redis_client, name=None, transaction=False):
def connect_redis(cls, redis_client, name=None, transaction=False) -> None:
"""
Store the redis connection in our connector instance.
Expand Down Expand Up @@ -120,7 +123,7 @@ def pipeline_method():
cls.connect(pipeline_method=pipeline_method, name=name)

@classmethod
def disconnect(cls, name=None):
def disconnect(cls, name: Optional[str] = None) -> None:
"""
remove a connection by name.
If no name is passed in, it assumes default.
Expand All @@ -136,7 +139,7 @@ def disconnect(cls, name=None):
pass

@classmethod
def reset(cls):
def reset(cls) -> None:
"""
remove all connections.
Useful for testing scenarios.
Expand All @@ -146,7 +149,7 @@ def reset(cls):
cls.connections = {}


def connect_redis(redis_client, name=None, transaction=False):
def connect_redis(redis_client, name=None, transaction=False) -> None:
"""
Connect your redis-py instance to redpipe.
Expand Down Expand Up @@ -178,11 +181,11 @@ def connect_redis(redis_client, name=None, transaction=False):
:param transaction:
:return:
"""
return ConnectionManager.connect_redis(
ConnectionManager.connect_redis(
redis_client=redis_client, name=name, transaction=transaction)


def disconnect(name=None):
def disconnect(name: Optional[str] = None) -> None:
"""
remove a connection by name.
If no name is passed in, it assumes default.
Expand All @@ -198,10 +201,10 @@ def disconnect(name=None):
:param name:
:return: None
"""
return ConnectionManager.disconnect(name=name)
ConnectionManager.disconnect(name=name)


def reset():
def reset() -> None:
"""
remove all connections.
Expand All @@ -218,4 +221,4 @@ def reset():
:return: None
"""
return ConnectionManager.reset()
ConnectionManager.reset()

0 comments on commit 4c93b06

Please sign in to comment.