Skip to content

Commit 639226a

Browse files
authored
[SWAT-4] Revert breaking changes to dataset pull (#372)
1 parent 0495534 commit 639226a

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

darwin/dataset/release.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import datetime
2+
import shutil
23
from pathlib import Path
34
from typing import Any, Dict, Optional
45

6+
import requests
57
from darwin.dataset.identifier import DatasetIdentifier
6-
from requests import Response
78

89

910
class Release:
@@ -191,15 +192,9 @@ def download_zip(self, path: Path) -> Path:
191192
if not self.url:
192193
raise ValueError("Release must have a valid url to download the zip.")
193194

194-
from darwin.client import Client
195-
196-
config_path: Path = Path.home() / ".darwin" / "config.yaml"
197-
client: Client = Client.from_config(config_path=config_path, team_slug=self.team_slug)
198-
199-
data: Response = client.fetch_binary(self.url)
200-
with open(path, "wb") as download_file:
201-
for chunk in data.iter_content(chunk_size=8192):
202-
download_file.write(chunk)
195+
with requests.get(self.url, stream=True) as response:
196+
with open(path, "wb") as download_file:
197+
shutil.copyfileobj(response.raw, download_file)
203198

204199
return path
205200

darwin/version/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.11"
1+
__version__ = "0.7.12"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import shutil
2+
from unittest.mock import patch
3+
4+
import requests
5+
from darwin.dataset.release import Release
6+
from tests.fixtures import *
7+
8+
9+
@pytest.fixture
10+
def release(dataset_slug: str, team_slug: str) -> Release:
11+
return Release(
12+
dataset_slug=dataset_slug,
13+
team_slug=team_slug,
14+
version="latest",
15+
name="test",
16+
url="http://test.v7labs.com/",
17+
export_date="now",
18+
image_count=None,
19+
class_count=None,
20+
available=True,
21+
latest=True,
22+
format="darwin",
23+
)
24+
25+
26+
def describe_release():
27+
def it_downloads_zip(release: Release, tmp_path: Path):
28+
with patch.object(requests, "get") as get:
29+
with patch.object(shutil, "copyfileobj") as copyfileobj:
30+
release.download_zip(tmp_path / "test.zip")
31+
get.assert_called_once_with("http://test.v7labs.com/", stream=True)
32+
copyfileobj.assert_called_once()

0 commit comments

Comments
 (0)