Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug introduced by PR #36 #49

Merged
merged 8 commits into from
Feb 27, 2023
16 changes: 6 additions & 10 deletions lib/ramble/ramble/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,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)
Expand All @@ -137,8 +134,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,
Expand Down
17 changes: 6 additions & 11 deletions lib/ramble/ramble/test/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
6 changes: 2 additions & 4 deletions lib/ramble/ramble/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/ramble/ramble/workspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
exists,
is_workspace_dir,
get_workspace_path,
set_workspace_path,
config_file,
config_file_name,
workspace_software_path,
Expand Down Expand Up @@ -61,7 +60,6 @@
'exists',
'is_workspace_dir',
'get_workspace_path',
'set_workspace_path',
'config_file',
'config_file_name',
'workspace_software_path',
Expand Down
10 changes: 3 additions & 7 deletions lib/ramble/ramble/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,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()
Expand Down