Skip to content

Commit

Permalink
CHORES: pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d-krupke committed Feb 25, 2024
1 parent 10c767e commit a98ee43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
36 changes: 26 additions & 10 deletions src/slurminade/check.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import click
import tempfile
import socket
import tempfile
import time
from pathlib import Path

from .dispatcher import set_dispatcher
import click

from .conf import update_default_configuration
from .function_map import set_entry_point
from .dispatcher import set_dispatcher
from .function import slurmify
from .function_map import set_entry_point


@slurmify()
def _write_to_file(path, content):
# get hostname and write it to the file
hostname = socket.gethostname()
with open(path, "w") as file:
file.write(content+"\n"+hostname)
file.write(content + "\n" + hostname)
# wait a second for the file to be written
time.sleep(1)


@click.command()
@click.option("--partition", default=None, help="The partition to use.")
@click.option("--constraint", default=None, help="The constraint to use.")
Expand All @@ -27,6 +30,7 @@ def check_slurm(partition, constraint):
"""
# enforce slurm
from .dispatcher import SlurmDispatcher

set_dispatcher(SlurmDispatcher())
set_entry_point(__file__)

Expand All @@ -41,10 +45,16 @@ def check_slurm(partition, constraint):
tmp_file_path = tmpdir + "/check_1.txt"
_write_to_file.distribute_and_wait(tmp_file_path, "test")
if not Path(tmp_file_path).exists():
raise Exception("Slurminade failed: The file was not written to the temporary directory.")
msg = "Slurminade failed: The file was not written to the temporary directory."
raise Exception(
msg
)
with open(tmp_file_path) as file:
content = file.readlines()
print("Slurminade check 1 successful. Test was run on node ", content[1].strip())
print(
"Slurminade check 1 successful. Test was run on node ",
content[1].strip(),
)

# Check 2
tmp_file_path = tmpdir + "/check_2.txt"
Expand All @@ -55,11 +65,17 @@ def check_slurm(partition, constraint):
break
time.sleep(1)
if not Path(tmp_file_path).exists():
raise Exception("Slurminade failed: The file was not written to the temporary directory.")
msg = "Slurminade failed: The file was not written to the temporary directory."
raise Exception(
msg
)
with open(tmp_file_path) as file:
content = file.readlines()
print("Slurminade check 2 successful. Test was run on node ", content[1].strip())
print(
"Slurminade check 2 successful. Test was run on node ",
content[1].strip(),
)


if __name__ == "__main__":
check_slurm()
check_slurm()
6 changes: 4 additions & 2 deletions src/slurminade/execute_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
The commands that can be understood by execute.py
"""

from .function_call import FunctionCall
import json
import logging
import os
Expand All @@ -13,6 +12,9 @@
from pathlib import Path
from tempfile import mkstemp

from .function_call import FunctionCall


def create_slurminade_command(
entry_point: Path, funcs: typing.Iterable[FunctionCall], max_arg_length: int
) -> str:
Expand Down Expand Up @@ -62,4 +64,4 @@ def call_slurminade_to_get_function_ids(entry_point: Path) -> typing.Set[str]:
]
out = subprocess.check_output(cmd).decode()
ids = json.loads(out)
return set(ids)
return set(ids)
4 changes: 2 additions & 2 deletions src/slurminade/function_call.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import typing


class FunctionCall:
"""
A function call to be dispatched.
Expand Down Expand Up @@ -35,4 +35,4 @@ def arg_to_str(arg):
if len(short_kwargs) > 200:
short_kwargs = short_kwargs[:200] + "..."
args = ", ".join(a for a in [short_args, short_kwargs] if a)
return f"{self.func_id.split(':')[-1]}({args})"
return f"{self.func_id.split(':')[-1]}({args})"

0 comments on commit a98ee43

Please sign in to comment.