Skip to content

Commit

Permalink
GitHub Action to spellcheck and lint Python code (#333)
Browse files Browse the repository at this point in the history
* GitHub Action to spellcheck and lint Python code

* Update pyproject.toml

Co-authored-by: William Woodruff <[email protected]>

* $(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 <[email protected]>
  • Loading branch information
cclauss and woodruffw authored Apr 28, 2024
1 parent 0e091c6 commit 6d5049a
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions cachecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Make it easy to import from cachecontrol without long namespaces.
"""

__author__ = "Eric Larson"
__email__ = "[email protected]"
__version__ = "0.14.0"
Expand Down
1 change: 1 addition & 0 deletions cachecontrol/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cachecontrol/caches/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cachecontrol/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
The httplib2 algorithms ported for use with requests.
"""

from __future__ import annotations

import calendar
Expand Down
4 changes: 2 additions & 2 deletions cachecontrol/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
5 changes: 4 additions & 1 deletion cachecontrol/heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/etags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -77,3 +78,4 @@ ignore_missing_imports = true

[tool.pytest.ini_options]
norecursedirs = ["bin", "lib", "include", "build"]

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ def pytest_configure(config):
def pytest_unconfigure(config):
try:
cherrypy.server.stop()
except:
except: # noqa: E722
pass
3 changes: 0 additions & 3 deletions tests/issue_263.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cache_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Test for supporting redirect caches as needed.
"""

import requests

from cachecontrol import CacheControl
Expand Down
1 change: 0 additions & 1 deletion tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0

import pickle
from unittest.mock import Mock

import msgpack
Expand Down
1 change: 1 addition & 0 deletions tests/test_storage_filecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Unit tests that verify FileCache storage works correctly.
"""

import os
import string

Expand Down

0 comments on commit 6d5049a

Please sign in to comment.