Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing and kwarg removals #102

Merged
merged 38 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b83d841
mypy bash files
Christian-B Nov 18, 2024
e11c370
typing
Christian-B Nov 19, 2024
0ff058d
more typing
Christian-B Nov 19, 2024
0d1a9e5
more typing
Christian-B Nov 20, 2024
f7ce523
destroy_job reason is expected in kwargs
Christian-B Nov 21, 2024
90418bb
put argv back in
Christian-B Nov 25, 2024
99f8903
remove timeout from kwargs
Christian-B Nov 25, 2024
c5eea6b
raise ProtocolTimeoutError
Christian-B Nov 25, 2024
8b4296f
typing
Christian-B Nov 25, 2024
da69c92
typing
Christian-B Nov 25, 2024
b38b2c3
put _read_any_str back in
Christian-B Nov 25, 2024
f89f1b9
fixes
Christian-B Nov 25, 2024
c508187
flake8
Christian-B Nov 26, 2024
3559c01
more flake8
Christian-B Nov 26, 2024
b9c9f2b
remove default values
Christian-B Nov 26, 2024
c26d5a8
remove argv
Christian-B Nov 26, 2024
858bc86
better type
Christian-B Nov 26, 2024
401bfc3
tighter typing
Christian-B Nov 26, 2024
3f7cf7c
remove kwargs
Christian-B Nov 26, 2024
15f2d7d
remove unused import
Christian-B Nov 26, 2024
6cf6543
remove unused import
Christian-B Nov 26, 2024
be26a3c
rename config.py to spalloc_config.py
Christian-B Nov 26, 2024
76ca52a
SpallocConfig
Christian-B Nov 26, 2024
fdd75f7
timeout is a float
Christian-B Nov 26, 2024
60d2d79
type fixes
Christian-B Nov 26, 2024
e5e5411
flake8
Christian-B Nov 26, 2024
37394b4
docs
Christian-B Nov 26, 2024
9388795
kwargs last
Christian-B Nov 26, 2024
8ae14ea
kwargs removal
Christian-B Nov 27, 2024
6b5107c
remove timout from job kwargs
Christian-B Nov 27, 2024
bc8fd00
remove another kwarg
Christian-B Nov 27, 2024
2a6f06c
remove more kwarg
Christian-B Nov 27, 2024
3085609
flake8
Christian-B Nov 27, 2024
5e87dd4
pylint fixes
Christian-B Nov 27, 2024
6ad56c7
pass params not kwarg to job
Christian-B Nov 27, 2024
7f0ad52
mypy-full_packages: spalloc_client
Christian-B Nov 27, 2024
62ed8df
better default
Christian-B Nov 27, 2024
6fc8f74
Fix oops in docstring
rowleya Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
coverage-package: spalloc tests
flake8-packages: spalloc_client tests
pylint-packages: spalloc_client
mypy-packages: spalloc_client tests
mypy-packages: tests
mypy-full_packages: spalloc_client
sphinx_directory: docs/source
secrets: inherit

27 changes: 27 additions & 0 deletions mypy.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Copyright (c) 2024 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This bash assumes that other repositories are installed in paralled

# requires the latest mypy
# pip install --upgrade mypy

utils="../SpiNNUtils/spinn_utilities"
machine="../SpiNNMachine/spinn_machine"
man="../SpiNNMan/spinnman"
pacman="../PACMAN/pacman"

mypy --python-version 3.8 $utils $machine $man $pacman spalloc_client tests
28 changes: 28 additions & 0 deletions mypyd.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Copyright (c) 2024 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This bash assumes that other repositories are installed in paralled

# requires the latest mypy
# pip install --upgrade mypy

utils="../SpiNNUtils/spinn_utilities"
machine="../SpiNNMachine/spinn_machine"
man="../SpiNNMan/spinnman"
pacman="../PACMAN/pacman"

mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man $pacman spalloc_client

4 changes: 2 additions & 2 deletions spalloc_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

__all__ = [
"Job", "JobDestroyedError", "JobState", "ProtocolClient",
"ProtocolError", "ProtocolTimeoutError", "SpallocServerException",
"StateChangeTimeoutError"]
"ProtocolError", "ProtocolTimeoutError",
"SpallocServerException", "StateChangeTimeoutError"]
11 changes: 7 additions & 4 deletions spalloc_client/_keepalive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"""
import sys
import threading
from typing import List
from spalloc_client.protocol_client import ProtocolClient, ProtocolTimeoutError


def wait_for_exit(stop_event):
def wait_for_exit(stop_event: threading.Event) -> None:
""" Listens to stdin for a line equal to 'exit' or end-of-file and then\
notifies the given event (that it is time to stop keeping the Spalloc\
job alive).
Expand All @@ -34,8 +35,10 @@ def wait_for_exit(stop_event):
stop_event.set()


def keep_job_alive(hostname, port, job_id, keepalive_period, timeout,
reconnect_delay, stop_event):
def keep_job_alive(
hostname: str, port: int, job_id: int, keepalive_period: float,
timeout: float, reconnect_delay: float,
stop_event: threading.Event) -> None:
""" Keeps a Spalloc job alive. Run as a separate process to the main\
Spalloc client.

Expand Down Expand Up @@ -78,7 +81,7 @@ def keep_job_alive(hostname, port, job_id, keepalive_period, timeout,
client.close()


def _run(argv):
def _run(argv: List[str]) -> None:
print("KEEPALIVE")
sys.stdout.flush()
hostname = argv[1]
Expand Down
15 changes: 11 additions & 4 deletions spalloc_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@

from datetime import datetime
import time
from typing import Optional


def time_left(timestamp):
def time_left_float(timestamp: float) -> float:
""" Convert a not None timestamp into how long to wait for it.
"""
return max(0.0, timestamp - time.time())


def time_left(timestamp: Optional[float]) -> Optional[float]:
""" Convert a timestamp into how long to wait for it.
"""
if timestamp is None:
return None
return max(0.0, timestamp - time.time())


def timed_out(timestamp):
def timed_out(timestamp: Optional[float]) -> bool:
""" Check if a timestamp has been reached.
"""
if timestamp is None:
return False
return timestamp < time.time()


def make_timeout(delay_seconds):
def make_timeout(delay_seconds: Optional[float]) -> Optional[float]:
""" Convert a delay (in seconds) into a timestamp.
"""
if delay_seconds is None:
return None
return time.time() + delay_seconds


def render_timestamp(timestamp) -> str:
def render_timestamp(timestamp: float) -> str:
""" Convert a timestamp (Unix seconds) into a local human-readable\
timestamp string.
"""
Expand Down
Loading
Loading