Skip to content

Commit

Permalink
Remove spinner from learning uploader (Qiskit#1415)
Browse files Browse the repository at this point in the history
Small refactor before Qiskit#1390.

The spinner was fun when the tool was primarily used locally, but now
it's annoying in CI and is an extra dependency. See an example of the
new behaviour in the
[test](https://github.com/Qiskit/documentation/actions/runs/9173882338/job/25223510491#step:5:102).
  • Loading branch information
frankharkins authored May 21, 2024
1 parent 9b72c35 commit f7d32de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
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

0 comments on commit f7d32de

Please sign in to comment.