Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Space runtime on static Space #1754

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/huggingface_hub/_space_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class SpaceRuntime:

def __init__(self, data: Dict) -> None:
self.stage = data["stage"]
self.hardware = data["hardware"]["current"]
self.requested_hardware = data["hardware"]["requested"]
self.sleep_time = data["gcTimeout"]
self.storage = data["storage"]
self.hardware = data.get("hardware", {}).get("current")
self.requested_hardware = data.get("hardware", {}).get("requested")
self.sleep_time = data.get("gcTimeout")
self.storage = data.get("storage")
Comment on lines +119 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax is not super pretty but LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll yet you open an issue on https://github.com/python/cpython and in the meantime merge this PR 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.raw = data


Expand Down
8 changes: 8 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,14 @@ def test_space_runtime(self) -> None:
# Raw response from Hub
self.assertIsInstance(runtime.raw, dict)

def test_static_space_runtime(self) -> None:
"""
Regression test for static Spaces.
See https://github.com/huggingface/huggingface_hub/pull/1754.
"""
runtime = self.api.get_space_runtime("victor/static-space")
self.assertIsInstance(runtime.raw, dict)

def test_pause_and_restart_space(self) -> None:
# Upload a fake app.py file
self.api.upload_file(path_or_fileobj=b"", path_in_repo="app.py", repo_id=self.repo_id, repo_type="space")
Expand Down