| 
									
										
										
										
											2020-01-19 12:50:04 -08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2020-01-18 15:45:52 +01:00
										 |  |  | import sys | 
					
						
							|  |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2021-06-06 15:11:17 +02:00
										 |  |  | import pkg_resources | 
					
						
							| 
									
										
										
										
											2020-10-19 08:26:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 15:30:20 +02:00
										 |  |  | requirements_files = {'requirements.txt'} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-19 08:26:31 +02:00
										 |  |  | if sys.version_info < (3, 8, 6): | 
					
						
							|  |  |  |     raise RuntimeError("Incompatible Python Version. 3.8.7+ is supported.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 15:11:17 +02:00
										 |  |  | update_ran = getattr(sys, "frozen", False)  # don't run update if environment is frozen/compiled | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-06 15:30:20 +02:00
										 |  |  | if not update_ran: | 
					
						
							|  |  |  |     for entry in os.scandir("worlds"): | 
					
						
							|  |  |  |         if entry.is_dir(): | 
					
						
							|  |  |  |             req_file = os.path.join(entry.path, "requirements.txt") | 
					
						
							|  |  |  |             if os.path.exists(req_file): | 
					
						
							|  |  |  |                 requirements_files.add(req_file) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-18 15:45:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def update_command(): | 
					
						
							| 
									
										
										
										
											2021-06-06 15:11:17 +02:00
										 |  |  |     for file in requirements_files: | 
					
						
							|  |  |  |         subprocess.call([sys.executable, '-m', 'pip', 'install', '-r', file, '--upgrade']) | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 23:05:41 +02:00
										 |  |  | def update(yes = False, force = False): | 
					
						
							| 
									
										
										
										
											2020-01-18 15:45:52 +01:00
										 |  |  |     global update_ran | 
					
						
							|  |  |  |     if not update_ran: | 
					
						
							|  |  |  |         update_ran = True | 
					
						
							| 
									
										
										
										
											2021-07-26 23:05:41 +02:00
										 |  |  |         if force: | 
					
						
							|  |  |  |             update_command() | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2021-06-06 15:11:17 +02: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 14:00:13 +01:00
										 |  |  |                 for line in requirementsfile: | 
					
						
							|  |  |  |                     if line.startswith('https://'): | 
					
						
							|  |  |  |                         # extract name and version from url | 
					
						
							|  |  |  |                         url = line.split(';')[0] | 
					
						
							|  |  |  |                         wheel = line.split('/')[-1] | 
					
						
							|  |  |  |                         name, version, _ = wheel.split('-',2) | 
					
						
							|  |  |  |                         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 15:45:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 23:37:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-18 15:45:52 +01:00
										 |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2021-07-26 23:05:41 +02:00
										 |  |  |     import argparse | 
					
						
							|  |  |  |     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') | 
					
						
							|  |  |  |     args = parser.parse_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     update(args.yes, args.force) |