Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jul 12, 2024
2 parents c7d9870 + 25f5d08 commit 531ccf7
Show file tree
Hide file tree
Showing 26 changed files with 556 additions and 332 deletions.
82 changes: 12 additions & 70 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,76 +15,18 @@
# This workflow will install Python dependencies, run tests, lint and rat with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python Build
name: Python Actions
on: [push]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
call:
uses: SpiNNakerManchester/SupportScripts/.github/workflows/python_checks.yml@main
with:
dependencies: SpiNNUtils
test_directories: tests
coverage-package: spalloc tests
flake8-packages: spalloc_client tests
pylint-packages: spalloc_client
mypy-packages: spalloc_client tests
sphinx_directory: docs/source
secrets: inherit

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Checkout
uses: actions/checkout@v4

- name: Checkout SupportScripts
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support

- name: Install pip, etc
uses: ./support/actions/python-tools

- name: Install Spinnaker Dependencies
uses: ./support/actions/install-spinn-deps
with:
repositories: SpiNNUtils
install: true

- name: Install
uses: ./support/actions/run-install

- name: Docs requirements Install
run: pip install -r requirements-docs.txt

- name: Test with pytest
uses: ./support/actions/pytest
with:
tests: tests
options: --durations=10 --timeout=120
coverage: ${{ matrix.python-version == 3.12 }}
cover-packages: spalloc tests
coveralls-token: ${{ secrets.GITHUB_TOKEN }}

- name: Lint with flake8
run: flake8 spalloc_client tests

- name: Lint with pylint
uses: ./support/actions/pylint
with:
package: spalloc_client
exitcheck: 39

- name: Run rat copyright enforcement
if: matrix.python-version == 3.12
uses: ./support/actions/check-copyrights
with:
config_file: rat_asl20.xml

- name: Build documentation with sphinx
if: matrix.python-version == 3.12
uses: ./support/actions/sphinx
with:
directory: docs/source

- name: Validate CITATION.cff
if: matrix.python-version == 3.12
uses: dieghernan/cff-validator@main
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test =
# pytest will be brought in by pytest-cov
pytest-cov
mock
types-appdirs

[options.entry_points]
console_scripts =
Expand Down
2 changes: 1 addition & 1 deletion spalloc_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def make_timeout(delay_seconds):
return time.time() + delay_seconds


def render_timestamp(timestamp):
def render_timestamp(timestamp) -> str:
""" Convert a timestamp (Unix seconds) into a local human-readable\
timestamp string.
"""
Expand Down
15 changes: 10 additions & 5 deletions spalloc_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=wrong-spelling-in-docstring
""" The spalloc command-line tool and Python library determine their default
configuration options from a spalloc configuration file if present.
Expand Down Expand Up @@ -62,7 +63,7 @@
The name of a specific machine on which to run all jobs or None to use any
available machine. (Default: None)
``tags``
The set of tags, comma seperated, to require a machine to have when
The set of tags, comma separated, to require a machine to have when
allocating jobs. (Default: default)
``min_ratio``
Require that when allocating a number of boards the allocation is at least
Expand All @@ -78,17 +79,19 @@
requires the allocation of a whole machine. If False, wrap-around links may
or may-not be present in allocated machines. (Default: False)
"""
import configparser
import os.path
from typing import Any, Dict, List, Optional

import appdirs
import configparser

# The application name to use in config file names
_name = "spalloc"

# Standard config file names/locations
SYSTEM_CONFIG_FILE = appdirs.site_config_dir(_name)
USER_CONFIG_FILE = appdirs.user_config_dir(_name)
CWD_CONFIG_FILE = os.path.join(os.curdir, ".{}".format(_name))
CWD_CONFIG_FILE = os.path.join(os.curdir, f".{_name}")

# Search path for config files (lowest to highest priority)
SEARCH_PATH = [
Expand All @@ -97,12 +100,14 @@
CWD_CONFIG_FILE,
]

TIMEOUT = 10.0

SECTION = "spalloc"
DEFAULT_CONFIG = {
"port": "22244",
"keepalive": "60.0",
"reconnect_delay": "5.0",
"timeout": "5.0",
"timeout": str(TIMEOUT),
"machine": "None",
"tags": "None",
"min_ratio": "0.333",
Expand Down Expand Up @@ -137,7 +142,7 @@ def _read_none_or_str(parser, option):
return parser.get(SECTION, option)


def read_config(filenames=None):
def read_config(filenames: Optional[List[str]] = None) -> Dict[str, Any]:
""" Attempt to read local configuration files to determine spalloc client
settings.
Expand Down
29 changes: 16 additions & 13 deletions spalloc_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# 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.
from spalloc_client.scripts.support import (
VERSION_RANGE_START, VERSION_RANGE_STOP)

# A high-level Python interface for allocating SpiNNaker boards.

Expand All @@ -21,13 +19,18 @@
import subprocess
import time
import sys

from spalloc_client.scripts.support import (
VERSION_RANGE_START, VERSION_RANGE_STOP)

from .protocol_client import ProtocolClient, ProtocolTimeoutError
from .config import read_config, SEARCH_PATH
from .states import JobState
from ._utils import time_left, timed_out, make_timeout

logger = logging.getLogger(__name__)

# pylint: disable=wrong-spelling-in-docstring
# In Python 2, no default handler exists for software which doesn't configure
# its own logging so we must add one ourselves as per
# https://docs.python.org/3.1/library/logging.html#configuring-logging-for-a-library
Expand Down Expand Up @@ -267,11 +270,14 @@ def __init__(self, *args, **kwargs):
job_state = self._get_state()
if (job_state.state == JobState.unknown or
job_state.state == JobState.destroyed):
raise JobDestroyedError("Job {} does not exist: {}{}{}".format(
resume_job_id,
job_state.state.name,
": " if job_state.reason is not None else "",
job_state.reason if job_state.reason is not None else ""))
if job_state.reason is not None:
reason = job_state.reason
else:
reason = ""
raise JobDestroyedError(
f"Job {resume_job_id} does not exist: "
f"{job_state.state.name}"
f"{': ' if job_state.reason is not None else ''}{reason}")

# Snag the keepalive interval from the job
self._keepalive = job_state.keepalive
Expand Down Expand Up @@ -363,8 +369,7 @@ def _assert_compatible_version(self):
if not (VERSION_RANGE_START <= v_ints < VERSION_RANGE_STOP):
self._client.close()
raise ValueError(
"Server version {} is not compatible with this client.".format(
v))
f"Server version {v} is not compatible with this client.")

def _reconnect(self):
""" Reconnect to the server and check version.
Expand Down Expand Up @@ -758,8 +763,7 @@ class _JobStateTuple(namedtuple("_JobStateTuple",
reason the job was terminated.
"""

# Python 3.4 Workaround: https://bugs.python.org/issue24931
__slots__ = tuple()
__slots__ = ()


class _JobMachineInfoTuple(namedtuple("_JobMachineInfoTuple",
Expand All @@ -786,5 +790,4 @@ class _JobMachineInfoTuple(namedtuple("_JobMachineInfoTuple",
None if none allocated yet.
"""

# Python 3.4 Workaround: https://bugs.python.org/issue24931
__slots__ = tuple()
__slots__ = ()
Loading

0 comments on commit 531ccf7

Please sign in to comment.