1414 os .path .join (root_dir , 'solvers' ),
1515]
1616
17+ def get_gamspy_license ():
18+ # 1. Environment variable (GitHub Actions)
19+ license_key = os .environ .get ("GAMSPY_LICENSE" )
20+ if license_key :
21+ return license_key .strip ()
22+
23+ # 2. Local file (ignored by git)
24+ license_file = os .path .join (root_dir , ".gamspy_license" )
25+ if os .path .exists (license_file ):
26+ with open (license_file ) as f :
27+ return f .read ().strip ()
28+
29+ raise RuntimeError (
30+ "No GAMSPY license found. "
31+ "Set the GAMSPY_LICENSE environment variable or create a .gamspy_license file."
32+ )
33+
1734exitCode = 0
1835for base_dir in base_dirs :
1936 for root , dirs , files in os .walk (base_dir ):
2441 # Iterate over problem directory (knapsack, tsp, etc.)
2542 for solver_name in os .listdir (framework_dir ):
2643 solver_dir = os .path .join (framework_dir , solver_name )
44+
2745 # If folder filter is specified, only process matching folders
2846 if folder_filter and folder_filter not in solver_dir :
2947 continue
3048
3149 req_file = os .path .join (solver_dir , 'requirements.txt' )
3250 if os .path .exists (req_file ):
3351 venv_name = f"{ os .path .basename (root )} _{ framework_name } _{ solver_name } "
34- print (f"Setting up virtual environment '{ venv_name } ' for { solver_dir } ..." )
52+
53+ print (f"Setting up virtual environment '{ venv_name } '" )
3554 try :
3655 venv_path = os .path .join ('venv' , venv_name )
37- subprocess .run (['python' , '-m' , 'venv' , venv_path ], check = True )
56+ subprocess .run (['python' , '-m' , 'venv' , venv_path ], check = True , capture_output = True )
3857 if platform .system () == 'Windows' :
3958 pip_executable = os .path .join (venv_path , 'Scripts' , 'pip.exe' )
59+ python_executable = os .path .join (venv_path , 'Scripts' , 'python.exe' )
4060 else :
4161 pip_executable = os .path .join (venv_path , 'bin' , 'pip' )
42- subprocess .run ([pip_executable , 'install' , '-r' , req_file ], check = True )
62+ python_executable = os .path .join (venv_path , 'bin' , 'python' )
63+
64+ # install dependencies from requirements.txt
65+ subprocess .run ([pip_executable , 'install' , '-r' , req_file ], check = True , capture_output = True )
66+
67+ # install GAMSPy license if this is a GAMS environment
68+ if "gams" in venv_name .lower ():
69+ license_key = get_gamspy_license ()
70+
71+ print ("Installing GAMSPy license and scip solver ..." )
72+ subprocess .run (
73+ [
74+ python_executable ,
75+ "-m" ,
76+ "gamspy" ,
77+ "install" ,
78+ "license" ,
79+ license_key ,
80+ ],
81+ check = True ,
82+ capture_output = True ,
83+ )
84+
85+ subprocess .run (
86+ [
87+ python_executable ,
88+ "-m" ,
89+ "gamspy" ,
90+ "install" ,
91+ "solver" ,
92+ "scip"
93+ ],
94+ check = True ,
95+ capture_output = True ,
96+ )
97+
4398 except subprocess .CalledProcessError as e :
44- print (f"Error setting up virtual environment for { solver_dir } : { e } " )
99+ print (f"Error setting up virtual environment '{ venv_name } ' for { solver_dir } :" )
100+ if e .stdout :
101+ print ("STDOUT:" )
102+ print (e .stdout .decode () if isinstance (e .stdout , bytes ) else e .stdout )
103+ if e .stderr :
104+ print ("STDERR:" )
105+ print (e .stderr .decode () if isinstance (e .stderr , bytes ) else e .stderr )
45106 exitCode = 1
46107
47108# let pipeline fail if there was an error in the venv setup.
48- exit (exitCode )
109+ exit (exitCode )
0 commit comments