Skip to content

Commit

Permalink
Merge pull request #48 from SpiNNakerManchester/abstract-context-manager
Browse files Browse the repository at this point in the history
Use the AbstractContextManager from SpiNNUtils
  • Loading branch information
Christian-B committed Oct 22, 2020
2 parents 74cebab + 590c2d0 commit 1b7c6da
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ before_install:
- python support/travis_blocking_stdout.py
- support/rat.sh download
- pip install --upgrade pip setuptools wheel
# SpiNNakerManchester internal dependencies; development mode
- support/pipinstall.sh git://github.com/SpiNNakerManchester/SpiNNUtils.git
install:
- python setup.py develop
- pip install -r requirements-test.txt
Expand Down
19 changes: 19 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2020 The University of Manchester
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

[pytest]
# Filter a warning from rig that doesn't affect this code anyway
filterwarnings =
ignore:.*inspect.getargspec.* is deprecated.*:DeprecationWarning
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
six>=1.8.0
appdirs
enum-compat
SpiNNUtilities >= 1!5.1.1, < 1!6.0.0
future
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
install_requires=["six>=1.8.0",
"appdirs",
"enum-compat",
'SpiNNUtilities >= 1!5.1.1, < 1!6.0.0',
"future"],
# Scripts
entry_points={
Expand All @@ -67,6 +68,12 @@
"spalloc-where-is = spalloc.scripts.where_is:main",
],
},
# Booting directly needs rig; not recommended! Use SpiNNMan instead, as
# that has an up-to-date boot image pre-built
extras_require={
'boot': [
'rig',
]},
maintainer="SpiNNakerTeam",
maintainer_email="spinnakerusers@googlegroups.com"
)
12 changes: 5 additions & 7 deletions spalloc/protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import sys
from threading import current_thread, RLock, local
from six import raise_from
from spinn_utilities.abstract_context_manager import AbstractContextManager
from spinn_utilities.overrides import overrides
from spalloc._utils import time_left, timed_out, make_timeout


Expand Down Expand Up @@ -52,7 +54,7 @@ def __init__(self):
self.sock = None


class ProtocolClient(object):
class ProtocolClient(AbstractContextManager):
""" A simple (blocking) client implementation of the `spalloc-server
<https://github.com/project-rig/spalloc_server>`_ protocol.
Expand Down Expand Up @@ -106,13 +108,9 @@ def __init__(self, hostname, port=22244, timeout=None):
self._notifications_lock = RLock()
self._default_timeout = timeout

def __enter__(self): # pragma: no cover
@overrides(AbstractContextManager._context_entered)
def _context_entered(self): # pragma: no cover
self.connect(self._default_timeout)
return self

def __exit__(self, _ty, _val, _tb): # pragma: no cover
self.close()
return False

def _get_connection(self, timeout):
if self._dead:
Expand Down
7 changes: 3 additions & 4 deletions spalloc/scripts/alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ def parse_argv(argv):
parser.add_argument("--no-destroy", "-D", action="store_true",
default=False,
help="do not destroy the job on exit")
if MachineController is not None:
parser.add_argument("--boot", "-B", action="store_true",
default=False,
if MachineController:
parser.add_argument("--boot", "-B", action="store_true", default=False,
help="boot the machine once powered on")

allocation_args = parser.add_argument_group(
Expand Down Expand Up @@ -446,7 +445,7 @@ def run_job(job_args, job_kwargs, ip_file_filename):
write_ips_to_csv(job.connections, ip_file_filename)

# Boot the machine if required
if MachineController is not None and arguments.boot:
if MachineController and arguments.boot:
update("Job {}: Booting...", t.yellow, job.id)
mc = MachineController(job.hostname)
mc.boot(job.width, job.height)
Expand Down

0 comments on commit 1b7c6da

Please sign in to comment.