Skip to content

Commit e1f86c8

Browse files
Merge pull request #36 from dodecatheon/configurable-workspace-dir
Allow workspace_path to be set via config:user:workspace_dir
2 parents 53c8c39 + 49a8f19 commit e1f86c8

File tree

12 files changed

+109
-37
lines changed

12 files changed

+109
-37
lines changed

etc/ramble/defaults/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ config:
2424
install: '--reuse'
2525
concretize: '--reuse'
2626
input_cache: $ramble/var/ramble/cache
27+
workspace_dirs: $ramble/var/ramble/workspaces

lib/ramble/ramble/cmd/workspace.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,22 @@ def workspace_activate(args):
106106
# Temporary workspace
107107
if args.temp:
108108
workspace = create_temp_workspace_directory()
109-
workspace_path = os.path.abspath(workspace)
110-
short_name = os.path.basename(workspace_path)
109+
wspath_dir = os.path.abspath(workspace)
110+
ramble.workspace.set_workspace_path(wspath_dir)
111+
short_name = os.path.basename(wspath_dir)
111112
ramble.workspace.Workspace(workspace).write()
112113

113114
# Named workspace
114115
elif ramble.workspace.exists(workspace_name_or_dir) and not args.dir:
115-
workspace_path = ramble.workspace.root(workspace_name_or_dir)
116+
wspath_dir = ramble.workspace.root(workspace_name_or_dir)
117+
ramble.workspace.set_workspace_path(wspath_dir)
116118
short_name = workspace_name_or_dir
117119

118120
# Workspace directory
119121
elif ramble.workspace.is_workspace_dir(workspace_name_or_dir):
120-
workspace_path = os.path.abspath(workspace_name_or_dir)
121-
short_name = os.path.basename(workspace_path)
122+
workspace_path_dir = os.path.abspath(workspace_name_or_dir)
123+
ramble.workspace.set_workspace_path(workspace_path_dir)
124+
short_name = os.path.basename(workspace_path_dir)
122125

123126
else:
124127
tty.die("No such workspace: '%s'" % workspace_name_or_dir)
@@ -134,7 +137,8 @@ def workspace_activate(args):
134137
env_mods = ramble.workspace.shell.deactivate()
135138

136139
# Activate new workspace
137-
active_workspace = ramble.workspace.Workspace(workspace_path)
140+
workspace_path_dir = ramble.workspace.get_workspace_path()
141+
active_workspace = ramble.workspace.Workspace(workspace_path_dir)
138142
cmds += ramble.workspace.shell.activate_header(
139143
ws=active_workspace,
140144
shell=args.shell,

lib/ramble/ramble/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
'install': '--reuse',
119119
'concretize': '--reuse'
120120
},
121-
'input_cache': '$ramble/var/ramble/cache'
121+
'input_cache': '$ramble/var/ramble/cache',
122+
'workspace_dirs': '$ramble/var/ramble/workspaces'
122123
}
123124
}
124125

lib/ramble/ramble/schema/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
'default': '$ramble/var/ramble/cache'
5151
}
5252

