[Launcher] Better requirements detection

The update menu is also less ambiguous since it shows what kind of requirements is going to update
This commit is contained in:
Twentysix 2017-01-11 15:21:12 +01:00
parent 030d40c253
commit b550946a93

View File

@ -4,7 +4,8 @@ import sys
import subprocess import subprocess
try: # Older Pythons lack this try: # Older Pythons lack this
import urllib.request # We'll let them reach the Python import urllib.request # We'll let them reach the Python
except ImportError: # check anyway from importlib.util import find_spec # check anyway
except ImportError:
pass pass
import platform import platform
import webbrowser import webbrowser
@ -214,21 +215,12 @@ def download_ffmpeg(bitness):
def verify_requirements(): def verify_requirements():
try: sys.path_importer_cache = {} # I don't know if the cache reset has any
from discord.ext import commands basic = find_spec("discord") # side effect. Without it, the lib folder
except ImportError: audio = find_spec("nacl") # wouldn't be seen if it didn't exist
return False if not basic: # when the launcher was started
else:
return True
def is_dpy_audio_installed():
"""Detects if the audio portion of discord.py is installed"""
if not verify_requirements:
return None return None
try: elif not audio:
import nacl.secret
except ImportError:
return False return False
else: else:
return True return True
@ -280,6 +272,14 @@ def update_menu():
clear_screen() clear_screen()
while True: while True:
print(INTRO) print(INTRO)
reqs = verify_requirements()
if reqs is None:
status = "No requirements installed"
elif reqs is False:
status = "Basic requirements installed (no audio)"
else:
status = "Basic + audio requirements installed"
print("Status: " + status + "\n")
print("Update:\n") print("Update:\n")
print("Red:") print("Red:")
print("1. Update Red + requirements (recommended)") print("1. Update Red + requirements (recommended)")
@ -292,9 +292,9 @@ def update_menu():
if choice == "1": if choice == "1":
update_red() update_red()
print("Updating requirements...") print("Updating requirements...")
audio = is_dpy_audio_installed() reqs = verify_requirements()
if audio is not None: if reqs is not None:
install_reqs(audio=audio) install_reqs(audio=reqs)
else: else:
print("The requirements haven't been installed yet.") print("The requirements haven't been installed yet.")
wait() wait()
@ -302,9 +302,9 @@ def update_menu():
update_red() update_red()
wait() wait()
elif choice == "3": elif choice == "3":
audio = is_dpy_audio_installed() reqs = verify_requirements()
if audio is not None: if reqs is not None:
install_reqs(audio=audio) install_reqs(audio=reqs)
else: else:
print("The requirements haven't been installed yet.") print("The requirements haven't been installed yet.")
wait() wait()
@ -362,7 +362,7 @@ def run_red(autorestart):
if interpreter is None: # This should never happen if interpreter is None: # This should never happen
raise RuntimeError("Couldn't find Python's interpreter") raise RuntimeError("Couldn't find Python's interpreter")
if not verify_requirements(): if verify_requirements() is None:
print("You don't have the requirements to start Red. " print("You don't have the requirements to start Red. "
"Install them from the launcher.") "Install them from the launcher.")
if not INTERACTIVE_MODE: if not INTERACTIVE_MODE: