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
|
|
|
|
2021-06-06 13:11:17 +00:00
|
|
|
requirements_files = ['requirements.txt']
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
2020-01-18 14:45:52 +00:00
|
|
|
def update():
|
|
|
|
global update_ran
|
|
|
|
if not update_ran:
|
|
|
|
update_ran = True
|
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:
|
|
|
|
requirements = pkg_resources.parse_requirements(requirementsfile)
|
|
|
|
for requirement in requirements:
|
|
|
|
requirement = str(requirement)
|
|
|
|
try:
|
|
|
|
pkg_resources.require(requirement)
|
|
|
|
except pkg_resources.ResolutionError:
|
|
|
|
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__":
|
2020-01-19 20:50:04 +00:00
|
|
|
update()
|