summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-11-17 09:16:51 +0200
committerLars Wirzenius <liw@liw.fi>2020-11-17 09:16:51 +0200
commitd67e20c6e29fcaff08340adf5eb7103f18f9fc81 (patch)
treea1d68ee101b87565f583ec2d63b0cc9a0ead9325 /templates
parent34cbe3d66c6a03d405915eac35a002a3c4013cd0 (diff)
downloadsubplot-d67e20c6e29fcaff08340adf5eb7103f18f9fc81.tar.gz
fix: set TMPDIR for each scenario to its datadir
Diffstat (limited to 'templates')
-rw-r--r--templates/python/main.py14
-rw-r--r--templates/python/scenarios.py4
2 files changed, 16 insertions, 2 deletions
diff --git a/templates/python/main.py b/templates/python/main.py
index fa78a5f..7f55765 100644
--- a/templates/python/main.py
+++ b/templates/python/main.py
@@ -28,17 +28,29 @@ def parse_command_line():
return p.parse_args()
+# Any environment variables set to this value will be set to the data directory
+# for each scenario, when the scenario starts.
+_DATADIR_COOKIE = "set-this-to-datadir-for-each-scenario"
+
+
def setup_minimal_environment():
minimal = {
"PATH": "/bin:/usr/bin",
"SHELL": "/bin/sh",
- "HOME": "/", # will be set to datadir for each scenario
+ "HOME": _DATADIR_COOKIE,
+ "TMPDIR": _DATADIR_COOKIE,
}
os.environ.clear()
os.environ.update(minimal)
+def set_environment_variables_to(scendir):
+ for key in os.environ:
+ if os.environ[key] == _DATADIR_COOKIE:
+ os.environ[key] = scendir
+
+
def setup_logging(args):
if args.log:
fmt = "%(asctime)s %(levelname)s %(message)s"
diff --git a/templates/python/scenarios.py b/templates/python/scenarios.py
index 71ed880..6dbc1a8 100644
--- a/templates/python/scenarios.py
+++ b/templates/python/scenarios.py
@@ -60,12 +60,14 @@ class Scenario:
self._steps.append(step)
def run(self, datadir):
+ set_environment_variables_to = globals()["set_environment_variables_to"]
+
print("scenario: {}".format(self._title))
logging.info("Scenario: {}".format(self._title))
scendir = tempfile.mkdtemp(dir=datadir)
os.chdir(scendir)
- os.environ["HOME"] = scendir
+ set_environment_variables_to(scendir)
done = []
ctx = self._ctx