Skip to content

Commit

Permalink
[PYTHON] Enable environment scoping (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed Jul 12, 2018
1 parent 8ae7ae8 commit ff226da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vta/python/vta/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def __init__(self, cfg):
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"""
Expand Down
9 changes: 9 additions & 0 deletions vta/tests/python/unittest/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit ff226da

Please sign in to comment.