From d173e9c8705e49ade9b71198cad3b5a41a1871f8 Mon Sep 17 00:00:00 2001 From: Jon Peirce Date: Tue, 16 Jul 2024 10:51:22 +0100 Subject: [PATCH 1/2] PKG: added first attempt at an install script for linux --- installPsychoPy.py | 179 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 installPsychoPy.py diff --git a/installPsychoPy.py b/installPsychoPy.py new file mode 100644 index 0000000000..38b68519f3 --- /dev/null +++ b/installPsychoPy.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Part of the PsychoPy library +# Copyright (C) 2002-2018 Jonathan Peirce (C) 2019-2024 Open Science Tools Ltd. +# Distributed under the terms of the GNU General Public License (GPL). + +import subprocess +import os +import sys +import requests + +"""This script will install PsychoPy to the current Python environment. + +For Linux installations, the script will fetch the supported linux distros for wxPython +and interactively select the distro and version to download the appropriate .whl file. + +After that the script will install PsychoPy using pip. + +NB: At present, for windows and MacOS you may as well just use `pip install psychopy` but +in the future we may add some additional functionality here, like adding application +shortcuts, checking/recommending virtual envs etc. +""" + +# Author: Florian Osmani +# Author: Jonathan Peirce + +wxLinuxUrl = "https://extras.wxpython.org/wxPython4/extras/linux/gtk3/" + +def installWhlFile(whlUrl): + """Installs a single specified wheel file using pip""" + wheel_path = os.path.basename(whlUrl) + subprocess.run([sys.exectuable, '-m', 'pip', 'install', '-U', '-f', wheel_path, 'wxPython'], check=True) + +def installPsychoPy(): + """Runs pip install psychopy""" + subprocess.run([sys.exectuable, '-m', 'pip', 'install', 'psychopy'], check=True) + +def getWxUrl(distroNames=None): + """Fetch the supported linux distros for wx and interactively select the + distro and version to download the appropriate .whl file. + + Args: + distroNames (_type_, optional): _description_. Defaults to None. + + Returns: + list: URL of the wheel for the selected distro/version + """ + def extractDistroNames(url): + """Extract the names of the linux distributions from the html content""" + + response = requests.get(url) + response.raise_for_status() + + distro_names = [] + lines = response.text.split('\n') + for line in lines: + if ' 10: + print("Sorry, please use Python 3.8, 3.9, or 3.10 to install Psychopy") + return None + + python_cp = f"cp{version_info.major}{version_info.minor}" + + def selectDistro(distroNames): + print("Please select your Linux distribution:") + for i, distro in enumerate(distroNames): + print(f"{i + 1}. {distro}") + + while True: + choice = input("Enter your choice (number): ") + if choice.isdigit() and 1 <= int(choice) <= len(distroNames): + return distroNames[int(choice) - 1] + else: + print("Invalid choice, please try again.") + + def organizeDistributions(distroNames): + distroDict = {} + for distro in distroNames: + nameParts = distro.split('-') + distroName = '-'.join(nameParts[:-1]) + version = nameParts[-1] if len(nameParts) > 1 else 'default' + + if distroName in distroDict: + distroDict[distroName].append(version) + else: + distroDict[distroName] = [version] + + return distroDict + + def selectVersion(selectedDistro, versions): + while True: + print("Please select the version:") + for i, version in enumerate(versions): + print(f"{i + 1}. {selectedDistro}-{version}") + print("0. Go back") + + choice = input("Enter your choice (number): ") + if choice.isdigit(): + choice = int(choice) + if 1 <= choice <= len(versions): + return versions[choice - 1] + elif choice == 0: + return None + print("Invalid choice, please try again.") + + def fetchWhlFiles(htmlContent, pythonVersions): + whl_files = [] + lines = htmlContent.split('\n') + for line in lines: + if ' Date: Tue, 16 Jul 2024 11:01:38 +0100 Subject: [PATCH 2/2] PKG: better information about linux wxPython install options --- installPsychoPy.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/installPsychoPy.py b/installPsychoPy.py index 38b68519f3..004cdcf8cc 100644 --- a/installPsychoPy.py +++ b/installPsychoPy.py @@ -128,15 +128,18 @@ def selectVersion(selectedDistro, versions): print("Invalid choice, please try again.") def fetchWhlFiles(htmlContent, pythonVersions): - whl_files = [] + all = [] + recommended = [] lines = htmlContent.split('\n') for line in lines: - if '