From ed2813c85ed6a4409fbb92750eb9e78ac24fac48 Mon Sep 17 00:00:00 2001 From: "Mike A. Trethewey" Date: Tue, 16 Mar 2021 00:58:09 -0700 Subject: [PATCH] Make local install a little smarter --- docs/BUILDING.md | 4 ++ resources/ci/common/common.py | 12 +++++- resources/ci/common/get_get_pip.py | 31 +++++++++++--- resources/ci/common/install.py | 61 +++++++++++++++++++++++++--- resources/ci/common/local_install.py | 13 +++++- 5 files changed, 107 insertions(+), 14 deletions(-) diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 965d07f1..298230ed 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -13,3 +13,7 @@ |Platform|Command line|Image| | :----: |------------|-----| |Windows |`resources/ci/common/local_install.py`|![Windows](https://raw.githubusercontent.com/miketrethewey/ALttPDoorRandomizer/DoorDevUnstable/docs/images/cli-windows.png) +|`py` Launcher: 3.9 |`resources/ci/common/local_install.py --py 3.9`| +|`py` Launcher: 3.8 |`resources/ci/common/local_install.py --py 3.8`| +|`py` Launcher: 3.7 |`resources/ci/common/local_install.py --py 3.7`| +|`py` Launcher: 3.6 |`resources/ci/common/local_install.py --py 3.6`| diff --git a/resources/ci/common/common.py b/resources/ci/common/common.py index f2288fe2..0dac9fb2 100644 --- a/resources/ci/common/common.py +++ b/resources/ci/common/common.py @@ -1,5 +1,6 @@ import os # for env vars import stat # file statistics +import sys # default system info global UBUNTU_VERSIONS global DEFAULT_EVENT @@ -75,10 +76,19 @@ def prepare_env(): env["BUILD_NUMBER"] = os.getenv("TRAVIS_BUILD_NUMBER",env["GITHUB_RUN_NUMBER"]) GITHUB_TAG = os.getenv("TRAVIS_TAG",os.getenv("GITHUB_TAG","")) - OS_NAME = os.getenv("TRAVIS_OS_NAME",os.getenv("OS_NAME","")).replace("macOS","osx") + OS_NAME = os.getenv("TRAVIS_OS_NAME",os.getenv("OS_NAME",sys.platform)).replace("macOS","osx") OS_DIST = os.getenv("TRAVIS_DIST","notset") OS_VERSION = "" + if "win32" in OS_NAME or \ + "cygwin" in OS_NAME or \ + "msys" in OS_NAME: + OS_NAME = "windows" + elif "darwin" in OS_NAME: + OS_NAME = "osx" + elif "linux2" in OS_NAME: + OS_NAME = "linux" + if '-' in OS_NAME: OS_VERSION = OS_NAME[OS_NAME.find('-')+1:] OS_NAME = OS_NAME[:OS_NAME.find('-')] diff --git a/resources/ci/common/get_get_pip.py b/resources/ci/common/get_get_pip.py index 9b69930d..4724ebd7 100644 --- a/resources/ci/common/get_get_pip.py +++ b/resources/ci/common/get_get_pip.py @@ -1,10 +1,14 @@ import common +import argparse import urllib.request, ssl import subprocess # do stuff at the shell level env = common.prepare_env() -def get_get_pip(): +def get_get_pip(PY_VERSION): + try: + import pip + except ImportError: print("Getting pip getter!") #make the request! url = "https://bootstrap.pypa.io/get-pip.py" @@ -29,11 +33,26 @@ def get_get_pip(): # linux/windows: python # macosx: python3 PYTHON_EXECUTABLE = "python3" if "osx" in env["OS_NAME"] else "python" + if PY_VERSION == None: + PY_VERSION = 0 + + if float(PY_VERSION) > 0: + PYTHON_EXECUTABLE = "py" + print("Getting pip!") - subprocess.check_call([PYTHON_EXECUTABLE,"get-pip.py"]) + args = [ + PYTHON_EXECUTABLE, + '-' + str(PY_VERSION), + "get-pip.py" + ] + if PY_VERSION == 0: + del args[1] + subprocess.check_call(args) if __name__ == "__main__": - try: - import pip - except ImportError: - get_get_pip() + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument('--py', default=0) + command_line_args = parser.parse_args() + PY_VERSION = vars(command_line_args)["py"] + + get_get_pip(PY_VERSION) diff --git a/resources/ci/common/install.py b/resources/ci/common/install.py index 70d10202..f32b4866 100644 --- a/resources/ci/common/install.py +++ b/resources/ci/common/install.py @@ -1,9 +1,10 @@ import common +import argparse import subprocess # do stuff at the shell level env = common.prepare_env() -def run_install(): +def run_install(PY_VERSION,USER): # get executables # python # linux/windows: python @@ -15,16 +16,66 @@ def run_install(): PIP_EXECUTABLE = "pip" if "windows" in env["OS_NAME"] else "pip3" PIP_EXECUTABLE = "pip" if "osx" in env["OS_NAME"] and "actions" in env["CI_SYSTEM"] else PIP_EXECUTABLE + if PY_VERSION == None: + PY_VERSION = 0 + if USER == None: + USER = False + + if float(PY_VERSION) > 0: + PYTHON_EXECUTABLE = "py" + print("Installing to Python %.1f" % float(PY_VERSION)) + if USER: + print("Installing packages at User level") + # upgrade pip - subprocess.check_call([PYTHON_EXECUTABLE,"-m","pip","install","--upgrade","pip"]) + args = [ + PYTHON_EXECUTABLE, + '-' + str(PY_VERSION), + "-m", + "pip", + "install", + "--upgrade", + "--user", + "pip" + ] + if not USER: + args.remove("--user") + if PY_VERSION == 0: + del args[1] + subprocess.check_call(args) # pip version subprocess.check_call([PIP_EXECUTABLE,"--version"]) # if pip3, install wheel if PIP_EXECUTABLE == "pip3": - subprocess.check_call([PIP_EXECUTABLE,"install","-U","wheel"]) + args = [ + PIP_EXECUTABLE, + "install", + "--user", + "-U", + "wheel" + ] + if not USER: + args.remove("--user") + subprocess.check_call(args) # install listed dependencies - subprocess.check_call([PIP_EXECUTABLE,"install","-r","./resources/app/meta/manifests/pip_requirements.txt"]) + args = [ + PIP_EXECUTABLE, + "install", + "--user", + "-r", + "./resources/app/meta/manifests/pip_requirements.txt" + ] + if not USER: + args.remove("--user") + subprocess.check_call(args) if __name__ == "__main__": - run_install() + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument('--py', default=0) + parser.add_argument('--user', default=False, action="store_true") + command_line_args = parser.parse_args() + PY_VERSION = vars(command_line_args)["py"] + USER = vars(command_line_args)["user"] + + run_install(PY_VERSION,USER) diff --git a/resources/ci/common/local_install.py b/resources/ci/common/local_install.py index 8cde8348..02cc25a5 100644 --- a/resources/ci/common/local_install.py +++ b/resources/ci/common/local_install.py @@ -1,8 +1,17 @@ import install import get_get_pip +import argparse + +parser = argparse.ArgumentParser(add_help=False) +parser.add_argument('--py', default=0) +parser.add_argument('--user', default=False, action="store_true") +command_line_args = parser.parse_args() +PY_VERSION = vars(command_line_args)["py"] +USER = vars(command_line_args)["user"] + # get & install pip -get_get_pip.get_get_pip() +get_get_pip.get_get_pip(PY_VERSION) # run installer -install.run_install() +install.run_install(PY_VERSION,USER)