Skip to content

Commit

Permalink
Merge pull request #837 from linsword13/cleanup
Browse files Browse the repository at this point in the history
Clean up static methods
  • Loading branch information
rfbgo authored Jan 22, 2025
2 parents f02c5d8 + c22aefc commit 1b0e0bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 66 deletions.
7 changes: 0 additions & 7 deletions lib/ramble/ramble/experimental/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,6 @@ def perform_upload(self, uri, results):
# results = query_job.result() # Waits for job to complete.
# return results[0]

def get_experiment_id(experiment):
# get_max_current_id(...) # Warning: dangerous..

# This should be stable per machine/python version, but is not
# guaranteed to be globally stable
return hash(json.dumps(experiment, sort_keys=True))


class PrintOnlyUploader(Uploader):
"""An uploader that only prints out formatted data without actually uploading."""
Expand Down
8 changes: 4 additions & 4 deletions lib/ramble/ramble/test/util/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_env_var_set_command_gen(mutable_mock_apps_repo):

answer = ["export var1=val1;", "export var2=val2;"]

out_cmds, _ = ramble.util.env.Env.get_env_set_commands(tests, set())
out_cmds, _ = ramble.util.env.action_funcs["set"](tests, set())
for cmd in answer:
assert cmd in out_cmds

Expand All @@ -40,7 +40,7 @@ def test_env_var_append_command_gen(mutable_mock_apps_repo):
'export path2="${path2}:path2";',
]

out_cmds, _ = ramble.util.env.Env.get_env_append_commands(tests, set())
out_cmds, _ = ramble.util.env.action_funcs["append"](tests, set())
for cmd in answer:
assert cmd in out_cmds

Expand All @@ -53,7 +53,7 @@ def test_env_var_prepend_command_gen(mutable_mock_apps_repo):

answer = ['export path1="path2:path1:${path1}";', 'export path2="path1:path2:${path2}";']

out_cmds, _ = ramble.util.env.Env.get_env_prepend_commands(tests, set())
out_cmds, _ = ramble.util.env.action_funcs["prepend"](tests, set())
for cmd in answer:
assert cmd in out_cmds

Expand All @@ -63,6 +63,6 @@ def test_env_var_unset_command_gen(mutable_mock_apps_repo):

answer = ["unset var1;", "unset var2;"]

out_cmds, _ = ramble.util.env.Env.get_env_unset_commands(tests, set())
out_cmds, _ = ramble.util.env.action_funcs["unset"](tests, set())
for cmd in answer:
assert cmd in out_cmds
112 changes: 57 additions & 55 deletions lib/ramble/ramble/util/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,84 @@
from ramble.util.shell_utils import get_compatible_base_shell


class Env:
def get_env_set_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
for var, val in var_conf.items():
var_set.add(var)
env_mods.set(var, val)
def _get_env_set_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
for var, val in var_conf.items():
var_set.add(var)
env_mods.set(var, val)

env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)
env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)

return (env_cmds_arr.split("\n"), var_set)
return (env_cmds_arr.split("\n"), var_set)

def get_env_unset_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
for var in var_conf:
if var in var_set:
var_set.remove(var)
env_mods.unset(var)

env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)
def _get_env_unset_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
for var in var_conf:
if var in var_set:
var_set.remove(var)
env_mods.unset(var)

return (env_cmds_arr.split("\n"), var_set)
env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)

def get_env_append_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
return (env_cmds_arr.split("\n"), var_set)

append_funcs = {
"vars": env_mods.append_flags,
"paths": env_mods.append_path,
}

var_set_orig = var_set.copy()
def _get_env_append_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()

for append_group in var_conf:
sep = " "
if "var-separator" in append_group:
sep = append_group["var-separator"]
append_funcs = {
"vars": env_mods.append_flags,
"paths": env_mods.append_path,
}

for group in append_funcs.keys():
if group in append_group.keys():
for var, val in append_group[group].items():
if var not in var_set:
env_mods.set(var, "${%s}" % var)
var_set.add(var)
append_funcs[group](var, val, sep=sep)
var_set_orig = var_set.copy()

env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)
for append_group in var_conf:
sep = " "
if "var-separator" in append_group:
sep = append_group["var-separator"]

return (env_cmds_arr.split("\n"), var_set_orig)
for group in append_funcs.keys():
if group in append_group.keys():
for var, val in append_group[group].items():
if var not in var_set:
env_mods.set(var, "${%s}" % var)
var_set.add(var)
append_funcs[group](var, val, sep=sep)

def get_env_prepend_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()
env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)

prepend_funcs = {
"paths": env_mods.prepend_path,
}
return (env_cmds_arr.split("\n"), var_set_orig)

var_set_orig = var_set.copy()

for prepend_group in var_conf:
for group in prepend_group.keys():
for var, val in prepend_group[group].items():
if var not in var_set:
env_mods.set(var, "${%s}" % var)
var_set.add(var)
prepend_funcs[group](var, val)
def _get_env_prepend_commands(var_conf, var_set, shell="sh"):
env_mods = RambleEnvModifications()

prepend_funcs = {
"paths": env_mods.prepend_path,
}

var_set_orig = var_set.copy()

for prepend_group in var_conf:
for group in prepend_group.keys():
for var, val in prepend_group[group].items():
if var not in var_set:
env_mods.set(var, "${%s}" % var)
var_set.add(var)
prepend_funcs[group](var, val)

env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)
env_cmds_arr = env_mods.shell_modifications(shell=shell, explicit=True)

return (env_cmds_arr.split("\n"), var_set_orig)
return (env_cmds_arr.split("\n"), var_set_orig)


action_funcs = {
"set": Env.get_env_set_commands,
"unset": Env.get_env_unset_commands,
"append": Env.get_env_append_commands,
"prepend": Env.get_env_prepend_commands,
"set": _get_env_set_commands,
"unset": _get_env_unset_commands,
"append": _get_env_append_commands,
"prepend": _get_env_prepend_commands,
}


Expand Down

0 comments on commit 1b0e0bd

Please sign in to comment.