Skip to content

Commit

Permalink
Merge pull request #25 from SpiNNakerManchester/minor-import-improvem…
Browse files Browse the repository at this point in the history
…ents

Make import statements use PEP 328 better
  • Loading branch information
dkfellows committed Nov 8, 2018
2 parents 358638a + ce3b32d commit f68799c
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 102 deletions.
4 changes: 1 addition & 3 deletions spalloc/_keepalive_process.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
""" A script for keeping Spalloc jobs alive, intended to only ever be run\
from the Spalloc client itself.
"""


from spalloc.protocol_client import ProtocolClient, ProtocolTimeoutError
import sys
import threading
from spalloc.protocol_client import ProtocolClient, ProtocolTimeoutError


def wait_for_exit(stop_event):
Expand Down
5 changes: 1 addition & 4 deletions spalloc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@
requires the allocation of a whole machine. If False, wrap-around links may
or may-not be present in allocated machines. (Default: False)
"""

# pylint: disable=import-error
import os
import os.path
import appdirs

from six import iteritems
# pylint: disable=import-error
from six.moves.configparser import ConfigParser, NoOptionError


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

Expand Down
1 change: 0 additions & 1 deletion spalloc/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
import time
import sys

from .protocol_client import ProtocolClient, ProtocolTimeoutError
from .config import read_config, SEARCH_PATH
from .states import JobState
Expand Down
8 changes: 4 additions & 4 deletions spalloc/protocol_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
""" A simple blocking spalloc_server protocol implementation.
"""

import socket
import json
from threading import current_thread, RLock, local
from collections import deque
from spalloc._utils import time_left, timed_out, make_timeout
import errno
import json
import socket
import sys
from threading import current_thread, RLock, local
from six import raise_from
from spalloc._utils import time_left, timed_out, make_timeout


class ProtocolError(Exception):
Expand Down
13 changes: 5 additions & 8 deletions spalloc/scripts/alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,19 @@
messages are sent automatically but after exiting the commands are no longer
sent. Adding the ``--keepalive -1`` option when creating a job disables this.
"""

import argparse
from collections import OrderedDict
import logging
import os
from six import iteritems
from six.moves import input, shlex_quote # @UnresolvedImport
import subprocess
import sys
import tempfile

from spalloc import config
from spalloc import Job, JobState, __version__
from six import iteritems
from six.moves import input, shlex_quote # @UnresolvedImport
from spalloc import (
config, Job, JobState, __version__, ProtocolError, ProtocolTimeoutError,
SpallocServerException)
from spalloc.term import Terminal, render_definitions
from spalloc import ProtocolError, ProtocolTimeoutError, SpallocServerException

# Rig is used to implement the optional '--boot' facility.
try:
from rig.machine_control import MachineController
Expand Down
9 changes: 4 additions & 5 deletions spalloc/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@
import argparse
from collections import OrderedDict
import datetime
from pytz import utc
from six import iteritems
import sys
from pytz import utc
from tzlocal import get_localzone

from six import iteritems
from spalloc import __version__, JobState
from spalloc.term import \
Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES
from spalloc.term import (
Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES)
from .support import Terminate, Script


Expand Down
10 changes: 4 additions & 6 deletions spalloc/scripts/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
"""
import argparse
from collections import defaultdict, OrderedDict
from six import next # pylint: disable=redefined-builtin
import sys

from six import next # pylint: disable=redefined-builtin
from spalloc import __version__
from spalloc.term import \
Terminal, render_table, render_definitions, render_boards, render_cells, \
DEFAULT_BOARD_EDGES
from spalloc.term import (
Terminal, render_table, render_definitions, render_boards, render_cells,
DEFAULT_BOARD_EDGES)
from .support import Terminate, Script


# The acceptable range of server version numbers
VERSION_RANGE_START = (0, 1, 0)
VERSION_RANGE_STOP = (2, 0, 0)
Expand Down
4 changes: 1 addition & 3 deletions spalloc/scripts/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
This list may be filtered by owner or machine with the ``--owner`` and
``--machine`` arguments.
"""

import argparse
import datetime
from pytz import utc
import sys
from pytz import utc
from tzlocal import get_localzone

from spalloc import __version__, JobState
from spalloc.term import Terminal, render_table
from .support import Script
Expand Down
6 changes: 3 additions & 3 deletions spalloc/scripts/support.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from spalloc import config
from spalloc import \
ProtocolClient, ProtocolError, ProtocolTimeoutError, SpallocServerException
from spalloc import (
config, ProtocolClient, ProtocolError, ProtocolTimeoutError,
SpallocServerException)

