Created setup.py
This commit is contained in:
68
setup.py
Normal file
68
setup.py
Normal file
@ -0,0 +1,68 @@
|
||||
"""
|
||||
Initalises the launchers virtual environment,
|
||||
and installs all dependancies.
|
||||
"""
|
||||
|
||||
import subprocess as sp
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
import os
|
||||
|
||||
def getVenvExec():
|
||||
"""
|
||||
Gets the path of the virtual environment
|
||||
based on the current opperating system.
|
||||
"""
|
||||
plat = platform.system()
|
||||
if plat == 'Linux':
|
||||
return f'./.venv/bin/python3'
|
||||
elif plat == 'Windows':
|
||||
return f'./.venv/Scripts/python.exe'
|
||||
else:
|
||||
print(f'WARNING: Playform type "{plat}" is not recognised. Exiting...')
|
||||
exit(1)
|
||||
|
||||
def inputYN(prompt: str, default=None):
|
||||
"""
|
||||
A simply yes/no prompt.
|
||||
"""
|
||||
while True:
|
||||
i = input(prompt)
|
||||
|
||||
if i.lower() in ['y', 'yes', '1', 'true']: return True
|
||||
elif i.lower() in ['n', 'no', '0', 'false']: return False
|
||||
elif i == '' and default != None: return default
|
||||
|
||||
def installRequirements(requirementsPath: str):
|
||||
"""
|
||||
Installs a requirements.txt file to the current venv.
|
||||
"""
|
||||
print(f'---------- Installing {requirementsPath} ----------')
|
||||
sp.run([getVenvExec(), '-m', 'pip', 'install', '-r', requirementsPath])
|
||||
|
||||
# Check for a pre-existing venv
|
||||
if os.path.isdir('./.venv/'):
|
||||
# If one exists, ask the user if they want to delete it
|
||||
replace = inputYN(f'Virtual environment already exists, would you like to replace it? (y/n) > ')
|
||||
if replace:
|
||||
# If so, remove the .venv directory
|
||||
print(f'---------- Removing old virtual environment ----------')
|
||||
shutil.rmtree('./.venv/')
|
||||
|
||||
# Initailise a venv, creating one if it doesn't exist
|
||||
print(f'---------- Initalising virtual environment ----------')
|
||||
sp.run([sys.executable, '-m', 'venv', './.venv/'])
|
||||
|
||||
# Upgrade pip
|
||||
print(f'---------- Upgrading pip ----------')
|
||||
sp.run([getVenvExec(), '-m', 'pip', 'install', '-U', 'pip'])
|
||||
|
||||
# Install all requirements.txt files
|
||||
for path in os.listdir('../'):
|
||||
requirementsPath = os.path.join('../', path, 'requirements.txt')
|
||||
if not os.path.isfile(requirementsPath):
|
||||
print(f'{path} does not have a requirements.txt, skipping...')
|
||||
continue
|
||||
|
||||
installRequirements(requirementsPath)
|
||||
Reference in New Issue
Block a user