From aa5601a59b678ea7d54c4d9f963d622da2b47dde Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 13 Mar 2025 09:20:47 +0900 Subject: [PATCH 1/3] Fix format --- .github/workflows/python-package.yml | 9 +++---- ring/__init__.py | 1 + ring/coder.py | 3 ++- ring/django.py | 3 ++- ring/func/__init__.py | 1 + ring/func/asyncio.py | 29 +++++++++++----------- ring/func/base.py | 7 +++--- ring/func/sync.py | 37 ++++++++++++++-------------- tests/_test_callable_py3.py | 1 - tests/django_app.py | 1 + 10 files changed, 47 insertions(+), 45 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 75c27c9..c94537a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["2.7", "3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v2 @@ -29,12 +29,11 @@ jobs: run: | sudo apt-get install libmemcached-dev python -m pip install --upgrade pip - python --version | grep '3.' && python -m pip install black + python -m pip install ruff python -m pip install -e '.[tests]' - - name: Lint with black + - name: Lint with ruff run: | - black --check ring tests setup.py - if: matrix.python-version != '2.7' + ruff format --diff ring tests setup.py - name: Start containers run: docker-compose -f "docker-compose.yml" up -d --build - name: Test with pytest diff --git a/ring/__init__.py b/ring/__init__.py index ce3d895..4ffec25 100644 --- a/ring/__init__.py +++ b/ring/__init__.py @@ -3,6 +3,7 @@ Common ring decorators are aliased in this level as shortcuts. """ + import ring.coder # noqa from ring.__version__ import __version__ # noqa from ring.func import lru, dict, shelve, disk, memcache, redis, redis_hash diff --git a/ring/coder.py b/ring/coder.py index 7909851..087446d 100644 --- a/ring/coder.py +++ b/ring/coder.py @@ -4,6 +4,7 @@ Coder is a configurable layer that provides ways to encode raw data and decode stored cache data. """ + import abc import six from collections import namedtuple @@ -105,7 +106,7 @@ def get_or_coderize(self, raw_coder): if coder is None: if isinstance(raw_coder, str): # py2 support raise TypeError( - "The given coder is not a registered name in coder " "registry." + "The given coder is not a registered name in coder registry." ) coder = coderize(raw_coder) return coder diff --git a/ring/django.py b/ring/django.py index 608469c..8612a89 100644 --- a/ring/django.py +++ b/ring/django.py @@ -1,6 +1,7 @@ """:mod:`ring.django` --- Django support ======================================== """ + from __future__ import absolute_import import warnings @@ -47,7 +48,7 @@ def transform_cache_page_args(wire, rules, args, kwargs): raw_request = args[0] if isinstance(raw_request, HttpRequest): request = raw_request - elif type(raw_request) == tuple: + elif type(raw_request) is tuple: template_request, path_hint = raw_request if not isinstance(template_request, HttpRequest): raise TypeError diff --git a/ring/func/__init__.py b/ring/func/__init__.py index 75280dc..6f2a245 100644 --- a/ring/func/__init__.py +++ b/ring/func/__init__.py @@ -3,6 +3,7 @@ Ring object factory functions are aggregated in this module. """ + from __future__ import absolute_import from ring.func import sync diff --git a/ring/func/asyncio.py b/ring/func/asyncio.py index 7f303e3..9a4d0a3 100644 --- a/ring/func/asyncio.py +++ b/ring/func/asyncio.py @@ -4,6 +4,7 @@ This module includes building blocks and storage implementations of **Ring** factories for :mod:`asyncio`. """ + import sys from functools import wraps, partial @@ -174,9 +175,7 @@ class CacheUserInterface(fbase.BaseUserInterface): details. """ - @fbase.interface_attrs( - return_annotation=lambda a: Optional[a.get("return", Any)] - ) # noqa: F722 + @fbase.interface_attrs(return_annotation=lambda a: Optional[a.get("return", Any)]) # noqa: F722 async def get(self, wire, **kwargs): key = self.key(wire, **kwargs) try: @@ -565,7 +564,7 @@ def dict( coder=None, user_interface=CacheUserInterface, storage_class=None, - **kwargs + **kwargs, ): """:class:`dict` interface for :mod:`asyncio`. @@ -587,7 +586,7 @@ def dict( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -599,7 +598,7 @@ def aiomcache( user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=AiomcacheStorage, key_encoding="utf-8", - **kwargs + **kwargs, ): """Memcached_ interface for :mod:`asyncio`. @@ -639,7 +638,7 @@ def aiomcache( coder=coder, key_encoding=key_encoding, key_refactor=key_refactor, - **kwargs + **kwargs, ) @@ -650,7 +649,7 @@ def aioredis1( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=Aioredis1Storage, - **kwargs + **kwargs, ): """Redis interface for :mod:`asyncio`. @@ -708,7 +707,7 @@ def aioredis1( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -719,7 +718,7 @@ def aioredis1_hash( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=Aioredis1HashStorage, - **kwargs + **kwargs, ): """Redis interface for :mod:`asyncio`. @@ -772,7 +771,7 @@ def aioredis1_hash( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -783,7 +782,7 @@ def aioredis2( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=Aioredis2Storage, - **kwargs + **kwargs, ): """Redis interface for :mod:`asyncio`. @@ -841,7 +840,7 @@ def aioredis2( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -852,7 +851,7 @@ def aioredis2_hash( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=Aioredis2HashStorage, - **kwargs + **kwargs, ): """Redis interface for :mod:`asyncio`. @@ -905,7 +904,7 @@ def aioredis2_hash( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) diff --git a/ring/func/base.py b/ring/func/base.py index 2ca9e32..166f8bc 100644 --- a/ring/func/base.py +++ b/ring/func/base.py @@ -1,7 +1,8 @@ -""":mod:`ring.func.base` --- The building blocks of **ring.func.\***. +""":mod:`ring.func.base` --- The building blocks of **ring.func.* **. ===================================================================== """ # noqa: W605 + import abc import collections import types @@ -213,7 +214,7 @@ def coerce_function(t): if issubclass(t, (list, tuple)): return _coerce_list_and_tuple - if t == type: + if t is type: return _coerce_type if issubclass(t, dict): @@ -269,7 +270,7 @@ def interface_attrs(**kwargs): if "transform_args" in kwargs: transform_args = kwargs.pop("transform_args") if transform_args: - if type(transform_args) != tuple: + if type(transform_args) is not tuple: transform_args = transform_args, {} func, rules = transform_args assert frozenset(rules.keys()) <= frozenset({"prefix_count"}) diff --git a/ring/func/sync.py b/ring/func/sync.py index eba4bd0..66237dc 100644 --- a/ring/func/sync.py +++ b/ring/func/sync.py @@ -4,6 +4,7 @@ This module includes building blocks and storage implementations of **Ring** factories. """ + from ring.typing import Any, Optional, List import time import re @@ -29,9 +30,7 @@ class CacheUserInterface(fbase.BaseUserInterface): details. """ - @fbase.interface_attrs( - return_annotation=lambda a: Optional[a.get("return", Any)] - ) # noqa: F722 + @fbase.interface_attrs(return_annotation=lambda a: Optional[a.get("return", Any)]) # noqa: F722 def get(self, wire, pargs): key = self.key(wire, pargs=pargs) try: @@ -413,7 +412,7 @@ def lru( user_interface=CacheUserInterface, storage_class=LruStorage, maxsize=128, - **kwargs + **kwargs, ): """LRU(Least-Recently-Used) cache interface. @@ -456,7 +455,7 @@ def lru( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -467,7 +466,7 @@ def dict( coder=None, user_interface=CacheUserInterface, storage_class=None, - **kwargs + **kwargs, ): """Basic Python :class:`dict` based cache. @@ -502,7 +501,7 @@ def dict( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -512,7 +511,7 @@ def shelve( coder=None, user_interface=CacheUserInterface, storage_class=ShelveStorage, - **kwargs + **kwargs, ): """Python :mod:`shelve` based cache. @@ -536,7 +535,7 @@ def shelve( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -547,7 +546,7 @@ def memcache( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=MemcacheStorage, - **kwargs + **kwargs, ): """Common Memcached_ interface. @@ -616,7 +615,7 @@ def memcache( expire_default=expire, coder=coder, key_refactor=key_refactor, - **kwargs + **kwargs, ) @@ -627,7 +626,7 @@ def redis_py( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=RedisStorage, - **kwargs + **kwargs, ): """Redis_ interface. @@ -667,7 +666,7 @@ def redis_py( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -678,7 +677,7 @@ def redis_py_hash( coder=None, user_interface=(CacheUserInterface, BulkInterfaceMixin), storage_class=RedisHashStorage, - **kwargs + **kwargs, ): """ This backend depends on `redis-py`_. @@ -716,7 +715,7 @@ def redis_py_hash( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -727,7 +726,7 @@ def diskcache( coder=None, user_interface=CacheUserInterface, storage_class=DiskCacheStorage, - **kwargs + **kwargs, ): """diskcache_ interface. @@ -751,7 +750,7 @@ def diskcache( miss_value=None, expire_default=expire, coder=coder, - **kwargs + **kwargs, ) @@ -762,7 +761,7 @@ def arcus( coder=None, default_action="get_or_update", user_interface=CacheUserInterface, - **kwargs + **kwargs, ): # pragma: no cover """Arcus support. deprecated.""" @@ -806,5 +805,5 @@ def key_refactor(key): expire_default=expire, coder=coder, key_refactor=key_refactor, - **kwargs + **kwargs, ) diff --git a/tests/_test_callable_py3.py b/tests/_test_callable_py3.py index d0b75b4..d64f608 100644 --- a/tests/_test_callable_py3.py +++ b/tests/_test_callable_py3.py @@ -1,4 +1,3 @@ -import asyncio from typing import Any, Optional from ring.callable import Callable from ring.func.base import ArgPack diff --git a/tests/django_app.py b/tests/django_app.py index d252478..416d569 100644 --- a/tests/django_app.py +++ b/tests/django_app.py @@ -7,6 +7,7 @@ django-admin runserver --pythonpath=. --settings=django_app """ + import random import string import datetime From 6552d1cc7a4659b273ebb55f6cf8afcb967d64e9 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Wed, 26 Mar 2025 14:22:21 +0900 Subject: [PATCH 2/3] Try fix docker --- .github/workflows/python-package.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c94537a..e67d3a1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -11,6 +11,14 @@ on: jobs: build: + services: + redis: + image: redis + ports: ['6379:6379'] + memcached: + image: memcached + ports: ['11211:11211'] + runs-on: ubuntu-latest strategy: fail-fast: false @@ -34,13 +42,9 @@ jobs: - name: Lint with ruff run: | ruff format --diff ring tests setup.py - - name: Start containers - run: docker-compose -f "docker-compose.yml" up -d --build - name: Test with pytest run: | pytest - - name: Stop containers - run: docker-compose -f "docker-compose.yml" down - name: Codecov run: bash <(curl -s https://codecov.io/bash) From 9e6c6e7e82f267541ee5aeeb919d6c769701bd2c Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 28 Mar 2025 10:13:20 +0900 Subject: [PATCH 3/3] Try fix test --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index efce989..7648a38 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def get_version(): 'functools32>=3.2.3-2;python_version<"3.0"', ] tests_require = [ - "pytest>=3.10.1", + "pytest<8", "pytest-cov", "pytest-lazy-fixture>=0.6.2", "mock",