Skip to content

Commit dfe3b3f

Browse files
authored
Merge pull request #4350 from boegel/easystack_tmpdir_fix
reset `tempfile.tempdir` to `None` to avoid that tmpdir path gets progressively deeper with each easystack item
2 parents 0f4ddfa + 7a1a56d commit dfe3b3f

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

easybuild/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import os
4343
import stat
4444
import sys
45+
import tempfile
4546
import traceback
4647

4748
# IMPORTANT this has to be the first easybuild import as it customises the logging
@@ -254,8 +255,9 @@ def process_easystack(easystack_path, args, logfile, testing, init_session_state
254255
easyconfig._easyconfigs_cache.clear()
255256
easyconfig._easyconfig_files_cache.clear()
256257

257-
# restore environment
258+
# restore environment and reset tempdir (to avoid tmpdir path getting progressively longer)
258259
restore_env(init_env)
260+
tempfile.tempdir = None
259261

260262
# If EasyConfig specific arguments were supplied in EasyStack file
261263
# merge arguments with original command line args

test/framework/easystack.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import os
3232
import re
3333
import sys
34+
import tempfile
3435
from unittest import TextTestRunner
3536

3637
import easybuild.tools.build_log
@@ -129,11 +130,22 @@ def test_easystack_invalid_key2(self):
129130
self.assertErrorRegex(EasyBuildError, error_pattern, parse_easystack, test_easystack)
130131

131132
def test_easystack_restore_env_after_each_build(self):
132-
"""Test that the build environment is reset for each easystack item"""
133+
"""Test that the build environment and tmpdir is reset for each easystack item"""
134+
135+
orig_tmpdir_tempfile = tempfile.gettempdir()
136+
orig_tmpdir_env = os.getenv('TMPDIR')
137+
orig_tmpdir_tempfile_len = len(orig_tmpdir_env.split(os.path.sep))
138+
orig_tmpdir_env_len = len(orig_tmpdir_env.split(os.path.sep))
139+
133140
test_es_txt = '\n'.join([
134141
"easyconfigs:",
135142
" - toy-0.0-gompi-2018a.eb:",
136143
" - libtoy-0.0.eb:",
144+
# also include a couple of easyconfigs for which a module is already available in test environment,
145+
# see test/framework/modules
146+
" - GCC-7.3.0-2.30",
147+
" - FFTW-3.3.7-gompi-2018a",
148+
" - foss-2018a",
137149
])
138150
test_es_path = os.path.join(self.test_prefix, 'test.yml')
139151
write_file(test_es_path, test_es_txt)
@@ -143,10 +155,24 @@ def test_easystack_restore_env_after_each_build(self):
143155
'--easystack',
144156
test_es_path
145157
]
146-
stdout = self.eb_main(args, do_build=True, raise_error=True)
158+
stdout = self.eb_main(args, do_build=True, raise_error=True, reset_env=False, redo_init_config=False)
147159
regex = re.compile(r"WARNING Loaded modules detected: \[.*gompi/2018.*\]\n")
148160
self.assertFalse(regex.search(stdout), "Pattern '%s' should not be found in: %s" % (regex.pattern, stdout))
149161

162+
# temporary directory after run should be exactly 2 levels deeper than original one:
163+
# - 1 level added by setting up configuration in EasyBuild main function
164+
# - 1 extra level added by first re-configuration for easystack item
165+
# (because $TMPDIR set by configuration done in main function is retained)
166+
tmpdir_tempfile = tempfile.gettempdir()
167+
tmpdir_env = os.getenv('TMPDIR')
168+
tmpdir_tempfile_len = len(tmpdir_tempfile.split(os.path.sep))
169+
tmpdir_env_len = len(tmpdir_env.split(os.path.sep))
170+
171+
self.assertEqual(tmpdir_tempfile_len, orig_tmpdir_tempfile_len + 2)
172+
self.assertEqual(tmpdir_env_len, orig_tmpdir_env_len + 2)
173+
self.assertTrue(tmpdir_tempfile.startswith(orig_tmpdir_tempfile))
174+
self.assertTrue(tmpdir_env.startswith(orig_tmpdir_env))
175+
150176
def test_missing_easyconfigs_key(self):
151177
"""Test that EasyStack file that doesn't contain an EasyConfigs key will fail with sane error message"""
152178
topdir = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)