From daa3bba7d694463ceaec4345ca78ba109bfca8ad Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Wed, 24 May 2023 17:03:23 +0200 Subject: [PATCH] Replace cachecontrol with a fork --- poetry.lock | 27 ++++++-------------- pyproject.toml | 7 ++---- src/poetry/repositories/pypi_repository.py | 2 +- src/poetry/utils/authenticator.py | 29 +++------------------- tests/repositories/test_pypi_repository.py | 2 +- tests/utils/test_authenticator.py | 2 +- 6 files changed, 16 insertions(+), 53 deletions(-) diff --git a/poetry.lock b/poetry.lock index 7e3d12b244b..46da822f973 100644 --- a/poetry.lock +++ b/poetry.lock @@ -42,23 +42,23 @@ typing = ["importlib-metadata (>=5.1)", "mypy (==0.991)", "tomli", "typing-exten virtualenv = ["virtualenv (>=20.0.35)"] [[package]] -name = "cachecontrol" -version = "0.12.11" +name = "cacheyou" +version = "23.2" description = "httplib2 caching for requests" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "CacheControl-0.12.11-py2.py3-none-any.whl", hash = "sha256:2c75d6a8938cb1933c75c50184549ad42728a27e9f6b92fd677c3151aa72555b"}, - {file = "CacheControl-0.12.11.tar.gz", hash = "sha256:a5b9fcc986b184db101aa280b42ecdcdfc524892596f606858e0b7a8b4d9e144"}, + {file = "cacheyou-23.2-py3-none-any.whl", hash = "sha256:c0d7ac6742b1a56d9767bf694e2774e70da7979254e4f947360a72d25a3ed1b6"}, + {file = "cacheyou-23.2.tar.gz", hash = "sha256:e64cd34f65e3e121df1ad6e2a70f87b42970b7cbba233a1c38b34d1a3fbb8131"}, ] [package.dependencies] -lockfile = {version = ">=0.9", optional = true, markers = "extra == \"filecache\""} +filelock = {version = ">=3.8.0", optional = true, markers = "extra == \"filecache\""} msgpack = ">=0.5.2" requests = "*" [package.extras] -filecache = ["lockfile (>=0.9)"] +filecache = ["filelock (>=3.8.0)"] redis = ["redis (>=2.10.5)"] [[package]] @@ -705,17 +705,6 @@ completion = ["shtab"] docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)"] testing = ["flake8 (<5)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] -[[package]] -name = "lockfile" -version = "0.12.2" -description = "Platform-independent file locking module" -optional = false -python-versions = "*" -files = [ - {file = "lockfile-0.12.2-py2.py3-none-any.whl", hash = "sha256:6c3cb24f344923d30b2785d5ad75182c8ea7ac1b6171b08657258ec7429d50fa"}, - {file = "lockfile-0.12.2.tar.gz", hash = "sha256:6aed02de03cba24efabcd600b30540140634fc06cfa603822d508d5361e9f799"}, -] - [[package]] name = "more-itertools" version = "9.1.0" @@ -1672,4 +1661,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "fab5b1b0800c476f29b2f064c2c664cde4bcf7b8fbe98c58feb529d0935f98fb" +content-hash = "510dbcb3f080753ec14026768b29e1074a8211aef9e1282915731b7482bd5142" diff --git a/pyproject.toml b/pyproject.toml index 2078e33921a..fe9109021d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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" @@ -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 diff --git a/src/poetry/repositories/pypi_repository.py b/src/poetry/repositories/pypi_repository.py index d91cfafe0d8..d005998aa7e 100644 --- a/src/poetry/repositories/pypi_repository.py +++ b/src/poetry/repositories/pypi_repository.py @@ -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 diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index beb20342ca8..958376a2e33 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -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 @@ -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 - # . - # - # 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) @@ -149,7 +127,6 @@ def __init__( / (cache_id or "_default_cache") / "_http" ), - lock_class=FileLockLockFile, ) if not disable_cache else None diff --git a/tests/repositories/test_pypi_repository.py b/tests/repositories/test_pypi_repository.py index c2f56943b5c..15f192f5b13 100644 --- a/tests/repositories/test_pypi_repository.py +++ b/tests/repositories/test_pypi_repository.py @@ -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 diff --git a/tests/utils/test_authenticator.py b/tests/utils/test_authenticator.py index 335e2b50c1e..0d3c972e424 100644 --- a/tests/utils/test_authenticator.py +++ b/tests/utils/test_authenticator.py @@ -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)