Skip to content

Commit

Permalink
Merge a67212f into 9e25f6f
Browse files Browse the repository at this point in the history
  • Loading branch information
haimasree committed Mar 24, 2022
2 parents 9e25f6f + a67212f commit 1dc97b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
- name: Install conda environment py310
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: py39
activate-environment: py310
environment-file: environment.ubuntu.singularity.yml
auto-activate-base: false
- name: Install dependencies
Expand Down
20 changes: 16 additions & 4 deletions kipoi_containers/zenodoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
from pathlib import Path
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from typing import Dict, Tuple, Union


Expand All @@ -15,11 +17,21 @@ def __init__(self) -> None:
self.params = {
"access_token": os.environ.get("ZENODO_ACCESS_TOKEN", "")
}
retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
allowed_methods=["GET", "PUT", "DELETE"],
)
adapter = HTTPAdapter(max_retries=retry_strategy)
self.session = requests.Session()
self.session.mount("https://", adapter)
self.session.mount("http://", adapter)

def get_content(self, url: str, **kwargs) -> Dict:
"""Performs GET request to an url and returns the
response body"""
response = requests.get(url, params=self.params | kwargs)
response = self.session.get(url, params=self.params | kwargs)
response.raise_for_status()
return response.json()

Expand All @@ -28,11 +40,11 @@ def put_content(self, url: str, data: Union[Path, Dict], **kwargs) -> Dict:
or a dict and returns the response body"""
if isinstance(data, Path):
with open(data, "rb") as file_handle:
response = requests.put(
response = self.session.put(
url, data=file_handle, params=(self.params | kwargs)
)
else:
response = requests.put(
response = self.session.put(
url,
data=json.dumps(data),
params=(self.params | kwargs),
Expand All @@ -51,7 +63,7 @@ def post_content(self, url: str, **kwargs) -> Tuple[int, Dict]:
def delete_content(self, url: str, **kwargs) -> None:
# Assumption: There will always be one file associated with each version
"""Performs DELETE request to an url"""
response = requests.delete(
response = self.session.delete(
url,
params=(self.params | kwargs),
)
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"spython",
"pre-commit",
"click",
"kipoi",
]
setup_requirements = []

Expand All @@ -38,10 +39,7 @@
"update_all_singularity=kipoi_containers.update_all_singularity_images:run_update",
],
},
install_requires=[
requirements,
"kipoi @ https://github.com/kipoi/kipoi/archive/master.tar.gz",
],
install_requires=requirements,
license="MIT license",
include_package_data=True,
keywords="kipoi_containers",
Expand Down

0 comments on commit 1dc97b6

Please sign in to comment.