Skip to content

Commit

Permalink
[SWAT-4] Revert breaking changes to dataset pull (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaazzini authored Mar 10, 2022
1 parent 0495534 commit 639226a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
15 changes: 5 additions & 10 deletions darwin/dataset/release.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
import shutil
from pathlib import Path
from typing import Any, Dict, Optional

import requests
from darwin.dataset.identifier import DatasetIdentifier
from requests import Response


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

from darwin.client import Client

config_path: Path = Path.home() / ".darwin" / "config.yaml"
client: Client = Client.from_config(config_path=config_path, team_slug=self.team_slug)

data: Response = client.fetch_binary(self.url)
with open(path, "wb") as download_file:
for chunk in data.iter_content(chunk_size=8192):
download_file.write(chunk)
with requests.get(self.url, stream=True) as response:
with open(path, "wb") as download_file:
shutil.copyfileobj(response.raw, download_file)

return path

Expand Down
2 changes: 1 addition & 1 deletion darwin/version/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.11"
__version__ = "0.7.12"
32 changes: 32 additions & 0 deletions tests/darwin/dataset/release_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import shutil
from unittest.mock import patch

import requests
from darwin.dataset.release import Release
from tests.fixtures import *


@pytest.fixture
def release(dataset_slug: str, team_slug: str) -> Release:
return Release(
dataset_slug=dataset_slug,
team_slug=team_slug,
version="latest",
name="test",
url="http://test.v7labs.com/",
export_date="now",
image_count=None,
class_count=None,
available=True,
latest=True,
format="darwin",
)


def describe_release():
def it_downloads_zip(release: Release, tmp_path: Path):
with patch.object(requests, "get") as get:
with patch.object(shutil, "copyfileobj") as copyfileobj:
release.download_zip(tmp_path / "test.zip")
get.assert_called_once_with("http://test.v7labs.com/", stream=True)
copyfileobj.assert_called_once()

0 comments on commit 639226a

Please sign in to comment.