From 6d5049aa575fb3889c8cb3192463d171890995c3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 28 Apr 2024 16:53:06 +0200 Subject: [PATCH] GitHub Action to spellcheck and lint Python code (#333) * GitHub Action to spellcheck and lint Python code * Update pyproject.toml Co-authored-by: William Woodruff * $(VENV)/bin/ruff check --fix * exclude: python-version: "3.7" on os: "macos-latest" * Update tests.yml * Allow Python 3.7 on ARM to crash --------- Co-authored-by: William Woodruff --- Makefile | 4 +++- cachecontrol/__init__.py | 1 + cachecontrol/cache.py | 1 + cachecontrol/caches/file_cache.py | 2 +- cachecontrol/controller.py | 1 + cachecontrol/filewrapper.py | 4 ++-- cachecontrol/heuristics.py | 5 ++++- docs/etags.rst | 2 +- docs/index.rst | 2 +- docs/tips.rst | 2 +- pyproject.toml | 12 +++++++----- tests/conftest.py | 2 +- tests/issue_263.py | 3 --- tests/test_cache_control.py | 3 ++- tests/test_redirects.py | 1 + tests/test_serialization.py | 1 - tests/test_storage_filecache.py | 1 + 17 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 814be635..62feb922 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 82646f37..4fd76a44 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 3293b005..91598e92 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 0f941713..f7992d57 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 70414be3..f826aec0 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 25143902..37d2fa59 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 ea1badca..d95e78a9 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 0128ece5..6c9688ce 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 86688270..4e068df8 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 af00bd9c..e67668ef 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 b600b34d..b9c736f6 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 89359cc3..02dd3417 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 66075fe9..b049e481 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 7d893cd9..f77b4ddc 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 a37bb2b2..9d6932b2 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 1ae4f00a..eab1c13f 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 d9dd2419..df74a3bd 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