2020-01-19 20:50:04 +00:00
|
|
|
import os
|
2020-01-18 14:45:52 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2021-06-06 13:11:17 +00:00
|
|
|
import pkg_resources
|
2020-10-19 06:26:31 +00:00
|
|
|
|
2022-03-31 23:09:16 +00:00
|
|
|
local_dir = os.path.dirname(__file__)
|
|
|
|
requirements_files = {os.path.join(local_dir, 'requirements.txt')}
|
2021-06-06 13:30:20 +00:00
|
|
|
|
2020-10-19 06:26:31 +00:00
|
|
|
if sys.version_info < (3, 8, 6):
|
|
|
|
raise RuntimeError("Incompatible Python Version. 3.8.7+ is supported.")
|
|
|
|
|
2021-06-06 13:11:17 +00:00
|
|
|
update_ran = getattr(sys, "frozen", False) # don't run update if environment is frozen/compiled
|
2020-01-19 22:30:22 +00:00
|
|
|
|
2021-06-06 13:30:20 +00:00
|
|
|
if not update_ran:
|
2022-03-31 23:09:16 +00:00
|
|
|
for entry in os.scandir(os.path.join(local_dir, "worlds")):
|
2022-10-01 15:38:39 +00:00
|
|
|
# skip .* (hidden / disabled) folders
|
|
|
|
if not entry.name.startswith("."):
|
|
|
|
if entry.is_dir():
|
|
|
|
req_file = os.path.join(entry.path, "requirements.txt")
|
|
|
|
if os.path.exists(req_file):
|
|
|
|
requirements_files.add(req_file)
|
2021-06-06 13:30:20 +00:00
|
|
|
|
2020-01-18 14:45:52 +00:00
|
|
|
|
|
|
|
def update_command():
|
2021-06-06 13:11:17 +00:00
|
|
|
for file in requirements_files:
|
|
|
|
subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', file, '--upgrade'])
|
2020-01-19 22:30:22 +00:00
|
|
|
|
|
|
|
|
2022-01-22 19:35:30 +00:00
|
|
|
def update(yes=False, force=False):
|
2020-01-18 14:45:52 +00:00
|
|
|
global update_ran
|
|
|
|
if not update_ran:
|
|
|
|
update_ran = True
|
2021-07-26 21:05:41 +00:00
|
|
|
if force:
|
|
|
|
update_command()
|
|
|
|
return
|
2021-06-06 13:11:17 +00:00
|
|
|
for req_file in requirements_files:
|
|
|
|
path = os.path.join(os.path.dirname(sys.argv[0]), req_file)
|
|
|
|
if not os.path.exists(path):
|
|
|
|
path = os.path.join(os.path.dirname(__file__), req_file)
|
|
|
|
with open(path) as requirementsfile:
|
2021-11-07 13:00:13 +00:00
|
|
|
for line in requirementsfile:
|
|
|
|
if line.startswith('https://'):
|
|
|
|
# extract name and version from url
|
|
|
|
wheel = line.split('/')[-1]
|
2022-01-22 19:35:30 +00:00
|
|
|
name, version, _ = wheel.split('-', 2)
|
2021-11-07 13:00:13 +00:00
|
|
|
line = f'{name}=={version}'
|
|
|
|
requirements = pkg_resources.parse_requirements(line)
|
|
|
|
for requirement in requirements:
|
|
|
|
requirement = str(requirement)
|
|
|
|
try:
|
|
|
|
pkg_resources.require(requirement)
|
|
|
|
except pkg_resources.ResolutionError:
|
|
|
|
if not yes:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
input(f'Requirement {requirement} is not satisfied, press enter to install it')
|
|
|
|
update_command()
|
|
|
|
return
|
2020-01-18 14:45:52 +00:00
|
|
|
|
2020-03-06 22:37:57 +00:00
|
|
|
|
2020-01-18 14:45:52 +00:00
|
|
|
if __name__ == "__main__":
|
2021-07-26 21:05:41 +00:00
|
|
|
import argparse
|
2022-01-22 19:35:30 +00:00
|
|
|
|
2021-07-26 21:05:41 +00:00
|
|
|
parser = argparse.ArgumentParser(description='Install archipelago requirements')
|
|
|
|
parser.add_argument('-y', '--yes', dest='yes', action='store_true', help='answer "yes" to all questions')
|
|
|
|
parser.add_argument('-f', '--force', dest='force', action='store_true', help='force update')
|
2022-05-03 20:14:03 +00:00
|
|
|
parser.add_argument('-a', '--append', nargs="*", dest='additional_requirements',
|
|
|
|
help='List paths to additional requirement files.')
|
2021-07-26 21:05:41 +00:00
|
|
|
args = parser.parse_args()
|
2022-05-03 20:14:03 +00:00
|
|
|
if args.additional_requirements:
|
|
|
|
requirements_files.update(args.additional_requirements)
|
2021-07-26 21:05:41 +00:00
|
|
|
update(args.yes, args.force)
|