From 1be8258b0fc39c1e8645f2409decdd2f93cfc4bb Mon Sep 17 00:00:00 2001 From: Uman Shahzad Date: Wed, 30 Oct 2019 11:02:24 +0500 Subject: [PATCH 1/4] Properly choose defaults for cache maxsize and ttl --- ipinfo/cache/default.py | 4 ++-- ipinfo/handler.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ipinfo/cache/default.py b/ipinfo/cache/default.py index c0b12df..1583e21 100644 --- a/ipinfo/cache/default.py +++ b/ipinfo/cache/default.py @@ -10,8 +10,8 @@ class DefaultCache(CacheInterface): """Default, in-memory cache.""" - def __init__(self, maxsize, ttl, **cache_options): - self.cache = cachetools.TTLCache(maxsize, ttl, **cache_options) + def __init__(self, **cache_options): + self.cache = cachetools.TTLCache(**cache_options) def __contains__(self, key): return self.cache.__contains__(key) diff --git a/ipinfo/handler.py b/ipinfo/handler.py index 28cf6ce..2548f0e 100644 --- a/ipinfo/handler.py +++ b/ipinfo/handler.py @@ -37,9 +37,11 @@ def __init__(self, access_token=None, **kwargs): self.cache = kwargs["cache"] else: cache_options = kwargs.get("cache_options", {}) - maxsize = cache_options.get("maxsize", self.CACHE_MAXSIZE) - ttl = cache_options.get("ttl", self.CACHE_TTL) - self.cache = DefaultCache(maxsize, ttl, **cache_options) + if "maxsize" not in cache_options: + cache_options["maxsize"] = self.CACHE_MAXSIZE + if "ttl" not in cache_options: + cache_options["ttl"] = self.CACHE_TTL + self.cache = DefaultCache(**cache_options) def getDetails(self, ip_address=None): """Get details for specified IP address as a Details object.""" From eefc5aa4669b519dc1d88c140636d161bad7ab34 Mon Sep 17 00:00:00 2001 From: Uman Shahzad Date: Wed, 30 Oct 2019 11:11:35 +0500 Subject: [PATCH 2/4] Fix test since default cache requires kwargs now --- tests/default_cache_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/default_cache_test.py b/tests/default_cache_test.py index e4d1e7f..088dea3 100644 --- a/tests/default_cache_test.py +++ b/tests/default_cache_test.py @@ -4,7 +4,7 @@ def _get_new_cache(): maxsize = 4 ttl = 8 - return DefaultCache(maxsize, ttl) + return DefaultCache(maxsize=maxsize, ttl=ttl) def test_contains(): From bdc81ffb8d2f41bd6422779e05d2f2306479b32d Mon Sep 17 00:00:00 2001 From: Uman Shahzad Date: Wed, 30 Oct 2019 11:11:41 +0500 Subject: [PATCH 3/4] Upgrade dependencies --- requirements.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9078712..64f381b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,26 +2,29 @@ # This file is autogenerated by pip-compile # To update, run: # -# pip-compile --no-index +# pip-compile --no-emit-trusted-host --no-index # appdirs==1.4.3 # via black atomicwrites==1.3.0 # via pytest -attrs==19.1.0 # via black, pytest +attrs==19.3.0 # via black, pytest black==19.3b0 cachetools==3.1.1 -certifi==2019.3.9 # via requests +certifi==2019.9.11 # via requests chardet==3.0.4 # via requests click==7.0 # via black, pip-tools idna==2.8 # via requests -importlib-metadata==0.18 # via pluggy -more-itertools==7.0.0 # via pytest +importlib-metadata==0.23 # via pluggy +more-itertools==7.2.0 # via pytest, zipp pip-tools==3.7.0 -pluggy==0.12.0 # via pytest +pluggy==0.13.0 # via pytest py==1.8.0 # via pytest pytest==4.5.0 requests==2.22.0 six==1.12.0 # via pip-tools, pytest toml==0.10.0 # via black -urllib3==1.25.3 # via requests +urllib3==1.25.6 # via requests wcwidth==0.1.7 # via pytest -zipp==0.5.1 # via importlib-metadata +zipp==0.6.0 # via importlib-metadata + +# The following packages are considered to be unsafe in a requirements file: +# setuptools==41.6.0 # via pytest From 71c08ecb68b93cd160c5c1ab2f6717a3d41c5a1e Mon Sep 17 00:00:00 2001 From: Uman Shahzad Date: Wed, 30 Oct 2019 11:16:54 +0500 Subject: [PATCH 4/4] Major bump - DefaultCache's constructor interface was changed a bit --- CHANGELOG.md | 17 +++++++++++++++++ setup.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a258c29..14bafe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,24 @@ # IPInfo Changelog +## 3.0.0 + +#### Breaking Changes + +- [PR #19](https://github.com/ipinfo/python/pull/19) + DefaultCache requires keyword arguments now instead of positional arguments, + in particular `maxsize` and `ttl`. + +#### Bug Fix + +- [PR #19](https://github.com/ipinfo/python/pull/19) + [Issue #18](https://github.com/ipinfo/python/issues/18) + An issue with the handler not being created if you provide your own custom + `maxsize`/`ttl` values has been fixed. + ## 2.1.0 +#### General + - Released a batch ops function on the handler called `getBatchDetails` which accepts a list of IP addresses (or an IP address plus a path to more specific details, e.g. `8.8.8.8/country`). See documentation on batch operations in the diff --git a/setup.py b/setup.py index 032b59b..5a859c4 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="ipinfo", - version="2.1.0", + version="3.0.0", description="Official Python library for IPInfo", long_description=long_description, url="https://github.com/ipinfo/python",