diff --git a/Makefile b/Makefile index 814be63..62feb92 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,9 @@ bootstrap: $(VENV)/bin/pip $(VENV)/bin/pip install -e .[dev] format: - $(VENV)/bin/black . + $(VENV)/bin/codespell + $(VENV)/bin/ruff check --fix + $(VENV)/bin/ruff format doc: $(VENV)/bin/sphinx-build . $(ACTIVATE); diff --git a/cachecontrol/__init__.py b/cachecontrol/__init__.py index 82646f3..4fd76a4 100644 --- a/cachecontrol/__init__.py +++ b/cachecontrol/__init__.py @@ -6,6 +6,7 @@ Make it easy to import from cachecontrol without long namespaces. """ + __author__ = "Eric Larson" __email__ = "eric@ionrock.org" __version__ = "0.14.0" diff --git a/cachecontrol/cache.py b/cachecontrol/cache.py index 3293b00..91598e9 100644 --- a/cachecontrol/cache.py +++ b/cachecontrol/cache.py @@ -6,6 +6,7 @@ The cache object API for implementing caches. The default is a thread safe in-memory dictionary. """ + from __future__ import annotations from threading import Lock diff --git a/cachecontrol/caches/file_cache.py b/cachecontrol/caches/file_cache.py index 0f94171..f7992d5 100644 --- a/cachecontrol/caches/file_cache.py +++ b/cachecontrol/caches/file_cache.py @@ -6,7 +6,7 @@ import hashlib import os from textwrap import dedent -from typing import IO, TYPE_CHECKING, Union +from typing import IO, TYPE_CHECKING from pathlib import Path from cachecontrol.cache import BaseCache, SeparateBodyBaseCache diff --git a/cachecontrol/controller.py b/cachecontrol/controller.py index 70414be..f826aec 100644 --- a/cachecontrol/controller.py +++ b/cachecontrol/controller.py @@ -5,6 +5,7 @@ """ The httplib2 algorithms ported for use with requests. """ + from __future__ import annotations import calendar diff --git a/cachecontrol/filewrapper.py b/cachecontrol/filewrapper.py index 2514390..37d2fa5 100644 --- a/cachecontrol/filewrapper.py +++ b/cachecontrol/filewrapper.py @@ -38,10 +38,10 @@ def __init__( self.__callback = callback def __getattr__(self, name: str) -> Any: - # The vaguaries of garbage collection means that self.__fp is + # The vagaries of garbage collection means that self.__fp is # not always set. By using __getattribute__ and the private # name[0] allows looking up the attribute value and raising an - # AttributeError when it doesn't exist. This stop thigns from + # AttributeError when it doesn't exist. This stop things from # infinitely recursing calls to getattr in the case where # self.__fp hasn't been set. # diff --git a/cachecontrol/heuristics.py b/cachecontrol/heuristics.py index ea1badc..d95e78a 100644 --- a/cachecontrol/heuristics.py +++ b/cachecontrol/heuristics.py @@ -68,7 +68,10 @@ def update_headers(self, response: HTTPResponse) -> dict[str, str]: if "expires" not in response.headers: date = parsedate(response.headers["date"]) - expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[index,misc] + expires = expire_after( + timedelta(days=1), + date=datetime(*date[:6], tzinfo=timezone.utc), # type: ignore[index,misc] + ) headers["expires"] = datetime_to_header(expires) headers["cache-control"] = "public" return headers diff --git a/docs/etags.rst b/docs/etags.rst index 0128ece..6c9688c 100644 --- a/docs/etags.rst +++ b/docs/etags.rst @@ -18,7 +18,7 @@ expired. In CacheControl the default behavior when an ETag is sent by the server is to cache the response. We'll refer to this pattern as a **Equal Priority** cache as the decision to cache is either time base or -due to the presense of an ETag. +due to the presence of an ETag. The spec is not explicit what takes priority when caching with both ETags and time based headers. Therefore, CacheControl supports the diff --git a/docs/index.rst b/docs/index.rst index 8668827..4e068df 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,7 +66,7 @@ effort to faithfully port the tests from httplib2 to CacheControl, but there is a decent chance that I've missed something. Please file bugs if you find any issues! -With that in mind, CacheControl has been used sucessfully in +With that in mind, CacheControl has been used successfully in production environments, replacing httplib2's usage. If you give it a try, please let me know of any issues. diff --git a/docs/tips.rst b/docs/tips.rst index af00bd9..e67668e 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -43,7 +43,7 @@ response. With that in mind, you should be aware that if you try to cache a very large response on a network store, you still might have some latency -tranferring the data from the network store to your +transferring the data from the network store to your application. Another consideration is storing large responses in a `FileCache`. If you are caching using ETags and the server is extremely specific as to what constitutes an equivalent request, it diff --git a/pyproject.toml b/pyproject.toml index b600b34..b9c736f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,15 +50,16 @@ redis = ["redis>=2.10.5"] dev = [ "CacheControl[filecache,redis]", "build", + "cherrypy", + "codespell[tomli]", + "furo", "mypy", - "tox", - "pytest-cov", "pytest", - "cherrypy", + "pytest-cov", + "ruff", "sphinx", - "furo", "sphinx-copybutton", - "black", + "tox", "types-redis", "types-requests", ] @@ -77,3 +78,4 @@ ignore_missing_imports = true [tool.pytest.ini_options] norecursedirs = ["bin", "lib", "include", "build"] + diff --git a/tests/conftest.py b/tests/conftest.py index 89359cc..02dd341 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -160,5 +160,5 @@ def pytest_configure(config): def pytest_unconfigure(config): try: cherrypy.server.stop() - except: + except: # noqa: E722 pass diff --git a/tests/issue_263.py b/tests/issue_263.py index 66075fe..b049e48 100644 --- a/tests/issue_263.py +++ b/tests/issue_263.py @@ -13,9 +13,6 @@ clogger.setLevel(logging.DEBUG) -from pprint import pprint - - class NoAgeHeuristic(BaseHeuristic): def update_headers(self, response): if "cache-control" in response.headers: diff --git a/tests/test_cache_control.py b/tests/test_cache_control.py index 7d893cd..f77b4dd 100644 --- a/tests/test_cache_control.py +++ b/tests/test_cache_control.py @@ -5,6 +5,7 @@ """ Unit tests that verify our caching methods work correctly. """ + import time from tempfile import mkdtemp from unittest.mock import ANY, Mock @@ -175,7 +176,7 @@ def update_cached_response_with_valid_headers_test(self, cache): This is the shared utility for any cache object. """ - # Cache starts out prepopulated wih an entry: + # Cache starts out prepopulated with an entry: etag = "jfd9094r808" cc = CacheController(cache) url = "http://localhost:123/x" diff --git a/tests/test_redirects.py b/tests/test_redirects.py index a37bb2b..9d6932b 100644 --- a/tests/test_redirects.py +++ b/tests/test_redirects.py @@ -5,6 +5,7 @@ """ Test for supporting redirect caches as needed. """ + import requests from cachecontrol import CacheControl diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 1ae4f00..eab1c13 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: Apache-2.0 -import pickle from unittest.mock import Mock import msgpack diff --git a/tests/test_storage_filecache.py b/tests/test_storage_filecache.py index d9dd241..df74a3b 100644 --- a/tests/test_storage_filecache.py +++ b/tests/test_storage_filecache.py @@ -5,6 +5,7 @@ """ Unit tests that verify FileCache storage works correctly. """ + import os import string