Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
ead7e21e
Unverified
Commit
ead7e21e
authored
Nov 12, 2019
by
Sébastien Eustace
Committed by
GitHub
Nov 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix TooManyRedirects error when resolving dependencies (#1564)
parent
779fecd0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
poetry/repositories/pypi_repository.py
+14
-4
tests/repositories/test_pypi_repository.py
+22
-0
No files found.
poetry/repositories/pypi_repository.py
View file @
ead7e21e
...
...
@@ -8,10 +8,12 @@ from typing import Union
from
cachecontrol
import
CacheControl
from
cachecontrol.caches.file_cache
import
FileCache
from
cachecontrol.controller
import
logger
as
cache_control_logger
from
cachy
import
CacheManager
from
html5lib.html5parser
import
parse
from
requests
import
get
from
requests
import
session
from
requests.exceptions
import
TooManyRedirects
from
poetry.locations
import
CACHE_DIR
from
poetry.packages
import
Package
...
...
@@ -39,6 +41,8 @@ except ImportError:
import
urlparse
cache_control_logger
.
setLevel
(
logging
.
ERROR
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -63,9 +67,8 @@ class PyPiRepository(Repository):
}
)
self
.
_session
=
CacheControl
(
session
(),
cache
=
FileCache
(
str
(
release_cache_dir
/
"_http"
))
)
self
.
_cache_control_cache
=
FileCache
(
str
(
release_cache_dir
/
"_http"
))
self
.
_session
=
CacheControl
(
session
(),
cache
=
self
.
_cache_control_cache
)
self
.
_inspector
=
Inspector
()
super
(
PyPiRepository
,
self
)
.
__init__
()
...
...
@@ -357,7 +360,14 @@ class PyPiRepository(Repository):
return
data
def
_get
(
self
,
endpoint
):
# type: (str) -> Union[dict, None]
json_response
=
self
.
_session
.
get
(
self
.
_url
+
endpoint
)
try
:
json_response
=
self
.
_session
.
get
(
self
.
_url
+
endpoint
)
except
TooManyRedirects
:
# Cache control redirect loop.
# We try to remove the cache and try again
self
.
_cache_control_cache
.
delete
(
self
.
_url
+
endpoint
)
json_response
=
self
.
_session
.
get
(
self
.
_url
+
endpoint
)
if
json_response
.
status_code
==
404
:
return
None
...
...
tests/repositories/test_pypi_repository.py
View file @
ead7e21e
import
json
import
shutil
from
io
import
BytesIO
import
pytest
from
requests.exceptions
import
TooManyRedirects
from
requests.models
import
Response
from
poetry.packages
import
Dependency
from
poetry.repositories.pypi_repository
import
PyPiRepository
from
poetry.utils._compat
import
PY35
from
poetry.utils._compat
import
Path
from
poetry.utils._compat
import
encode
class
MockRepository
(
PyPiRepository
):
...
...
@@ -186,3 +192,19 @@ def test_invalid_versions_ignored():
# and a correct one.
packages
=
repo
.
find_packages
(
"pygame-music-grid"
)
assert
len
(
packages
)
==
1
def
test_get_should_invalid_cache_on_too_many_redirects_error
(
mocker
):
delete_cache
=
mocker
.
patch
(
"cachecontrol.caches.file_cache.FileCache.delete"
)
response
=
Response
()
response
.
encoding
=
"utf-8"
response
.
raw
=
BytesIO
(
encode
(
'{"foo": "bar"}'
))
mocker
.
patch
(
"cachecontrol.adapter.CacheControlAdapter.send"
,
side_effect
=
[
TooManyRedirects
(),
response
],
)
repository
=
PyPiRepository
()
repository
.
_get
(
"https://pypi.org/pypi/async-timeout/json"
)
assert
delete_cache
.
called
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment