Skip to content

Commit

Permalink
Replace cachecontrol with a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed May 24, 2023
1 parent 9217975 commit daa3bba
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 53 deletions.
27 changes: 8 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ python = "^3.8"
poetry-core = "1.6.0"
poetry-plugin-export = "^1.3.1"
build = "^0.10.0"
cachecontrol = { version = "^0.12.9", extras = ["filecache"] }
# cacheyou uses calver, so version is unclamped
cacheyou = { version = ">=23.2", extras = ["filecache"] }
cleo = "^2.0.0"
crashtest = "^0.4.1"
dulwich = "^0.21.2"
Expand All @@ -44,7 +45,6 @@ importlib-metadata = { version = ">=4.4", python = "<3.10" }
installer = "^0.7.0"
jsonschema = "^4.10.0"
keyring = "^23.9.0"
lockfile = "^0.12.2"
# packaging uses calver, so version is unclamped
packaging = ">=20.4"
pexpect = "^4.7.0"
Expand Down Expand Up @@ -181,17 +181,14 @@ warn_unused_ignores = false

[[tool.mypy.overrides]]
module = [
'cachecontrol.*',
'deepdiff.*',
'httpretty.*',
'keyring.*',
'lockfile.*',
'pexpect.*',
'requests_toolbelt.*',
'shellingham.*',
'virtualenv.*',
'xattr.*',
'zipp.*',
]
ignore_missing_imports = true

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import requests

from cachecontrol.controller import logger as cache_control_logger
from cacheyou.controller import logger as cache_control_logger
from poetry.core.packages.package import Package
from poetry.core.packages.utils.link import Link
from poetry.core.version.exceptions import InvalidVersion
Expand Down
29 changes: 3 additions & 26 deletions src/poetry/utils/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
from typing import TYPE_CHECKING
from typing import Any

import lockfile
import requests
import requests.auth
import requests.exceptions

from cachecontrol import CacheControlAdapter
from cachecontrol.caches import FileCache
from cachecontrol.caches.file_cache import url_to_file_path
from filelock import FileLock
from cacheyou import CacheControlAdapter
from cacheyou.caches import FileCache
from cacheyou.caches.file_cache import url_to_file_path

from poetry.config.config import Config
from poetry.exceptions import PoetryException
Expand All @@ -38,26 +36,6 @@
logger = logging.getLogger(__name__)


class FileLockLockFile(lockfile.LockBase): # type: ignore[misc]
# The default LockFile from the lockfile package as used by cachecontrol can remain
# locked if a process exits ungracefully. See eg
# <https://github.com/python-poetry/poetry/issues/6030#issuecomment-1189383875>.
#
# FileLock from the filelock package does not have this problem, so we use that to
# construct something compatible with cachecontrol.
def __init__(
self, path: str, threaded: bool = True, timeout: float | None = None
) -> None:
super().__init__(path, threaded, timeout)
self.file_lock = FileLock(self.lock_file)

def acquire(self, timeout: float | None = None) -> None:
self.file_lock.acquire(timeout=timeout)

def release(self) -> None:
self.file_lock.release()


@dataclasses.dataclass(frozen=True)
class RepositoryCertificateConfig:
cert: Path | None = dataclasses.field(default=None)
Expand Down Expand Up @@ -149,7 +127,6 @@ def __init__(
/ (cache_id or "_default_cache")
/ "_http"
),
lock_class=FileLockLockFile,
)
if not disable_cache
else None
Expand Down
2 changes: 1 addition & 1 deletion tests/repositories/test_pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_invalid_versions_ignored() -> None:
def test_get_should_invalid_cache_on_too_many_redirects_error(
mocker: MockerFixture,
) -> None:
delete_cache = mocker.patch("cachecontrol.caches.file_cache.FileCache.delete")
delete_cache = mocker.patch("cacheyou.caches.file_cache.FileCache.delete")

response = Response()
response.status_code = 200
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def test_authenticator_get_cached_file_for_url__cache_hit(config: Config) -> Non
authenticator = Authenticator(config, NullIO())
url = "https://foo.bar/files/foo-0.1.0.tar.gz"

authenticator._cache_control.set(url, b"hello")
authenticator._cache_control.set(url, b"hello") # type: ignore[union-attr]

assert authenticator.get_cached_file_for_url(url)

Expand Down

0 comments on commit daa3bba

Please sign in to comment.