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

Remove spinner from learning uploader #1415

Merged
merged 2 commits into from
May 21, 2024
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
1 change: 0 additions & 1 deletion scripts/ibm-quantum-learning-uploader/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers = [
]
dependencies = [
"pyyaml",
"yaspin",
"requests~=2.28"
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import random
import requests
import sys
from yaspin import yaspin
from yaspin.spinners import Spinners


class Lesson:
Expand Down Expand Up @@ -73,28 +71,30 @@ def push(self, lesson: Lesson):
Wrapper for `_push` to handle spinner and Exceptions
"""
base_msg = f"Push \033[1m{lesson.name}\033[0m"
spinner = yaspin(Spinners.dots12, text=base_msg, color="blue")
spinner.start()

def _log_fn(msg):
spinner.text = f"{base_msg}: {msg}"
def _log_fn(msg, state="working"):
"""
Display event to terminal
msg: Event message
state: 'working'|'fail'|'complete'
"""
emoji = { "working": "🔄", "fail": "❌", "complete": "✅" }[state]
print(f"{emoji} {base_msg}: {msg}")

try:
web_page = self._push(lesson, _log_fn)

except KeyboardInterrupt:
_log_fn("Cancelled by user")
spinner.fail("❌")
_log_fn("Cancelled by user", state="fail")
lesson.delete_zip()
sys.exit()

except Exception as err:
spinner.fail("❌")
_log_fn("Something went wrong", state="fail")
lesson.delete_zip()
raise err

spinner.text = base_msg
spinner.ok("✅")
_log_fn("Complete!", state="complete")

if not self.hide_urls:
print(f" \033[30m╷\033[0m Web page: \033[96m{web_page}\033[0m")
Expand Down
Loading