Skip to content

Commit f08c14d

Browse files
Refactor pkg_resources -> importlib (#39)
* pkg_resources -> importlib * drop setuptools requirement from CI * update trove classifiers * fix line too long * fix import sort * disutils -> packaging * actually... just drop support for redispy 2.x
1 parent e98cc87 commit f08c14d

4 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jobs:
4242
- name: Install Python dependencies
4343
run: |
4444
python -m pip install --upgrade pip
45-
pip install setuptools
4645
pip install flake8 flake8-docstrings flake8-polyfill pep8 pep8-naming isort
4746
pip install --no-deps -r requirements.txt
4847
pip install -r requirements_test.txt

‎limitlion/running_counter.py‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import itertools
22
import time
33
from collections import namedtuple
4-
from distutils.version import LooseVersion
5-
6-
import pkg_resources
7-
8-
REDIS_PY_VERSION = pkg_resources.get_distribution("redis").version
9-
IS_REDIS_PY_2 = LooseVersion(REDIS_PY_VERSION) < LooseVersion("3")
10-
114

125
BucketCount = namedtuple('BucketCount', ['bucket', 'count'])
136

@@ -204,10 +197,7 @@ def inc(self, increment=1, name=None):
204197
pipeline.expire(bucket_key, expire)
205198
if self.group_name is not None:
206199
group_key = self._group_key()
207-
if IS_REDIS_PY_2:
208-
pipeline.zadd(group_key, name, now)
209-
else:
210-
pipeline.zadd(group_key, {name: now})
200+
pipeline.zadd(group_key, {name: now})
211201
pipeline.expire(group_key, expire)
212202
# Trim zset to keys used within window so
213203
# it doesn't grow uncapped.

‎limitlion/throttle.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Token bucket throttle backed by Redis."""
22

33
import time
4-
5-
import pkg_resources
4+
from importlib import resources
65

76
KEY_FORMAT = 'throttle:{}'
87

@@ -105,9 +104,9 @@ def throttle_configure(redis_instance, testing=False):
105104
global redis, throttle_script
106105
redis = redis_instance
107106

108-
lua_script = pkg_resources.resource_string(
109-
__name__, 'throttle.lua'
110-
).decode()
107+
lua_script = (
108+
resources.files(__package__).joinpath('throttle.lua').read_text()
109+
)
111110

112111
# Modify scripts when testing so time can be frozen
113112
if testing:

‎setup.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
'License :: OSI Approved :: MIT License',
2323
'Operating System :: OS Independent',
2424
'Programming Language :: Python :: 3',
25-
'Programming Language :: Python :: 3.5',
26-
'Programming Language :: Python :: 3.6',
25+
'Programming Language :: Python :: 3.10',
26+
'Programming Language :: Python :: 3.11',
27+
'Programming Language :: Python :: 3.12',
28+
'Programming Language :: Python :: 3.13',
2729
'Topic :: Software Development :: Libraries :: Python Modules',
2830
],
2931
packages=[

0 commit comments

Comments
 (0)