Commit 6c2dda23 by Sébastien Eustace

Improve dependency resolution time by using cache control

parent c8858956
# Change Log # Change Log
## [Unreleased]
### Changes
- Improved dependency resolution time by using cache control.
## [0.7.1] - 2018-04-05 ## [0.7.1] - 2018-04-05
### Fixed ### Fixed
......
...@@ -2,8 +2,10 @@ from pathlib import Path ...@@ -2,8 +2,10 @@ from pathlib import Path
from typing import List from typing import List
from typing import Union from typing import Union
from cachecontrol import CacheControl
from cachecontrol.caches.file_cache import FileCache
from cachy import CacheManager from cachy import CacheManager
from requests import get from requests import session
from poetry.locations import CACHE_DIR from poetry.locations import CACHE_DIR
from poetry.packages import dependency_from_pep_508 from poetry.packages import dependency_from_pep_508
...@@ -21,6 +23,7 @@ class PyPiRepository(Repository): ...@@ -21,6 +23,7 @@ class PyPiRepository(Repository):
def __init__(self, url='https://pypi.org/', disable_cache=False): def __init__(self, url='https://pypi.org/', disable_cache=False):
self._url = url self._url = url
self._disable_cache = disable_cache self._disable_cache = disable_cache
release_cache_dir = Path(CACHE_DIR) / 'cache' / 'repositories' / 'pypi' release_cache_dir = Path(CACHE_DIR) / 'cache' / 'repositories' / 'pypi'
self._cache = CacheManager({ self._cache = CacheManager({
'default': 'releases', 'default': 'releases',
...@@ -36,6 +39,11 @@ class PyPiRepository(Repository): ...@@ -36,6 +39,11 @@ class PyPiRepository(Repository):
} }
}) })
self._session = CacheControl(
session(),
cache=FileCache(str(release_cache_dir / '_packages'))
)
super().__init__() super().__init__()
def find_packages(self, def find_packages(self,
...@@ -203,7 +211,7 @@ class PyPiRepository(Repository): ...@@ -203,7 +211,7 @@ class PyPiRepository(Repository):
return data return data
def _get(self, endpoint: str) -> Union[dict, None]: def _get(self, endpoint: str) -> Union[dict, None]:
json_response = get(self._url + endpoint) json_response = self._session.get(self._url + endpoint)
if json_response.status_code == 404: if json_response.status_code == 404:
return None return None
......
...@@ -32,6 +32,7 @@ requests-toolbelt = "^0.8.0" ...@@ -32,6 +32,7 @@ requests-toolbelt = "^0.8.0"
jsonschema = "^2.6" jsonschema = "^2.6"
pyrsistent = "^0.14.2" pyrsistent = "^0.14.2"
pyparsing = "^2.2" pyparsing = "^2.2"
cachecontrol = { version = "^0.12.4", extras = ["filecache"] }
# zipfile36 is needed for Python 3.4 and 3.5 # zipfile36 is needed for Python 3.4 and 3.5
zipfile36 = { version = "^0.1", python = ">=3.4 <3.6" } zipfile36 = { version = "^0.1", python = ">=3.4 <3.6" }
...@@ -39,6 +40,12 @@ zipfile36 = { version = "^0.1", python = ">=3.4 <3.6" } ...@@ -39,6 +40,12 @@ zipfile36 = { version = "^0.1", python = ">=3.4 <3.6" }
# The typing module is not in the stdlib in Python 3.4 # The typing module is not in the stdlib in Python 3.4
typing = { version = "^3.6", python = "~3.4" } typing = { version = "^3.6", python = "~3.4" }
# cachecontrol dependencies are badly set
# and do not appear in PyPI JSON API
# So we set them here
msgpack-python = "^0.5"
lockfile = "^0.12"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pytest = "^3.4" pytest = "^3.4"
pytest-cov = "^2.5" pytest-cov = "^2.5"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment