Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Jun 7, 2024
1 parent e8f2da7 commit c759218
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 66 deletions.
11 changes: 4 additions & 7 deletions aiida_hyperqueue/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from aiida.cmdline.params import options as core_options
from aiida.cmdline.params import types as core_types

from .root import cmd_root
from .install import cmd_install
from .server import cmd_info, cmd_start, cmd_stop
from .alloc import cmd_list, cmd_add, cmd_remove
from .root import cmd_root # noqa: F401
from .install import cmd_install # noqa: F401
from .server import cmd_info, cmd_start, cmd_stop # noqa: F401
from .alloc import cmd_list, cmd_add, cmd_remove # noqa: F401
2 changes: 2 additions & 0 deletions aiida_hyperqueue/cli/alloc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
import click

from aiida.cmdline.params import options, arguments
from aiida.cmdline.utils import echo

from .root import cmd_root


@cmd_root.group("alloc")
def alloc_group():
"""Commands to configure HQ allocations."""
Expand Down
18 changes: 12 additions & 6 deletions aiida_hyperqueue/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
"--hq-version", type=str, default="0.19.0", help="the hq version will be installed."
)
# TODO: should also support different arch binary??
def cmd_install(computer: orm.Computer, remote_bin_dir: Path, hq_version: str, write_bashrc: bool):
def cmd_install(
computer: orm.Computer, remote_bin_dir: Path, hq_version: str, write_bashrc: bool
):
"""Install the hq binary to the computer through the transport"""

# The minimal hq version we support is 0.13.0, check the minor version
try:
_, minor, _ = hq_version.split('.')
_, minor, _ = hq_version.split(".")
except ValueError as e:
echo.echo_critical(f"Cannot parse the version {hq_version}: {e}")
echo.echo_critical(f"Cannot parse the version {hq_version}: {e}")
else:
if int(minor) < 13:
# `--no-hyper-threading` replace `--cpus=no-ht` from 0.13.0
Expand Down Expand Up @@ -78,9 +80,13 @@ def cmd_install(computer: orm.Computer, remote_bin_dir: Path, hq_version: str, w
# TODO: try not override if the binary exist, put has overwrite=True as default
with computer.get_transport() as transport:
# Get the abs path of remote bin dir
retval, stdout, stderr = transport.exec_command_wait(f"echo {str(remote_bin_dir)}")
if retval !=0:
echo.echo_critical(f"Not able to parse remote bin dir {remote_bin_dir}, exit_code={retval}")
retval, stdout, stderr = transport.exec_command_wait(
f"echo {str(remote_bin_dir)}"
)
if retval != 0:
echo.echo_critical(
f"Not able to parse remote bin dir {remote_bin_dir}, exit_code={retval}"
)
else:
remote_bin_dir = Path(stdout.strip())

Expand Down
28 changes: 20 additions & 8 deletions aiida_hyperqueue/cli/server.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# -*- coding: utf-8 -*-
import click

from aiida.cmdline.utils import echo

from .root import cmd_root
from .params import arguments


@cmd_root.group("server")
def server_group():
"""Commands for interacting with the HQ server."""


@server_group.command("start")
@arguments.COMPUTER()
@click.option("-d", "--domain", required=False, type=click.STRING, help="domain that will attached to the `hostname` of remote.")
@click.option(
"-d",
"--domain",
required=False,
type=click.STRING,
help="domain that will attached to the `hostname` of remote.",
)
def cmd_start(computer, domain: str):
"""Start the HyperQueue server."""

Expand All @@ -32,16 +40,20 @@ def cmd_start(computer, domain: str):
start_command_lst = ["nohup", "hq", "server", "start"]

if domain is not None:
retval, stdout, stderr = transport.exec_command_wait(
"hostname"
)
retval, stdout, stderr = transport.exec_command_wait("hostname")
if retval != 0:
echo.echo_critical(f"unable to get the hostname: {stderr}")
else:
hostname = stdout.strip()
start_command_lst.extend(["--host", f"{hostname}.{domain}"])

start_command_lst.extend(["1>$HOME/.hq-stdout", "2>$HOME/.hq-stderr", "&",])
start_command_lst.extend(
[
"1>$HOME/.hq-stdout",
"2>$HOME/.hq-stderr",
"&",
]
)
start_command = " ".join(start_command_lst)

echo.echo_debug(f"Run start command {start_command} on the remote")
Expand All @@ -58,6 +70,7 @@ def cmd_start(computer, domain: str):

echo.echo_success("HQ server started!")


@server_group.command("stop")
@arguments.COMPUTER()
def cmd_stop(computer):
Expand All @@ -73,15 +86,14 @@ def cmd_stop(computer):
echo.echo_info("Stop the hq server will close all allocs.")

with computer.get_transport() as transport:
retval, _, stderr = transport.exec_command_wait(
"hq server stop"
)
retval, _, stderr = transport.exec_command_wait("hq server stop")

if retval != 0:
echo.echo_critical(f"unable to stop the server: {stderr}")

echo.echo_success("HQ server stopped!")


@server_group.command("restart")
@arguments.COMPUTER()
# TODO: how to pass domain to restart???
Expand Down
14 changes: 5 additions & 9 deletions aiida_hyperqueue/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""Plugin for the HyperQueue meta scheduler.
"""
"""Plugin for the HyperQueue meta scheduler."""

import re
from typing import Union, Optional
import typing as t

from aiida.common.extendeddicts import AttributeDict
from aiida.common.exceptions import FeatureNotAvailable
from aiida.schedulers import Scheduler, SchedulerError
from aiida.schedulers.datastructures import JobInfo, JobState, JobResource, JobTemplate

Expand Down Expand Up @@ -85,8 +83,7 @@ def get_tot_num_mpiprocs(self):


class HyperQueueScheduler(Scheduler):
"""Support for the HyperQueue scheduler (https://it4innovations.github.io/hyperqueue/stable/).
"""
"""Support for the HyperQueue scheduler (https://it4innovations.github.io/hyperqueue/stable/)."""

_logger = Scheduler._logger.getChild("hyperqueue")

Expand Down Expand Up @@ -200,7 +197,7 @@ def _parse_submit_output(self, retval: int, stdout: str, stderr: str) -> str:
)

def _get_joblist_command(
self, jobs: Optional[list] = None, user: Optional[str] = None
self, jobs: t.Optional[list] = None, user: t.Optional[str] = None
) -> str:
"""Return the ``hq`` command for listing the active jobs.
Expand Down Expand Up @@ -247,8 +244,7 @@ def _parse_joblist_output(self, retval: int, stdout: str, stderr: str) -> list:
return job_info_list

def _get_kill_command(self, jobid):
"""Return the command to kill the job with specified jobid.
"""
"""Return the command to kill the job with specified jobid."""
submit_command = f"hq job cancel {jobid}"

self.logger.info(f"killing job {jobid}")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cli_alloc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
import pytest
from click.testing import CliRunner

from aiida.transports.transport import Transport as TransportClass


@pytest.fixture
def runner():
return CliRunner()


original_exec_command_wait = TransportClass.exec_command_wait

# TODO: Not yet implemented, seems hard to just use hq_env
Expand Down
19 changes: 14 additions & 5 deletions tests/test_cli_install.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# -*- coding: utf-8 -*-
import pytest
from click.testing import CliRunner

from aiida_hyperqueue.cli import cmd_install


@pytest.fixture
def runner():
return CliRunner()


def test_install(runner, tmp_path, aiida_computer_ssh):
aiida_computer_ssh(label="localhost-hq")

version = "0.19.0"
result = runner.invoke(cmd_install, ["-p", f"{str(tmp_path.resolve())}", "--hq-version", version, "--no-write-bashrc", "localhost-hq"])
result = runner.invoke(
cmd_install,
[
"-p",
f"{str(tmp_path.resolve())}",
"--hq-version",
version,
"--no-write-bashrc",
"localhost-hq",
],
)

assert result.exit_code == 0
assert f"hq version {version}" in result.output




Loading

0 comments on commit c759218

Please sign in to comment.