Skip to content

Commit 77aa292

Browse files
committed
new xp setup using venv
1 parent a6dcbce commit 77aa292

File tree

4 files changed

+70
-39
lines changed

4 files changed

+70
-39
lines changed

Diff for: pyproject.toml

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@ name = "davai"
33
dynamic = ["version"]
44
description = "Davai environment: commandlines for running DAVAI-tests experiments."
55
readme = "README.md"
6-
requires-python = ">=3.7"
6+
requires-python = ">=3.10"
77
keywords = []
88
license = {text = "CECILL-C"}
99
authors = [
1010
{ name = "Alexandre Mary" , email = "[email protected]"}
1111
]
1212
dependencies=[
1313
"pyyaml",
14-
# indirect dependencies: required by DAVAI-tests -> should be moved into DAVAI-tests, which should be cloned +
15-
# checkout + pip install -e ?
16-
"ial_build==1.3.0",
17-
"ial_expertise==1.2.0",
18-
"epygram==2.0.2",
19-
# "ecbundle" is not on PyPI, to be installed manually (though not mandatory for incr packs)
20-
"requests[socks]",
21-
"six",
14+
"ial_build==1.3.3",
2215
]
2316

2417
[project.urls]

Diff for: src/davai_env/conf/atos_bologna.ini

+3-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ logs = $SCRATCH/davai/logs
33
default_mtooldir = $SCRATCH/mtool/$LOGNAME
44

55
[packages]
6-
# vortex & epygram are special, the path has to be the root of the project
7-
#vortex = ~sos/vortex/vortex-olive-dev
8-
vortex = ~acrd/public/vortex/am_davai_ec_tmp
9-
epygram = ~acrd/public/EPyGrAM/1.4.x-49t2_bf
10-
# for others, the path has to lead to the python package
11-
ial_expertise = ~acrd/public/IAL-expertise/1.1.6/src/ial_expertise
12-
ial_build = ~acrd/public/IAL-build/1.2.6/src/ial_build
13-
ecbundle = ~acrd/public/ecbundle/2.0.0/ecbundle
6+
# vortex is special, the path has to be the root of the project
7+
vortex = ~sos/vortex/vortex-olive-dev
8+
#vortex = ~acrd/public/vortex/am_davai_ec_tmp

Diff for: src/davai_env/conf/belenos.ini

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@ logs = $WORKDIR/davai/logs
33
default_mtooldir = /scratch/mtool/$LOGNAME
44

55
[packages]
6-
# vortex & epygram are special, the path has to be the root of the project
6+
# vortex is special, the path has to be the root of the project
77
vortex = ~verolive/vortex/vortex-olive-dev
8-
epygram = ~mary/public/EPyGrAM/1.4.20-ecc2.38.0
9-
# for others, the path has to lead to the python package
10-
#ial_expertise = ~mary/public/IAL-expertise/1.2.0/src/ial_expertise
11-
#ial_build = ~mary/public/IAL-build/1.3.0/src/ial_build
12-
#ecbundle = ~mary/public/ecbundle/2.0.0/ecbundle

Diff for: src/davai_env/experiment.py

+64-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import configparser
1414
import yaml
1515
import time
16+
import venv
1617

1718
from ial_build.bundle import IALBundle, TmpIALbundleRepo
1819

@@ -84,12 +85,13 @@ def new_xp(cls, sources_to_test,
8485
# now XP path is created, we move in for the continuation of the experiment setup
8586
os.chdir(xp_path)
8687
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)
9395
if genesis_commandline:
9496
xp.write_genesis(genesis_commandline)
9597
return xp
@@ -108,6 +110,8 @@ class ThisXP(object):
108110

109111
def __init__(self, new=False):
110112
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)
111115
self.xpid = os.path.basename(os.path.dirname(os.path.dirname(self.xp_path)))
112116
self.vapp = os.path.basename(os.path.dirname(self.xp_path))
113117
self.vconf = os.path.basename(self.xp_path)
@@ -151,6 +155,39 @@ def setup(self, sources_to_test,
151155
self._setup_conf_general(host)
152156
self._setup_final_prompt()
153157

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+
154191
def guess_davai_tests_version(self, bundle_src_dir=None):
155192
"""Guess davai_tests_version from IAL repo (potentially through bundle)."""
156193
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):
225262

226263
def _setup_DAVAI_tests(self, remote, version):
227264
"""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)
230267
subprocess.check_call(['git', 'fetch', 'origin', version, '-q'])
231268
self._checkout_davai_tests(version)
232269
os.chdir(self.xp_path)
@@ -237,6 +274,21 @@ def check_sources_to_test(self, sources_to_test):
237274
self.sources_to_test_minimal_keys)
238275
assert assertion_test, assertion_errmsg
239276

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+
240292
def _setup_conf_sources(self, sources_to_test):
241293
"""Sources config: information on sources to be tested."""
242294
self.check_sources_to_test(sources_to_test)
@@ -262,10 +314,6 @@ def _setup_tasks(self):
262314

263315
def _setup_packages(self):
264316
"""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
269317
packages = {p:expandpath(config['packages'][p]) for p in config['packages']}
270318
for package, path in packages.items():
271319
os.symlink(expandpath(path), package)
@@ -281,10 +329,10 @@ def _setup_final_prompt(self):
281329
"""Final prompt for the setup of the experiment."""
282330
print("------------------------------------")
283331
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'")
288336
print("------------------------------------")
289337

290338
def write_genesis(self, command):

0 commit comments

Comments
 (0)