diff --git a/lib/ramble/ramble/cmd/workspace.py b/lib/ramble/ramble/cmd/workspace.py index 83c790b2d..6fcbb1d84 100644 --- a/lib/ramble/ramble/cmd/workspace.py +++ b/lib/ramble/ramble/cmd/workspace.py @@ -107,22 +107,19 @@ def workspace_activate(args): # Temporary workspace if args.temp: workspace = create_temp_workspace_directory() - wspath_dir = os.path.abspath(workspace) - ramble.workspace.set_workspace_path(wspath_dir) - short_name = os.path.basename(wspath_dir) + workspace_path = os.path.abspath(workspace) + short_name = os.path.basename(workspace_path) ramble.workspace.Workspace(workspace).write() # Named workspace elif ramble.workspace.exists(workspace_name_or_dir) and not args.dir: - wspath_dir = ramble.workspace.root(workspace_name_or_dir) - ramble.workspace.set_workspace_path(wspath_dir) + workspace_path = ramble.workspace.root(workspace_name_or_dir) short_name = workspace_name_or_dir # Workspace directory elif ramble.workspace.is_workspace_dir(workspace_name_or_dir): - workspace_path_dir = os.path.abspath(workspace_name_or_dir) - ramble.workspace.set_workspace_path(workspace_path_dir) - short_name = os.path.basename(workspace_path_dir) + workspace_path = os.path.abspath(workspace_name_or_dir) + short_name = os.path.basename(workspace_path) else: tty.die("No such workspace: '%s'" % workspace_name_or_dir) @@ -138,8 +135,7 @@ def workspace_activate(args): env_mods = ramble.workspace.shell.deactivate() # Activate new workspace - workspace_path_dir = ramble.workspace.get_workspace_path() - active_workspace = ramble.workspace.Workspace(workspace_path_dir) + active_workspace = ramble.workspace.Workspace(workspace_path) cmds += ramble.workspace.shell.activate_header( ws=active_workspace, shell=args.shell, diff --git a/lib/ramble/ramble/test/cmd/workspace.py b/lib/ramble/ramble/test/cmd/workspace.py index 1017d3cd4..3a8c81cf6 100644 --- a/lib/ramble/ramble/test/cmd/workspace.py +++ b/lib/ramble/ramble/test/cmd/workspace.py @@ -220,9 +220,9 @@ def test_workspace_dirs(tmpdir, mutable_mock_workspace_path): # it would be expected wsdir1 = os.path.join(os.getcwd(), 'ws1') os.makedirs(wsdir1) - ramble.workspace.set_workspace_path(wsdir1) - workspace('create', 'test1') - out = workspace('list') + with ramble.config.override('config:workspace_dirs', wsdir1): + workspace('create', 'test1') + out = workspace('list') assert 'test1' in out # Now make a second temp directory, @@ -232,17 +232,12 @@ def test_workspace_dirs(tmpdir, mutable_mock_workspace_path): # second is wsdir2 = os.path.join(os.getcwd(), 'ws2') os.makedirs(wsdir2) - ramble.workspace.set_workspace_path(wsdir2) - workspace('create', 'test2') - out = workspace('list') + with ramble.config.override('config:workspace_dirs', wsdir2): + workspace('create', 'test2') + out = workspace('list') assert 'test2' in out assert 'test1' not in out - # Cleanup after test - workspace('remove', '-y', 'test2') - ramble.workspace.set_workspace_path(wsdir1) - workspace('remove', '-y', 'test1') - def test_remove_workspace(capfd): workspace('create', 'foo') diff --git a/lib/ramble/ramble/test/conftest.py b/lib/ramble/ramble/test/conftest.py index f517263ed..6d6d54633 100644 --- a/lib/ramble/ramble/test/conftest.py +++ b/lib/ramble/ramble/test/conftest.py @@ -387,11 +387,9 @@ def _factory(name, output, subdir=('bin',)): @pytest.fixture(scope='function') def mutable_mock_workspace_path(tmpdir_factory, mutable_config): """Fixture for mocking the internal ramble workspaces directory.""" - saved_path = ramble.workspace.get_workspace_path() mock_path = tmpdir_factory.mktemp('mock-workspace-path') - ramble.workspace.set_workspace_path(str(mock_path)) - yield mock_path - ramble.workspace.set_workspace_path(saved_path) + with ramble.config.override('config:workspace_dirs', str(mock_path)): + yield mock_path @pytest.fixture diff --git a/lib/ramble/ramble/workspace/__init__.py b/lib/ramble/ramble/workspace/__init__.py index 05859c4f4..f3171906b 100644 --- a/lib/ramble/ramble/workspace/__init__.py +++ b/lib/ramble/ramble/workspace/__init__.py @@ -29,7 +29,6 @@ exists, is_workspace_dir, get_workspace_path, - set_workspace_path, config_file, config_file_name, workspace_software_path, @@ -61,7 +60,6 @@ 'exists', 'is_workspace_dir', 'get_workspace_path', - 'set_workspace_path', 'config_file', 'config_file_name', 'workspace_software_path', diff --git a/lib/ramble/ramble/workspace/workspace.py b/lib/ramble/ramble/workspace/workspace.py index 329b706f8..54b8f75e8 100644 --- a/lib/ramble/ramble/workspace/workspace.py +++ b/lib/ramble/ramble/workspace/workspace.py @@ -286,17 +286,13 @@ def get_workspace_path(): """Returns current directory of ramble-managed workspaces""" path_in_config = ramble.config.get('config:workspace_dirs') if not path_in_config: - path_in_config = '$ramble/var/ramble/GET_WORKSPACE_ERROR/' + # command above should have worked, so if it doesn't, error out: + tty.die('No config:workspace_dirs setting found in configuration!') - wspath = ramble.util.path.canonicalize_path(path_in_config) + wspath = ramble.util.path.canonicalize_path(str(path_in_config)) return wspath -def set_workspace_path(dirname): - """Sets the parent directory of ramble-managed workspaces""" - ramble.config.set('config:workspace_dirs:', dirname) - - def _root(name): """Non-validating version of root(), to be used internally.""" wspath = get_workspace_path()