From 5c89327afc8d52e37132811efbb1d645046d80fe Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Wed, 22 Jul 2026 11:22:46 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20Update=20pre-commit=20hooks?= =?UTF-8?q?=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump the pre-commit hook revisions in .pre-commit-config.yaml and commit the resulting formatting updates across the codebase. --- .github/workflows/update_changelog.py | 2 +- .pre-commit-config.yaml | 9 ++++++--- aiida_hyperqueue/cli/__init__.py | 4 ++-- aiida_hyperqueue/cli/alloc.py | 2 +- aiida_hyperqueue/cli/install.py | 11 ++++++----- aiida_hyperqueue/cli/params/options.py | 1 + aiida_hyperqueue/cli/server.py | 2 +- aiida_hyperqueue/scheduler.py | 4 ++-- docs/source/conf.py | 2 +- tests/conftest.py | 7 +++---- tests/test_cli_install.py | 5 ++--- tests/test_cli_server.py | 9 +++++---- tests/test_scheduler.py | 7 ++++--- tests/utils/__init__.py | 6 +++--- 14 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.github/workflows/update_changelog.py b/.github/workflows/update_changelog.py index d2cadf5..fdfc538 100644 --- a/.github/workflows/update_changelog.py +++ b/.github/workflows/update_changelog.py @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- """Script for automatically updating the `CHANGELOG.md` based on the commits since the latest release tag.""" -from pathlib import Path import re import subprocess +from pathlib import Path DEFAULT_CHANGELOG_SECTIONS = """ ### ‼️ Breaking changes diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3fae56..7ba7eda 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,17 +1,20 @@ # Install pre-commit hooks via: # pre-commit install +default_language_version: + python: python3.11 + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - - id: fix-encoding-pragma - id: mixed-line-ending - id: trailing-whitespace - id: check-json - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.5 + rev: v0.8.6 hooks: - id: ruff-format - id: ruff + args: [--fix] diff --git a/aiida_hyperqueue/cli/__init__.py b/aiida_hyperqueue/cli/__init__.py index 61ba344..171f24e 100644 --- a/aiida_hyperqueue/cli/__init__.py +++ b/aiida_hyperqueue/cli/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from .root import cmd_root # noqa: F401 +from .alloc import cmd_add, cmd_list, cmd_remove # noqa: F401 from .install import cmd_install # noqa: F401 +from .root import cmd_root # noqa: F401 from .server import cmd_info, cmd_start, cmd_stop # noqa: F401 -from .alloc import cmd_list, cmd_add, cmd_remove # noqa: F401 diff --git a/aiida_hyperqueue/cli/alloc.py b/aiida_hyperqueue/cli/alloc.py index 7bf218f..f8c3823 100644 --- a/aiida_hyperqueue/cli/alloc.py +++ b/aiida_hyperqueue/cli/alloc.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import click -from aiida.cmdline.params import options, arguments +from aiida.cmdline.params import arguments, options from aiida.cmdline.utils import echo from .root import cmd_root diff --git a/aiida_hyperqueue/cli/install.py b/aiida_hyperqueue/cli/install.py index 0e049fb..676f2f6 100644 --- a/aiida_hyperqueue/cli/install.py +++ b/aiida_hyperqueue/cli/install.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -import click -import tempfile -import requests import tarfile +import tempfile from pathlib import Path +import click +import requests + from aiida import orm from aiida.cmdline.utils import echo @@ -81,7 +82,7 @@ def cmd_install( 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)}" + f"echo {remote_bin_dir!s}" ) if retval != 0: echo.echo_critical( @@ -102,7 +103,7 @@ def cmd_install( ) # XXX: should transport.put take care of this already?? - transport.exec_command_wait(f"chmod +x {str(remote_bin_dir / 'hq')}") + transport.exec_command_wait(f"chmod +x {remote_bin_dir / 'hq'!s}") # write to bashrc if write_bashrc: diff --git a/aiida_hyperqueue/cli/params/options.py b/aiida_hyperqueue/cli/params/options.py index 3f773be..8f9e422 100644 --- a/aiida_hyperqueue/cli/params/options.py +++ b/aiida_hyperqueue/cli/params/options.py @@ -4,6 +4,7 @@ import functools import click + from aiida.cmdline.params import options as core_options from aiida.cmdline.params import types as core_types diff --git a/aiida_hyperqueue/cli/server.py b/aiida_hyperqueue/cli/server.py index 7f2fae3..1e58ef8 100644 --- a/aiida_hyperqueue/cli/server.py +++ b/aiida_hyperqueue/cli/server.py @@ -3,8 +3,8 @@ from aiida.cmdline.utils import echo -from .root import cmd_root from .params import arguments +from .root import cmd_root @cmd_root.group("server") diff --git a/aiida_hyperqueue/scheduler.py b/aiida_hyperqueue/scheduler.py index 6c58005..97e77c8 100644 --- a/aiida_hyperqueue/scheduler.py +++ b/aiida_hyperqueue/scheduler.py @@ -14,8 +14,8 @@ import warnings from aiida.common.extendeddicts import AttributeDict -from aiida.schedulers import Scheduler, SchedulerError, BashCliScheduler -from aiida.schedulers.datastructures import JobInfo, JobState, JobResource, JobTemplate +from aiida.schedulers import BashCliScheduler, Scheduler, SchedulerError +from aiida.schedulers.datastructures import JobInfo, JobResource, JobState, JobTemplate # Mapping of HyperQueue states to AiiDA `JobState`s _MAP_STATUS_HYPERQUEUE = { diff --git a/docs/source/conf.py b/docs/source/conf.py index fc44ccd..754a30b 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -14,10 +14,10 @@ import time import aiida_hyperqueue + from aiida import load_profile from aiida.storage.sqlite_temp import SqliteTempBackend - # -- AiiDA-related setup -------------------------------------------------- temp_profile = SqliteTempBackend.create_profile("temp-profile") load_profile(temp_profile, allow_switch=True) diff --git a/tests/conftest.py b/tests/conftest.py index 15069d9..8dc53b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,8 @@ import subprocess import time from dataclasses import dataclass -from typing import Iterable, List, Optional, Tuple from pathlib import Path +from typing import Iterable, List, Optional, Tuple import pytest @@ -32,7 +32,7 @@ def pytest_sessionstart(session): hq_version = os.environ.get("HQ_VERSION", "v0.19.0") install_command = f"wget -qO- https://github.com/It4innovations/hyperqueue/releases/download/{hq_version}/hq-{hq_version}-linux-x64.tar.gz | tar xvz -C {BIN_DIR.resolve()}" print(install_command) - result = subprocess.run(install_command, shell=True) + result = subprocess.run(install_command, shell=True, check=False) if result.returncode != 0: raise Exception(f"Installation failed with return code {result.returncode}") @@ -132,8 +132,7 @@ def kill_process(self, name: str, signal: int = signal.SIGTERM) -> subprocess.Po if p.process.returncode is None and not p.process.poll(): os.killpg(os.getpgid(p.process.pid), signal) return p.process - else: - raise Exception("Process not found") + raise Exception("Process not found") def sort_processes_for_kill(self): pass diff --git a/tests/test_cli_install.py b/tests/test_cli_install.py index 25b7c93..29d8198 100644 --- a/tests/test_cli_install.py +++ b/tests/test_cli_install.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- import pytest -from click.testing import CliRunner - from aiida_hyperqueue.cli import cmd_install +from click.testing import CliRunner @pytest.fixture @@ -18,7 +17,7 @@ def test_install(runner, tmp_path, aiida_computer_local): cmd_install, [ "-p", - f"{str(tmp_path.resolve())}", + f"{tmp_path.resolve()!s}", "--hq-version", version, "--no-write-bashrc", diff --git a/tests/test_cli_server.py b/tests/test_cli_server.py index 1f62fe4..894bfbc 100644 --- a/tests/test_cli_server.py +++ b/tests/test_cli_server.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -import pytest import time + +import pytest +from aiida_hyperqueue.cli import cmd_info, cmd_start, cmd_stop from click.testing import CliRunner from aiida.transports.transport import Transport as TransportClass -from aiida_hyperqueue.cli import cmd_info, cmd_start, cmd_stop from .conftest import HqEnv, get_hq_binary @@ -57,11 +58,11 @@ def _mock_exec_command_wait(obj, command: str, **kwargs): cmd_list = command.split(" ") if command.startswith("hq"): # `hq` command = " ".join( - [f"{hq}", "--server-dir", f"{str(tmp_path.resolve())}"] + cmd_list[1:] + [f"{hq}", "--server-dir", f"{tmp_path.resolve()!s}"] + cmd_list[1:] ) elif command.startswith("nohup hq"): # `nohup hq` command = " ".join( - [f"nohup {hq}", "--server-dir", f"{str(tmp_path.resolve())}"] + [f"nohup {hq}", "--server-dir", f"{tmp_path.resolve()!s}"] + cmd_list[2:] ) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index b5c47c2..adc142e 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- """Tests for command line interface.""" -import pytest import uuid from pathlib import Path -from aiida.schedulers import JobState +import pytest +from aiida_hyperqueue.scheduler import HyperQueueJobResource, HyperQueueScheduler + from aiida.common.datastructures import CodeRunMode +from aiida.schedulers import JobState from aiida.schedulers.datastructures import JobTemplate, JobTemplateCodeInfo -from aiida_hyperqueue.scheduler import HyperQueueJobResource, HyperQueueScheduler from .conftest import HqEnv from .utils import wait_for_job_state diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index a7c557a..e4458ac 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -3,9 +3,9 @@ from .wait import wait_for_job_state, wait_for_worker_state __all__ = [ - "wait_for_job_state", - "wait_for_worker_state", + "JOB_TABLE_ROWS", "parse_table", "parse_tables", - "JOB_TABLE_ROWS", + "wait_for_job_state", + "wait_for_worker_state", ] From 8a66ccb4f04be25b369fb0ba2b0f298378b97431 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Wed, 22 Jul 2026 11:42:31 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=AA=20Test=203.14=20in=20CI=20(#50?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b019d9e..0a2a1f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: timeout-minutes: 30 strategy: matrix: - python-version: ["3.10"] + python-version: ["3.10", "3.14"] steps: - uses: actions/checkout@v3 From 7fb25ccdc82465ba186db398b3830a735a8765cc Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Wed, 22 Jul 2026 12:19:13 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Drop=20support=20Pytho?= =?UTF-8?q?n=203.9=20pyupgrade=20code=20to=203.10=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run in addition `pyupgrade --py310-plus` --- .github/workflows/update_changelog.py | 1 - .github/workflows/validate_release_tag.py | 1 - aiida_hyperqueue/__init__.py | 1 - aiida_hyperqueue/cli/__init__.py | 1 - aiida_hyperqueue/cli/alloc.py | 1 - aiida_hyperqueue/cli/install.py | 1 - aiida_hyperqueue/cli/params/arguments.py | 1 - aiida_hyperqueue/cli/params/options.py | 1 - aiida_hyperqueue/cli/root.py | 1 - aiida_hyperqueue/cli/server.py | 1 - aiida_hyperqueue/scheduler.py | 1 - docs/source/conf.py | 3 +-- pyproject.toml | 2 +- tests/__init__.py | 1 - tests/conftest.py | 13 ++++++------- tests/test_cli_alloc.py | 1 - tests/test_cli_install.py | 1 - tests/test_cli_server.py | 1 - tests/test_scheduler.py | 1 - tests/utils/__init__.py | 1 - tests/utils/cmd.py | 8 ++------ tests/utils/io.py | 1 - tests/utils/job.py | 6 ++---- tests/utils/mock.py | 4 +--- tests/utils/table.py | 13 +++++-------- tests/utils/wait.py | 16 +++++++--------- 26 files changed, 25 insertions(+), 58 deletions(-) diff --git a/.github/workflows/update_changelog.py b/.github/workflows/update_changelog.py index fdfc538..b35a3a0 100644 --- a/.github/workflows/update_changelog.py +++ b/.github/workflows/update_changelog.py @@ -1,5 +1,4 @@ #!/bin/bash -# -*- coding: utf-8 -*- """Script for automatically updating the `CHANGELOG.md` based on the commits since the latest release tag.""" import re diff --git a/.github/workflows/validate_release_tag.py b/.github/workflows/validate_release_tag.py index 5efafac..7b39fab 100644 --- a/.github/workflows/validate_release_tag.py +++ b/.github/workflows/validate_release_tag.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Validate that the version in the tag label matches the version of the package.""" import argparse diff --git a/aiida_hyperqueue/__init__.py b/aiida_hyperqueue/__init__.py index 8a9664e..a415510 100644 --- a/aiida_hyperqueue/__init__.py +++ b/aiida_hyperqueue/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ aiida_hyperqueue diff --git a/aiida_hyperqueue/cli/__init__.py b/aiida_hyperqueue/cli/__init__.py index 171f24e..c6311a4 100644 --- a/aiida_hyperqueue/cli/__init__.py +++ b/aiida_hyperqueue/cli/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .alloc import cmd_add, cmd_list, cmd_remove # noqa: F401 from .install import cmd_install # noqa: F401 from .root import cmd_root # noqa: F401 diff --git a/aiida_hyperqueue/cli/alloc.py b/aiida_hyperqueue/cli/alloc.py index f8c3823..ee25c45 100644 --- a/aiida_hyperqueue/cli/alloc.py +++ b/aiida_hyperqueue/cli/alloc.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import click from aiida.cmdline.params import arguments, options diff --git a/aiida_hyperqueue/cli/install.py b/aiida_hyperqueue/cli/install.py index 676f2f6..956c8d1 100644 --- a/aiida_hyperqueue/cli/install.py +++ b/aiida_hyperqueue/cli/install.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import tarfile import tempfile from pathlib import Path diff --git a/aiida_hyperqueue/cli/params/arguments.py b/aiida_hyperqueue/cli/params/arguments.py index cf140e3..d28d569 100644 --- a/aiida_hyperqueue/cli/params/arguments.py +++ b/aiida_hyperqueue/cli/params/arguments.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from aiida.cmdline.params import arguments as core_arguments COMPUTER = core_arguments.COMPUTER diff --git a/aiida_hyperqueue/cli/params/options.py b/aiida_hyperqueue/cli/params/options.py index 8f9e422..7fba411 100644 --- a/aiida_hyperqueue/cli/params/options.py +++ b/aiida_hyperqueue/cli/params/options.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Reusable options for CLI commands.""" import functools diff --git a/aiida_hyperqueue/cli/root.py b/aiida_hyperqueue/cli/root.py index 7341882..d277015 100644 --- a/aiida_hyperqueue/cli/root.py +++ b/aiida_hyperqueue/cli/root.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Command line interface `aiida-hq` for aiida-hyperqueue. The CLI implementation prototype from `aiida-pseudo`. """ diff --git a/aiida_hyperqueue/cli/server.py b/aiida_hyperqueue/cli/server.py index 1e58ef8..0d3cdf8 100644 --- a/aiida_hyperqueue/cli/server.py +++ b/aiida_hyperqueue/cli/server.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import click from aiida.cmdline.utils import echo diff --git a/aiida_hyperqueue/scheduler.py b/aiida_hyperqueue/scheduler.py index 97e77c8..e1feca4 100644 --- a/aiida_hyperqueue/scheduler.py +++ b/aiida_hyperqueue/scheduler.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ########################################################################### # Copyright (c), The AiiDA team. All rights reserved. # # This file is part of the AiiDA code. # diff --git a/docs/source/conf.py b/docs/source/conf.py index 754a30b..325fb46 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Sphinx configuration for aiida-hyperqueue # @@ -69,7 +68,7 @@ copyright_year_string = ( current_year if current_year == copyright_first_year - else "{}-{}".format(copyright_first_year, current_year) + else f"{copyright_first_year}-{current_year}" ) # pylint: disable=redefined-builtin copyright = "{}, {}. All rights reserved".format( diff --git a/pyproject.toml b/pyproject.toml index 7bf417f..3c046f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ classifiers = [ "Natural Language :: English", "Programming Language :: Python", ] -requires-python = ">=3.9" +requires-python = ">=3.10" dependencies = [ "aiida-core~=2.7", diff --git a/tests/__init__.py b/tests/__init__.py index 7015e81..484b467 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Tests for the plugin. Includes both tests written in unittest style (test_cli.py) and tests written diff --git a/tests/conftest.py b/tests/conftest.py index 8dc53b5..8a20c34 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import contextlib import json import os @@ -7,7 +6,7 @@ import time from dataclasses import dataclass from pathlib import Path -from typing import Iterable, List, Optional, Tuple +from collections.abc import Iterable import pytest @@ -120,7 +119,7 @@ def kill_all(self): if p.final_check: raise e - def get_processes_by_name(self, name: str) -> Iterable[Tuple[int, ManagedProcess]]: + def get_processes_by_name(self, name: str) -> Iterable[tuple[int, ManagedProcess]]: for i, p in enumerate(self.processes): if p.name == name: yield i, p @@ -191,7 +190,7 @@ def start_server( self.check_running_processes() return process - def start_workers(self, count, **kwargs) -> List[subprocess.Popen]: + def start_workers(self, count, **kwargs) -> list[subprocess.Popen]: workers = [] for _ in range(count): workers.append(self.start_worker(**kwargs)) @@ -207,7 +206,7 @@ def start_worker( wait_for_start=True, on_server_lost="stop", server_dir=None, - work_dir: Optional[str] = None, + work_dir: str | None = None, final_check: bool = False, hostname=None, ) -> subprocess.Popen: @@ -273,7 +272,7 @@ def kill_worker(self, worker_id: int, signal: int = signal.SIGTERM, wait=True): if wait: wait_until(lambda: process.poll() is not None) - def find_process_by_pid(self, pid: int) -> Optional[ManagedProcess]: + def find_process_by_pid(self, pid: int) -> ManagedProcess | None: for p in self.processes: if p.process.pid == pid: return p @@ -293,7 +292,7 @@ def command( ignore_stderr=False, env=None, use_server_dir=True, - cmd_prefix: Optional[List[str]] = None, + cmd_prefix: list[str] | None = None, ): cmd_prefix = cmd_prefix if cmd_prefix is not None else [] if isinstance(args, str): diff --git a/tests/test_cli_alloc.py b/tests/test_cli_alloc.py index 2730bf8..2d7b4ed 100644 --- a/tests/test_cli_alloc.py +++ b/tests/test_cli_alloc.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import pytest from click.testing import CliRunner diff --git a/tests/test_cli_install.py b/tests/test_cli_install.py index 29d8198..8a8c371 100644 --- a/tests/test_cli_install.py +++ b/tests/test_cli_install.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import pytest from aiida_hyperqueue.cli import cmd_install from click.testing import CliRunner diff --git a/tests/test_cli_server.py b/tests/test_cli_server.py index 894bfbc..8155d07 100644 --- a/tests/test_cli_server.py +++ b/tests/test_cli_server.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import time import pytest diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index adc142e..afe0c6d 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Tests for command line interface.""" import uuid diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index e4458ac..92f92ca 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from .table import JOB_TABLE_ROWS, parse_table, parse_tables from .wait import wait_for_job_state, wait_for_worker_state diff --git a/tests/utils/cmd.py b/tests/utils/cmd.py index 7794397..ec6a78c 100644 --- a/tests/utils/cmd.py +++ b/tests/utils/cmd.py @@ -1,15 +1,11 @@ -# -*- coding: utf-8 -*- -from typing import List - - -def python(command: str) -> List[str]: +def python(command: str) -> list[str]: """ Returns commands that will run the specified command as a Python script. """ return ["python3", "-c", command] -def bash(command: str) -> List[str]: +def bash(command: str) -> list[str]: """ Returns commands that will run in a bash script. """ diff --git a/tests/utils/io.py b/tests/utils/io.py index f5b0e9e..47161be 100644 --- a/tests/utils/io.py +++ b/tests/utils/io.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import socket from contextlib import closing diff --git a/tests/utils/job.py b/tests/utils/job.py index d24fa40..2a58a1e 100644 --- a/tests/utils/job.py +++ b/tests/utils/job.py @@ -1,19 +1,17 @@ -# -*- coding: utf-8 -*- import os -from typing import List, Optional from ..conftest import HqEnv from .table import Table def default_task_output( - job_id=1, task_id=0, type="stdout", working_dir: Optional[str] = None + job_id=1, task_id=0, type="stdout", working_dir: str | None = None ) -> str: working_dir = working_dir if working_dir else os.getcwd() return f"{working_dir}/job-{job_id}/{task_id}.{type}" -def list_jobs(hq_env: HqEnv, all=True, filters: List[str] = None) -> Table: +def list_jobs(hq_env: HqEnv, all=True, filters: list[str] = None) -> Table: args = ["job", "list"] if all: assert filters is None diff --git a/tests/utils/mock.py b/tests/utils/mock.py index 4371cdf..cd20ec3 100644 --- a/tests/utils/mock.py +++ b/tests/utils/mock.py @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- import contextlib import os import sys from pathlib import Path -from typing import Dict class ProgramMock: @@ -11,7 +9,7 @@ def __init__(self, directory: str): self.directory = Path(os.path.abspath(directory)) os.makedirs(self.directory, exist_ok=True) - def update_env(self, env: Dict[str, str]): + def update_env(self, env: dict[str, str]): path = str(self.directory) if "PATH" in env: path += f":{env['PATH']}" diff --git a/tests/utils/table.py b/tests/utils/table.py index e89526a..2b3e324 100644 --- a/tests/utils/table.py +++ b/tests/utils/table.py @@ -1,11 +1,8 @@ -# -*- coding: utf-8 -*- -from typing import Dict, List, Optional - JOB_TABLE_ROWS = 16 class Table: - def __init__(self, rows: List[List[str]], header: Optional[List[str]]): + def __init__(self, rows: list[list[str]], header: list[str] | None): self.rows = rows self.header = header @@ -23,7 +20,7 @@ def as_horizontal(self) -> "Table": assert self.rows return Table(self.rows[1:], self.rows[0]) - def get_row_value(self, key) -> Optional[str]: + def get_row_value(self, key) -> str | None: """ Assumes vertical table (each value has a separate row). """ @@ -39,7 +36,7 @@ def check_row_value(self, key: str, value: str): raise Exception(f"Key `{key!r}` not found in\n{self}") assert row == value - def get_column_value(self, key: str) -> Optional[List[str]]: + def get_column_value(self, key: str) -> list[str] | None: """ Assumes horizontal table (each value has a separate column). """ @@ -58,7 +55,7 @@ def check_column_value(self, key: str, index: int, value: str): row = column[index] assert row == value - def check_columns_value(self, keys: List[str], index: int, values: List[str]): + def check_columns_value(self, keys: list[str], index: int, values: list[str]): assert len(keys) == len(values) for key, val in zip(keys, values): self.check_column_value(key, index, val) @@ -146,6 +143,6 @@ def parse_tables(table_string: str): return tables -def parse_multiline_cell(cell: str) -> Dict[str, str]: +def parse_multiline_cell(cell: str) -> dict[str, str]: lines = cell.splitlines(keepends=False) return dict(line.split(": ") for line in lines) diff --git a/tests/utils/wait.py b/tests/utils/wait.py index 400f645..dc1a8d3 100644 --- a/tests/utils/wait.py +++ b/tests/utils/wait.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- import time -from typing import List, Union import psutil @@ -24,21 +22,21 @@ def wait_until(fn, sleep_s=0.2, timeout_s=DEFAULT_TIMEOUT): def wait_for_state( env, - ids: Union[int, List[int]], - target_states: Union[str, List[str]], - commands: List[str], + ids: int | list[int], + target_states: str | list[str], + commands: list[str], state_index: int, **kwargs, ): if isinstance(ids, int): ids = {str(ids)} else: - ids = set(str(id) for id in ids) + ids = {str(id) for id in ids} if isinstance(target_states, str): target_states = {target_states.lower()} else: - target_states = set(state.lower() for state in target_states) + target_states = {state.lower() for state in target_states} last_table = None @@ -61,13 +59,13 @@ def check(): def wait_for_job_state( - env, ids: Union[int, List[int]], target_states: Union[str, List[str]], **kwargs + env, ids: int | list[int], target_states: str | list[str], **kwargs ): wait_for_state(env, ids, target_states, ["job", "list", "--all"], 2, **kwargs) def wait_for_worker_state( - env, ids: Union[int, List[int]], target_states: Union[str, List[str]], **kwargs + env, ids: int | list[int], target_states: str | list[str], **kwargs ): wait_for_state(env, ids, target_states, ["worker", "list", "--all"], 1, **kwargs)