Commit 9f0e8ffe by Tianqi Chen

[PYTHON] Enable environment scoping (#33)

parent 7ab574b0
......@@ -143,6 +143,15 @@ class Environment(object):
self.mock_mode = False
self._mock_env = None
self._dev_ctx = None
self._last_env = None
def __enter__(self):
self._last_env = Environment.current
Environment.current = self
return self
def __exit__(self, ptype, value, trace):
Environment.current = self._last_env
def pkg_config(self):
"""PkgConfig instance"""
......
......@@ -6,6 +6,15 @@ def test_env():
mock = env.mock
assert mock.alu == "skip_alu"
def test_env_scope():
env = vta.get_env()
cfg = env.pkg_config().cfg_dict
cfg["TARGET"] = "xyz"
with vta.Environment(cfg):
assert vta.get_env().TARGET == "xyz"
assert vta.get_env().TARGET == env.TARGET
if __name__ == "__main__":
test_env()
test_env_scope()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment