Add pathing intelligence
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os # for env vars
|
import os # for env vars
|
||||||
import stat # file statistics
|
import stat # file statistics
|
||||||
import sys # default system info
|
import sys # default system info
|
||||||
|
from my_path import get_py_path
|
||||||
|
|
||||||
global UBUNTU_VERSIONS
|
global UBUNTU_VERSIONS
|
||||||
global DEFAULT_EVENT
|
global DEFAULT_EVENT
|
||||||
@@ -45,6 +46,8 @@ def prepare_env():
|
|||||||
APP_VERSION = f.readlines()[0].strip()
|
APP_VERSION = f.readlines()[0].strip()
|
||||||
# ci data
|
# ci data
|
||||||
env["CI_SYSTEM"] = os.getenv("CI_SYSTEM","")
|
env["CI_SYSTEM"] = os.getenv("CI_SYSTEM","")
|
||||||
|
# py data
|
||||||
|
(env["PYTHON_EXE_PATH"],env["PY_EXE_PATH"],env["PIP_EXE_PATH"]) = get_py_path()
|
||||||
# git data
|
# git data
|
||||||
env["BRANCH"] = os.getenv("TRAVIS_BRANCH","")
|
env["BRANCH"] = os.getenv("TRAVIS_BRANCH","")
|
||||||
env["GITHUB_ACTOR"] = os.getenv("GITHUB_ACTOR","MegaMan.EXE")
|
env["GITHUB_ACTOR"] = os.getenv("GITHUB_ACTOR","MegaMan.EXE")
|
||||||
|
|||||||
@@ -1,53 +1,54 @@
|
|||||||
import common
|
import common
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import urllib.request, ssl
|
import urllib.request, ssl
|
||||||
import subprocess # do stuff at the shell level
|
import subprocess # do stuff at the shell level
|
||||||
|
|
||||||
env = common.prepare_env()
|
env = common.prepare_env()
|
||||||
|
|
||||||
def get_get_pip(PY_VERSION):
|
def get_get_pip(PY_VERSION):
|
||||||
try:
|
try:
|
||||||
import pip
|
import pip
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("Getting pip getter!")
|
print("Getting pip getter!")
|
||||||
#make the request!
|
#make the request!
|
||||||
url = "https://bootstrap.pypa.io/get-pip.py"
|
url = "https://bootstrap.pypa.io/get-pip.py"
|
||||||
context = ssl._create_unverified_context()
|
context = ssl._create_unverified_context()
|
||||||
req = urllib.request.urlopen(url, context=context)
|
req = urllib.request.urlopen(url, context=context)
|
||||||
got_pip = req.read().decode("utf-8")
|
got_pip = req.read().decode("utf-8")
|
||||||
|
|
||||||
with open("get-pip.py", "w") as g:
|
with open("get-pip.py", "w") as g:
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url,
|
url,
|
||||||
data=None,
|
data=None,
|
||||||
headers={
|
headers={
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
req = urllib.request.urlopen(req, context=context)
|
req = urllib.request.urlopen(req, context=context)
|
||||||
data = req.read().decode("utf-8")
|
data = req.read().decode("utf-8")
|
||||||
g.write(data)
|
g.write(data)
|
||||||
|
|
||||||
# get executables
|
# get executables
|
||||||
# python
|
# python
|
||||||
# linux/windows: python
|
# linux/windows: python
|
||||||
# macosx: python3
|
# macosx: python3
|
||||||
PYTHON_EXECUTABLE = "python3" if "osx" in env["OS_NAME"] else "python"
|
PYTHON_EXECUTABLE = "python3" if "osx" in env["OS_NAME"] else "python"
|
||||||
if PY_VERSION == None:
|
if PY_VERSION == None:
|
||||||
PY_VERSION = 0
|
PY_VERSION = 0
|
||||||
|
|
||||||
if float(PY_VERSION) > 0:
|
if float(PY_VERSION) > 0:
|
||||||
PYTHON_EXECUTABLE = "py"
|
PYTHON_EXECUTABLE = "py"
|
||||||
|
|
||||||
print("Getting pip!")
|
print("Getting pip!")
|
||||||
args = [
|
args = [
|
||||||
PYTHON_EXECUTABLE,
|
env["PYTHON_EXE_PATH"] + PYTHON_EXECUTABLE,
|
||||||
'-' + str(PY_VERSION),
|
'-' + str(PY_VERSION),
|
||||||
"get-pip.py"
|
"get-pip.py"
|
||||||
]
|
]
|
||||||
if PY_VERSION == 0:
|
if PY_VERSION == 0:
|
||||||
del args[1]
|
del args[1]
|
||||||
subprocess.check_call(args)
|
subprocess.check_call(args)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(add_help=False)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
@@ -55,4 +56,8 @@ if __name__ == "__main__":
|
|||||||
command_line_args = parser.parse_args()
|
command_line_args = parser.parse_args()
|
||||||
PY_VERSION = vars(command_line_args)["py"]
|
PY_VERSION = vars(command_line_args)["py"]
|
||||||
|
|
||||||
get_get_pip(PY_VERSION)
|
try:
|
||||||
|
import pip
|
||||||
|
print("pip is installed")
|
||||||
|
except ImportError:
|
||||||
|
get_get_pip(PY_VERSION)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import common
|
import common
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
import subprocess # do stuff at the shell level
|
import subprocess # do stuff at the shell level
|
||||||
|
|
||||||
env = common.prepare_env()
|
env = common.prepare_env()
|
||||||
@@ -12,7 +14,9 @@ def run_install(PY_VERSION,USER):
|
|||||||
# pip
|
# pip
|
||||||
# linux/macosx: pip3
|
# linux/macosx: pip3
|
||||||
# windows: pip
|
# windows: pip
|
||||||
|
PYTHON_PATH = env["PYTHON_EXE_PATH"]
|
||||||
PYTHON_EXECUTABLE = "python3" if "osx" in env["OS_NAME"] else "python"
|
PYTHON_EXECUTABLE = "python3" if "osx" in env["OS_NAME"] else "python"
|
||||||
|
PIP_PATH = env["PIP_EXE_PATH"]
|
||||||
PIP_EXECUTABLE = "pip" if "windows" in env["OS_NAME"] else "pip3"
|
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
|
PIP_EXECUTABLE = "pip" if "osx" in env["OS_NAME"] and "actions" in env["CI_SYSTEM"] else PIP_EXECUTABLE
|
||||||
|
|
||||||
@@ -23,13 +27,17 @@ def run_install(PY_VERSION,USER):
|
|||||||
|
|
||||||
if float(PY_VERSION) > 0:
|
if float(PY_VERSION) > 0:
|
||||||
PYTHON_EXECUTABLE = "py"
|
PYTHON_EXECUTABLE = "py"
|
||||||
print("Installing to Python %.1f" % float(PY_VERSION))
|
PYTHON_PATH = env["PY_EXE_PATH"]
|
||||||
if USER:
|
print("Installing to Python %.1f via Py Launcher" % float(PY_VERSION))
|
||||||
print("Installing packages at User level")
|
else:
|
||||||
|
print("Installing to Python %s" % platform.python_version())
|
||||||
|
print("Installing packages at %s level" % ("User" if USER else "Global"))
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Upgrading pip-")
|
||||||
# upgrade pip
|
# upgrade pip
|
||||||
args = [
|
args = [
|
||||||
PYTHON_EXECUTABLE,
|
PYTHON_PATH + PYTHON_EXECUTABLE,
|
||||||
'-' + str(PY_VERSION),
|
'-' + str(PY_VERSION),
|
||||||
"-m",
|
"-m",
|
||||||
"pip",
|
"pip",
|
||||||
@@ -44,12 +52,11 @@ def run_install(PY_VERSION,USER):
|
|||||||
del args[1]
|
del args[1]
|
||||||
subprocess.check_call(args)
|
subprocess.check_call(args)
|
||||||
|
|
||||||
# pip version
|
|
||||||
subprocess.check_call([PIP_EXECUTABLE,"--version"])
|
|
||||||
# if pip3, install wheel
|
# if pip3, install wheel
|
||||||
if PIP_EXECUTABLE == "pip3":
|
if PIP_EXECUTABLE == "pip3":
|
||||||
|
print("Installing Wheel!")
|
||||||
args = [
|
args = [
|
||||||
PIP_EXECUTABLE,
|
PIP_PATH + PIP_EXECUTABLE,
|
||||||
"install",
|
"install",
|
||||||
"--user",
|
"--user",
|
||||||
"-U",
|
"-U",
|
||||||
@@ -58,9 +65,13 @@ def run_install(PY_VERSION,USER):
|
|||||||
if not USER:
|
if not USER:
|
||||||
args.remove("--user")
|
args.remove("--user")
|
||||||
subprocess.check_call(args)
|
subprocess.check_call(args)
|
||||||
|
|
||||||
|
print()
|
||||||
# install listed dependencies
|
# install listed dependencies
|
||||||
|
print("Installing dependencies")
|
||||||
|
print("-----------------------")
|
||||||
args = [
|
args = [
|
||||||
PIP_EXECUTABLE,
|
PIP_PATH + PIP_EXECUTABLE,
|
||||||
"install",
|
"install",
|
||||||
"--user",
|
"--user",
|
||||||
"-r",
|
"-r",
|
||||||
|
|||||||
33
resources/ci/common/my_path.py
Normal file
33
resources/ci/common/my_path.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def get_py_path():
|
||||||
|
user_paths = os.environ["PATH"].split(os.pathsep)
|
||||||
|
(python,py) = ("","")
|
||||||
|
|
||||||
|
for path in user_paths:
|
||||||
|
parts = path.split(os.sep)
|
||||||
|
part = parts[len(parts) - 1].lower()
|
||||||
|
if ("python" in part) and ('.' not in part):
|
||||||
|
path.replace(os.sep,os.sep + os.sep)
|
||||||
|
if path not in user_paths:
|
||||||
|
py = path
|
||||||
|
|
||||||
|
for path in sys.path:
|
||||||
|
parts = path.split(os.sep)
|
||||||
|
part = parts[len(parts) - 1].lower()
|
||||||
|
if ("python" in part) and ('.' not in part):
|
||||||
|
path.replace(os.sep,os.sep + os.sep)
|
||||||
|
if path not in user_paths:
|
||||||
|
python = path
|
||||||
|
|
||||||
|
paths = (
|
||||||
|
os.path.join(python,"") if python != "" else "",
|
||||||
|
os.path.join(py,"") if py != "" else "",
|
||||||
|
os.path.join(python,"Scripts","") if python != "" else ""
|
||||||
|
)
|
||||||
|
# print(paths)
|
||||||
|
return paths
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
get_py_path()
|
||||||
Reference in New Issue
Block a user