Skip to content

Commit 9ebdeb9

Browse files
committed
Avoid checking executable rights of subdirs of temp dirs already checked
`run_cmd` is one of the slowest things we can do as it forks the whole process. In the check when setting a temp dir we run a dummy file to see if the folder is actually executable. This means running this check at least twice per test case and another time for each init_config call in the test amounting to e.g. 263 calls in a single test (test_compiler_dependent_optarch) So cache the results and don't repeat the run_cmd if it already succeeded for a parent folder. Likely no change at all in regular mode but really helps for the tests
1 parent 25b5ade commit 9ebdeb9

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

easybuild/tools/options.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,24 +1756,31 @@ def set_tmpdir(tmpdir=None, raise_error=False):
17561756
# reset to make sure tempfile picks up new temporary directory to use
17571757
tempfile.tempdir = None
17581758

1759-
# test if temporary directory allows to execute files, warn if it doesn't
1760-
try:
1761-
fd, tmptest_file = tempfile.mkstemp()
1762-
os.close(fd)
1763-
os.chmod(tmptest_file, 0o700)
1764-
if not run_cmd(tmptest_file, simple=True, log_ok=False, regexp=False, force_in_dry_run=True, trace=False,
1765-
stream_output=False):
1766-
msg = "The temporary directory (%s) does not allow to execute files. " % tempfile.gettempdir()
1767-
msg += "This can cause problems in the build process, consider using --tmpdir."
1768-
if raise_error:
1769-
raise EasyBuildError(msg)
1759+
# Skip the executable check if it already succeeded for any parent folder
1760+
# Especially important for the unit test suite, less so for actual execution
1761+
executable_tmp_paths = getattr(set_tmpdir, 'executable_tmp_paths', [])
1762+
if not any(current_tmpdir.startswith(path) for path in executable_tmp_paths):
1763+
# test if temporary directory allows to execute files, warn if it doesn't
1764+
try:
1765+
fd, tmptest_file = tempfile.mkstemp()
1766+
os.close(fd)
1767+
os.chmod(tmptest_file, 0o700)
1768+
if not run_cmd(tmptest_file, simple=True, log_ok=False, regexp=False, force_in_dry_run=True, trace=False,
1769+
stream_output=False):
1770+
msg = "The temporary directory (%s) does not allow to execute files. " % tempfile.gettempdir()
1771+
msg += "This can cause problems in the build process, consider using --tmpdir."
1772+
if raise_error:
1773+
raise EasyBuildError(msg)
1774+
else:
1775+
_log.warning(msg)
17701776
else:
1771-
_log.warning(msg)
1772-
else:
1773-
_log.debug("Temporary directory %s allows to execute files, good!" % tempfile.gettempdir())
1774-
os.remove(tmptest_file)
1777+
_log.debug("Temporary directory %s allows to execute files, good!" % tempfile.gettempdir())
1778+
# Put this folder into the cache
1779+
executable_tmp_paths.append(current_tmpdir)
1780+
set_tmpdir.executable_tmp_paths = executable_tmp_paths
1781+
os.remove(tmptest_file)
17751782

1776-
except OSError as err:
1777-
raise EasyBuildError("Failed to test whether temporary directory allows to execute files: %s", err)
1783+
except OSError as err:
1784+
raise EasyBuildError("Failed to test whether temporary directory allows to execute files: %s", err)
17781785

17791786
return current_tmpdir

0 commit comments

Comments
 (0)