Skip to content

Commit ff8d3a2

Browse files
authored
Cleanup; retry; refactor (#150)
* Deleted old files, no longer used. * Adjusted the exports from __init__.py. * Use tenacity for retries, and always return response object from HTTP requests, rather than the payload of the response object. * Add decorators for raising exceptions on 'failed' http requests, and for unpacking json content. * Do not set `Content-Length` header in `_blob_client.py`. * Bumped httpx, and added tenacity. * Bump minimum Python version to 3.8 * Remove Python 3.7 from test matrix. --------- Co-authored-by: Raymond Wiker <rayw@equinor.com>
1 parent 2a7abbd commit ff8d3a2

11 files changed

Lines changed: 120 additions & 1521 deletions

File tree

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.7", "3.8", "3.9"]
14+
python-version: ["3.8", "3.9"]
1515
permissions:
1616
contents: read
1717
id-token: write

requirements/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ msal-extensions>=1.0.0
33
PyYAML>=5.4
44
setuptools>=49.2.1
55
pyjwt>=2.4.0
6-
httpx>=0.24.1
6+
httpx>=0.25.0
7+
tenacity>=8.2.3

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def parse_requirements(fname):
4242
"Development Status :: 3 - Alpha",
4343
"Intended Audience :: Developers",
4444
"Natural Language :: English",
45-
"Programming Language :: Python :: 3.7",
4645
"Programming Language :: Python :: 3.8",
46+
"Programming Language :: Python :: 3.9",
47+
"Programming Language :: Python :: 3.10",
48+
"Programming Language :: Python :: 3.11",
4749
],
4850
use_scm_version={"write_to": "src/sumo/wrapper/version.py"},
4951
author="Equinor ASA",
5052
install_requires=REQUIREMENTS,
51-
python_requires=">=3.6",
53+
python_requires=">=3.8",
5254
packages=find_packages("src"),
5355
package_dir={"": "src"},
5456
include_package_data=True,

src/sumo/wrapper/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from ._call_sumo_api import CallSumoApi
21
from .sumo_client import SumoClient
32

4-
__all__ = ["CallSumoApi", "SumoClient"]
3+
__all__ = ["SumoClient"]

src/sumo/wrapper/_auth.py

Lines changed: 0 additions & 224 deletions
This file was deleted.

src/sumo/wrapper/_blob_client.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import httpx
22

3-
from ._request_error import raise_request_error_exception
3+
from .decorators import raise_for_status, http_retry
44

55

66
class BlobClient:
77
"""Upload blobs to blob store using pre-authorized URLs"""
88

9+
@raise_for_status
10+
@http_retry
911
def upload_blob(self, blob: bytes, url: str):
1012
"""Upload a blob.
1113
@@ -16,20 +18,15 @@ def upload_blob(self, blob: bytes, url: str):
1618

1719
headers = {
1820
"Content-Type": "application/octet-stream",
19-
"Content-Length": str(len(blob)),
2021
"x-ms-blob-type": "BlockBlob",
2122
}
2223

23-
try:
24-
response = httpx.put(url, data=blob, headers=headers)
25-
except httpx.ProxyError as err:
26-
raise_request_error_exception(503, err)
27-
28-
if response.is_error:
29-
raise_request_error_exception(response.status_code, response.text)
24+
response = httpx.put(url, content=blob, headers=headers)
3025

3126
return response
3227

28+
@raise_for_status
29+
@http_retry
3330
async def upload_blob_async(self, blob: bytes, url: str):
3431
"""Upload a blob async.
3532
@@ -40,19 +37,10 @@ async def upload_blob_async(self, blob: bytes, url: str):
4037

4138
headers = {
4239
"Content-Type": "application/octet-stream",
43-
"Content-Length": str(len(blob)),
4440
"x-ms-blob-type": "BlockBlob",
4541
}
4642

47-
try:
48-
async with httpx.AsyncClient() as client:
49-
response = await client.put(
50-
url=url, data=blob, headers=headers
51-
)
52-
except httpx.ProxyError as err:
53-
raise_request_error_exception(503, err)
54-
55-
if response.is_error:
56-
raise_request_error_exception(response.status_code, response.text)
43+
async with httpx.AsyncClient() as client:
44+
response = await client.put(url=url, content=blob, headers=headers)
5745

5846
return response

0 commit comments

Comments
 (0)