53+
properties['config']['workspace_dirs'] = {
54+
'type': 'string',
55+
'default': '$ramble/var/ramble/workspaces'
56+
}
57+
5358
#: Full schema with metadata
5459
schema = {
5560
'$schema': 'http://json-schema.org/schema#',

lib/ramble/ramble/test/cmd/on.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
from ramble.main import RambleCommand
1616

1717
# everything here uses the mock_workspace_path
18-
pytestmark = pytest.mark.usefixtures(
19-
'mutable_mock_workspace_path', 'config', 'mutable_mock_repo')
18+
pytestmark = pytest.mark.usefixtures('mutable_config',
19+
'mutable_mock_workspace_path',
20+
'mutable_mock_repo')
2021

2122
workspace = RambleCommand('workspace')
2223
add = RambleCommand('add')
2324
remove = RambleCommand('remove')
2425
on = RambleCommand('on')
2526

2627

27-
def test_on_command():
28+
def test_on_command(mutable_mock_workspace_path):
2829
ws_name = 'test'
2930
workspace('create', ws_name)
3031

@@ -41,7 +42,7 @@ def test_on_command():
4142
on()
4243

4344

44-
def test_execute_nothing():
45+
def test_execute_nothing(mutable_mock_workspace_path):
4546
ws_name = 'test'
4647
workspace('create', ws_name)
4748
assert ws_name in workspace('list')

lib/ramble/ramble/test/cmd/workspace.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
from ramble.main import RambleCommand, RambleCommandError
1717

1818
# everything here uses the mock_workspace_path
19-
pytestmark = pytest.mark.usefixtures(
20-
'mutable_mock_workspace_path', 'config', 'mutable_mock_repo')
19+
pytestmark = pytest.mark.usefixtures('mutable_config',
20+
'mutable_mock_workspace_path',
21+
'mutable_mock_repo')
2122

2223
config = RambleCommand('config')
2324
workspace = RambleCommand('workspace')
@@ -210,6 +211,39 @@ def test_workspace_from_template(tmpdir):
210211
assert num_templates > 0
211212

212213

214+
def test_workspace_dirs(tmpdir, mutable_mock_workspace_path):
215+
with tmpdir.as_cwd():
216+
# Make a temp directory,
217+
# Set it up as the workspace_dirs path,
218+
# make a test workspace there, and
219+
# verify the workspace was created where
220+
# it would be expected
221+
wsdir1 = os.path.join(os.getcwd(), 'ws1')
222+
os.makedirs(wsdir1)
223+
ramble.workspace.set_workspace_path(wsdir1)
224+
workspace('create', 'test1')
225+
out = workspace('list')
226+
assert 'test1' in out
227+
228+
# Now make a second temp directory,
229+
# follow same process to make another test
230+
# workspace, and verify that the first
231+
# test workspace is not found while the
232+
# second is
233+
wsdir2 = os.path.join(os.getcwd(), 'ws2')
234+
os.makedirs(wsdir2)
235+
ramble.workspace.set_workspace_path(wsdir2)
236+
workspace('create', 'test2')
237+
out = workspace('list')
238+
assert 'test2' in out
239+
assert 'test1' not in out
240+
241+
# Cleanup after test
242+
workspace('remove', '-y', 'test2')
243+
ramble.workspace.set_workspace_path(wsdir1)
244+
workspace('remove', '-y', 'test1')
245+
246+
213247
def test_remove_workspace(capfd):
214248
workspace('create', 'foo')
215249
workspace('create', 'bar')

lib/ramble/ramble/test/conftest.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def pytest_collection_modifyitems(config, items):
6262
#
6363
@pytest.fixture(scope='function', autouse=True)
6464
def no_chdir():
65-
"""Ensure that no test changes Ramble's working dirctory.
65+
"""Ensure that no test changes Ramble's working directory.
6666
6767
This prevents Ramble tests (and therefore Ramble commands) from
6868
changing the working directory and causing other tests to fail
@@ -231,8 +231,11 @@ def mutable_config(tmpdir_factory, configuration_dir):
231231
mutable_dir = tmpdir_factory.mktemp('mutable_config').join('tmp')
232232
configuration_dir.copy(mutable_dir)
233233

234-
scopes = [ramble.config.ConfigScope(name, str(mutable_dir.join(name)))
235-
for name in ['site', 'system', 'user']]
234+
defaults = ramble.config.InternalConfigScope('_builtin',
235+
ramble.config.config_defaults)
236+
scopes = [defaults]
237+
scopes += [ramble.config.ConfigScope(name, str(mutable_dir.join(name)))
238+
for name in ['site', 'system', 'user']]
236239

237240
with ramble.config.use_configuration(*scopes) as cfg:
238241
yield cfg
@@ -381,14 +384,14 @@ def _factory(name, output, subdir=('bin',)):
381384
return _factory
382385

383386

384-
@pytest.fixture()
385-
def mutable_mock_workspace_path(tmpdir_factory):
387+
@pytest.fixture(scope='function')
388+
def mutable_mock_workspace_path(tmpdir_factory, mutable_config):
386389
"""Fixture for mocking the internal ramble workspaces directory."""
387-
saved_path = ramble.workspace.workspace_path
390+
saved_path = ramble.workspace.get_workspace_path()
388391
mock_path = tmpdir_factory.mktemp('mock-workspace-path')
389-
ramble.workspace.workspace.workspace_path = str(mock_path)
392+
ramble.workspace.set_workspace_path(str(mock_path))
390393
yield mock_path
391-
ramble.workspace.workspace.workspace_path = saved_path
394+
ramble.workspace.set_workspace_path(saved_path)
392395

393396

394397
@pytest.fixture

lib/ramble/ramble/test/end_to_end.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from ramble.main import RambleCommand
1616

1717
# everything here uses the mock_workspace_path
18-
pytestmark = pytest.mark.usefixtures(
19-
'mutable_mock_workspace_path', 'config')
18+
pytestmark = pytest.mark.usefixtures('mutable_config',
19+
'mutable_mock_workspace_path')
2020

2121
workspace = RambleCommand('workspace')
2222

2323

24-
def test_wrfv4_dry_run():
24+
def test_wrfv4_dry_run(mutable_config, mutable_mock_workspace_path):
2525
test_config = """
2626
ramble:
2727
mpi:

lib/ramble/ramble/test/expander.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import ramble.expander
1313
from ramble.main import RambleCommand
1414

15-
pytestmark = pytest.mark.usefixtures(
16-
'mutable_mock_workspace_path', 'config', 'mutable_mock_repo')
15+
pytestmark = pytest.mark.usefixtures('mutable_config',
16+
'mutable_mock_workspace_path',
17+
'mutable_mock_repo',
18+
)
1719

1820
workspace = RambleCommand('workspace')
1921
add = RambleCommand('add')

lib/ramble/ramble/test/mirror_tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
pytestmark = [pytest.mark.skipif(sys.platform == "win32",
2525
reason="does not run on windows"),
26-
pytest.mark.usefixtures('mutable_config', 'mutable_mock_repo')]
26+
pytest.mark.usefixtures('tmpdir',
27+
'tmpdir_factory',
28+
'mutable_config',
29+
'mutable_mock_workspace_path',
30+
'mutable_mock_repo')]
2731

2832

2933
class MockFetcher(object):
@@ -86,7 +90,7 @@ def check_mirror(mirror_path, app_name, app_class):
8690
])
8791
def test_mirror_create(tmpdir, mutable_mock_repo,
8892
mutable_mock_workspace_path,
89-
config, app_name, tmpdir_factory):
93+
app_name, tmpdir_factory):
9094

9195
test_config = f"""
9296
ramble:

0 commit comments

Comments
 (0)