# The acceptable range of server version numbers
VERSION_RANGE_START = (0, 1, 0)
Expand Down
2 changes: 0 additions & 2 deletions spalloc/scripts/where_is.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
"""
import sys
import argparse

from collections import OrderedDict

from spalloc import __version__
from spalloc.term import render_definitions
from .support import Terminate, Script
Expand Down
7 changes: 2 additions & 5 deletions spalloc/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

import os
import sys

from functools import partial
from itertools import chain
from collections import defaultdict

from six import iteritems, string_types

from enum import IntEnum
from functools import partial
from six import iteritems, string_types


class ANSIDisplayAttributes(IntEnum):
Expand Down
8 changes: 2 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import pytest

from mock import Mock

import os
import sys
import threading
import tempfile

import pytest
from mock import Mock
from spalloc import ProtocolClient
from spalloc.config import SEARCH_PATH

from .common import MockServer


Expand Down
12 changes: 4 additions & 8 deletions tests/scripts/test_alloc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pytest

from mock import Mock, PropertyMock

import os
import tempfile

import pytest
from mock import Mock, PropertyMock
from spalloc import JobState, JobDestroyedError

from spalloc.scripts.alloc import \
write_ips_to_csv, print_info, run_command, main
from spalloc.scripts.alloc import (
write_ips_to_csv, print_info, run_command, main)


@pytest.yield_fixture
Expand Down
13 changes: 5 additions & 8 deletions tests/scripts/test_job_script.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import datetime
import pytest

from mock import Mock, MagicMock

import datetime

from spalloc import JobState, ProtocolError
from spalloc.term import Terminal
from spalloc.scripts.job import \
show_job_info, watch_job, power_job, list_ips, destroy_job, main
from spalloc.scripts.support import \
VERSION_RANGE_START, VERSION_RANGE_STOP, Terminate
from spalloc.scripts.job import (
show_job_info, watch_job, power_job, list_ips, destroy_job, main)
from spalloc.scripts.support import (
VERSION_RANGE_START, VERSION_RANGE_STOP, Terminate)


@pytest.fixture
Expand Down
11 changes: 4 additions & 7 deletions tests/scripts/test_machine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import pytest

from mock import Mock, MagicMock

from spalloc.term import Terminal

from spalloc.scripts.machine import \
main, generate_keys, list_machines, show_machine
from spalloc.scripts.support import \
VERSION_RANGE_START, VERSION_RANGE_STOP, Terminate
from spalloc.scripts.machine import (
main, generate_keys, list_machines, show_machine)
from spalloc.scripts.support import (
VERSION_RANGE_START, VERSION_RANGE_STOP, Terminate)
from spalloc.protocol_client import ProtocolError


Expand Down
1 change: 0 additions & 1 deletion tests/scripts/test_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import datetime
from mock import Mock, MagicMock
import pytest

from spalloc.scripts.ps import main, render_job_list
from spalloc.scripts.support import VERSION_RANGE_START, VERSION_RANGE_STOP
from spalloc.term import Terminal
Expand Down
2 changes: 0 additions & 2 deletions tests/scripts/test_where_is.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from mock import Mock, MagicMock

from spalloc.scripts.where_is import main
from spalloc.scripts.support import VERSION_RANGE_START, VERSION_RANGE_STOP
from spalloc.protocol_client import ProtocolError
Expand Down
4 changes: 1 addition & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pytest

import tempfile
import shutil
import os.path

import pytest
from spalloc.config import read_config


Expand Down
16 changes: 5 additions & 11 deletions tests/test_job.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import time
from threading import Thread, Event
import pytest

from mock import Mock

import time

from spalloc import Job, JobState, JobDestroyedError, ProtocolTimeoutError

from spalloc._keepalive_process import keep_job_alive
from spalloc.job import \
_JobStateTuple, _JobMachineInfoTuple, \
VERSION_RANGE_START, VERSION_RANGE_STOP, \
StateChangeTimeoutError

from threading import Thread, Event
from spalloc.job import (
_JobStateTuple, _JobMachineInfoTuple, StateChangeTimeoutError,
VERSION_RANGE_START, VERSION_RANGE_STOP)

GOOD_VERSION = ".".join(map(str, VERSION_RANGE_START))
BAD_VERSION = ".".join(map(str, VERSION_RANGE_STOP))
Expand Down
11 changes: 5 additions & 6 deletions tests/test_protocol_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from mock import Mock
import socket
import threading
import time
import logging

from spalloc import ProtocolClient
from spalloc import SpallocServerException, ProtocolTimeoutError, ProtocolError

import pytest
from mock import Mock
from spalloc import (
ProtocolClient, SpallocServerException, ProtocolTimeoutError,
ProtocolError)
from .common import MockServer

logging.basicConfig(level=logging.DEBUG)
Expand Down
10 changes: 4 additions & 6 deletions tests/test_term.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest

from collections import OrderedDict

from spalloc.term import \
Terminal, render_table, render_definitions, render_boards, render_cells, \
DEFAULT_BOARD_EDGES
import pytest
from spalloc.term import (
Terminal, render_table, render_definitions, render_boards, render_cells,
DEFAULT_BOARD_EDGES)


@pytest.mark.parametrize("force", [True, False])
Expand Down

0 comments on commit f68799c

Please sign in to comment.