13
13
import configparser
14
14
import yaml
15
15
import time
16
+ import venv
16
17
17
18
from ial_build .bundle import IALBundle , TmpIALbundleRepo
18
19
@@ -84,12 +85,13 @@ def new_xp(cls, sources_to_test,
84
85
# now XP path is created, we move in for the continuation of the experiment setup
85
86
os .chdir (xp_path )
86
87
xp = ThisXP (new = True )
87
- xp .setup (sources_to_test ,
88
- davai_tests_version = davai_tests_version ,
89
- davai_tests_origin = davai_tests_origin ,
90
- usecase = usecase ,
91
- host = host ,
92
- bundle_src_dir = bundle_src_dir )
88
+ #xp.setup(sources_to_test,
89
+ xp .venv_setup (sources_to_test ,
90
+ davai_tests_version = davai_tests_version ,
91
+ davai_tests_origin = davai_tests_origin ,
92
+ usecase = usecase ,
93
+ host = host ,
94
+ bundle_src_dir = bundle_src_dir )
93
95
if genesis_commandline :
94
96
xp .write_genesis (genesis_commandline )
95
97
return xp
@@ -108,6 +110,8 @@ class ThisXP(object):
108
110
109
111
def __init__ (self , new = False ):
110
112
self .xp_path = os .getcwd ()
113
+ self .venv_path = os .path .join (self .xp_path , '.venv' )
114
+ self .davai_tests_absdir = os .path .join (self .xp_path , self .davai_tests_dir )
111
115
self .xpid = os .path .basename (os .path .dirname (os .path .dirname (self .xp_path )))
112
116
self .vapp = os .path .basename (os .path .dirname (self .xp_path ))
113
117
self .vconf = os .path .basename (self .xp_path )
@@ -151,6 +155,39 @@ def setup(self, sources_to_test,
151
155
self ._setup_conf_general (host )
152
156
self ._setup_final_prompt ()
153
157
158
+ def venv_setup (self , sources_to_test ,
159
+ davai_tests_version = None ,
160
+ davai_tests_origin = config ['defaults' ]['davai_tests_origin' ],
161
+ usecase = config ['defaults' ]['usecase' ],
162
+ host = guess_host (),
163
+ bundle_src_dir = None ):
164
+ """
165
+ Setup the experiment as a venv (at creation time).
166
+
167
+ :param sources_to_test: information about the sources to be tested, provided as a dict
168
+ :param davai_tests_version: version of the DAVAI-tests to be used. If not provided, try to guess from IAL repo
169
+ :param davai_tests_origin: remote repository of the DAVAI-tests to be cloned
170
+ :param usecase: type of set of tests to be prepared
171
+ :param host: host machine
172
+ :param bundle_src_dir: in case tests_version is not specified:
173
+ cache directory where to download/update bundle repositories,
174
+ in search for the tests_version, potentially stored in IAL.
175
+ """
176
+ os .makedirs ('conf' )
177
+ self ._setup_conf_sources (sources_to_test )
178
+ if davai_tests_version is None :
179
+ # this will fail if the version is not known in IAL
180
+ davai_tests_version = self .guess_davai_tests_version (bundle_src_dir = bundle_src_dir )
181
+ # set DAVAI-tests repo
182
+ self ._setup_DAVAI_tests (davai_tests_origin , davai_tests_version )
183
+ self ._setup_venv ()
184
+ self ._setup_packages () # remaining, not on PyPI: vortex
185
+ self ._setup_logs ()
186
+ # configuration files
187
+ self ._setup_conf_usecase (usecase )
188
+ self ._setup_conf_general (host )
189
+ self ._setup_final_prompt ()
190
+
154
191
def guess_davai_tests_version (self , bundle_src_dir = None ):
155
192
"""Guess davai_tests_version from IAL repo (potentially through bundle)."""
156
193
if 'IAL_git_ref' in self .sources_to_test and 'IAL_repository' in self .sources_to_test :
@@ -225,8 +262,8 @@ def _checkout_davai_tests(gitref):
225
262
226
263
def _setup_DAVAI_tests (self , remote , version ):
227
264
"""Clone and checkout required version of the DAVAI-tests."""
228
- subprocess .check_call (['git' , 'clone' , remote , self .davai_tests_dir ])
229
- os .chdir (self .davai_tests_dir )
265
+ subprocess .check_call (['git' , 'clone' , remote , self .davai_tests_absdir ])
266
+ os .chdir (self .davai_tests_absdir )
230
267
subprocess .check_call (['git' , 'fetch' , 'origin' , version , '-q' ])
231
268
self ._checkout_davai_tests (version )
232
269
os .chdir (self .xp_path )
@@ -237,6 +274,21 @@ def check_sources_to_test(self, sources_to_test):
237
274
self .sources_to_test_minimal_keys )
238
275
assert assertion_test , assertion_errmsg
239
276
277
+ def _setup_venv (self ):
278
+ """Create a new venv it."""
279
+ # create venv within the xp
280
+ print ("Create virtualenv ({})..." .format (self .venv_path ))
281
+ venv .create (self .venv_path ,
282
+ with_pip = True ,
283
+ symlinks = True ,
284
+ prompt = '{}.venv' .format (self .xpid ))
285
+ print ("... virtualenv created." )
286
+ # install DAVAI-tests and dependencies in the venv
287
+ venv_python = os .path .join (self .venv_path , 'bin' , 'python' )
288
+ print ("Setup virtualenv..." )
289
+ subprocess .check_call ([venv_python , '-m' , 'pip' , 'install' , '-e' , self .davai_tests_absdir ])
290
+ print ("... virtualenv set up." )
291
+
240
292
def _setup_conf_sources (self , sources_to_test ):
241
293
"""Sources config: information on sources to be tested."""
242
294
self .check_sources_to_test (sources_to_test )
@@ -262,10 +314,6 @@ def _setup_tasks(self):
262
314
263
315
def _setup_packages (self ):
264
316
"""Link necessary packages in XP."""
265
- # davai_taskutil from DAVAI-tests locally checkedout
266
- os .symlink (os .path .join (self .davai_tests_dir , 'src' , 'davai_taskutil' ),
267
- 'davai_taskutil' )
268
- # other packages
269
317
packages = {p :expandpath (config ['packages' ][p ]) for p in config ['packages' ]}
270
318
for package , path in packages .items ():
271
319
os .symlink (expandpath (path ), package )
@@ -281,10 +329,10 @@ def _setup_final_prompt(self):
281
329
"""Final prompt for the setup of the experiment."""
282
330
print ("------------------------------------" )
283
331
print ("DAVAI xp '{}' has been successfully setup !" .format (self .xpid ))
284
- print ("Now go to the XP path below and:" )
285
- print ("- if necessary, tune experiment in '{}'" .format (self .general_config_file ))
286
- print ("- run experiment using : 'davai-run_xp'" )
287
- print (" =>" , self . xp_path )
332
+ print (" => XP path:" , self . xp_path )
333
+ print (" => XP config file: '{}'" .format (self .general_config_file ))
334
+ print (" => Activation venv : 'source {}/bin/activate'" . format ( self . venv_path ) )
335
+ print (" => Run experiment : 'davai-run_xp'" )
288
336
print ("------------------------------------" )
289
337
290
338
def write_genesis (self , command ):
0 commit comments