From 9fde231250ccf630d2a27f1299043eb6d068341d Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Sun, 13 Mar 2022 15:18:53 +0100 Subject: [PATCH] moved control-related modules to a sub-package; minor corrections --- setup.cfg | 2 +- src/asyncio_taskpool/__init__.py | 2 +- src/asyncio_taskpool/control/__init__.py | 0 src/asyncio_taskpool/{ => control}/__main__.py | 4 ++-- src/asyncio_taskpool/{ => control}/client.py | 4 ++-- src/asyncio_taskpool/{ => control}/parser.py | 6 +++--- src/asyncio_taskpool/{ => control}/server.py | 4 ++-- src/asyncio_taskpool/{ => control}/session.py | 10 +++++----- src/asyncio_taskpool/pool.py | 2 +- tests/test_control/__init__.py | 0 tests/{ => test_control}/test_client.py | 4 ++-- tests/{ => test_control}/test_parser.py | 2 +- tests/{ => test_control}/test_server.py | 6 +++--- tests/{ => test_control}/test_session.py | 4 ++-- 14 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 src/asyncio_taskpool/control/__init__.py rename src/asyncio_taskpool/{ => control}/__main__.py (97%) rename src/asyncio_taskpool/{ => control}/client.py (98%) rename src/asyncio_taskpool/{ => control}/parser.py (99%) rename src/asyncio_taskpool/{ => control}/server.py (98%) rename src/asyncio_taskpool/{ => control}/session.py (97%) create mode 100644 tests/test_control/__init__.py rename tests/{ => test_control}/test_client.py (98%) rename tests/{ => test_control}/test_parser.py (99%) rename tests/{ => test_control}/test_server.py (96%) rename tests/{ => test_control}/test_session.py (99%) diff --git a/setup.cfg b/setup.cfg index 664e256..644509a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = asyncio-taskpool -version = 0.6.0 +version = 0.6.1 author = Daniil Fajnberg author_email = mail@daniil.fajnberg.de description = Dynamically manage pools of asyncio tasks diff --git a/src/asyncio_taskpool/__init__.py b/src/asyncio_taskpool/__init__.py index c3b03b7..952ec9d 100644 --- a/src/asyncio_taskpool/__init__.py +++ b/src/asyncio_taskpool/__init__.py @@ -19,5 +19,5 @@ Brings the main classes up to package level for import convenience. """ +from .control.server import TCPControlServer, UnixControlServer from .pool import TaskPool, SimpleTaskPool -from .server import TCPControlServer, UnixControlServer diff --git a/src/asyncio_taskpool/control/__init__.py b/src/asyncio_taskpool/control/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/asyncio_taskpool/__main__.py b/src/asyncio_taskpool/control/__main__.py similarity index 97% rename from src/asyncio_taskpool/__main__.py rename to src/asyncio_taskpool/control/__main__.py index 5c9e97e..86ed53a 100644 --- a/src/asyncio_taskpool/__main__.py +++ b/src/asyncio_taskpool/control/__main__.py @@ -25,9 +25,9 @@ from asyncio import run from pathlib import Path from typing import Dict, Any +from ..constants import PACKAGE_NAME +from ..pool import TaskPool from .client import ControlClient, TCPControlClient, UnixControlClient -from .constants import PACKAGE_NAME -from .pool import TaskPool from .server import TCPControlServer, UnixControlServer diff --git a/src/asyncio_taskpool/client.py b/src/asyncio_taskpool/control/client.py similarity index 98% rename from src/asyncio_taskpool/client.py rename to src/asyncio_taskpool/control/client.py index 9a08127..8a309cf 100644 --- a/src/asyncio_taskpool/client.py +++ b/src/asyncio_taskpool/control/client.py @@ -27,8 +27,8 @@ from asyncio.streams import StreamReader, StreamWriter, open_connection from pathlib import Path from typing import Optional, Union -from .constants import CLIENT_EXIT, CLIENT_INFO, SESSION_MSG_BYTES -from .types import ClientConnT, PathT +from ..constants import CLIENT_EXIT, CLIENT_INFO, SESSION_MSG_BYTES +from ..types import ClientConnT, PathT class ControlClient(ABC): diff --git a/src/asyncio_taskpool/parser.py b/src/asyncio_taskpool/control/parser.py similarity index 99% rename from src/asyncio_taskpool/parser.py rename to src/asyncio_taskpool/control/parser.py index d13753a..75352ed 100644 --- a/src/asyncio_taskpool/parser.py +++ b/src/asyncio_taskpool/control/parser.py @@ -25,9 +25,9 @@ from inspect import Parameter, getmembers, isfunction, signature from shutil import get_terminal_size from typing import Callable, Container, Dict, Set, Type, TypeVar -from .constants import CLIENT_INFO, CMD, STREAM_WRITER -from .exceptions import HelpRequested -from .helpers import get_first_doc_line +from ..constants import CLIENT_INFO, CMD, STREAM_WRITER +from ..exceptions import HelpRequested +from ..helpers import get_first_doc_line FmtCls = TypeVar('FmtCls', bound=Type[HelpFormatter]) diff --git a/src/asyncio_taskpool/server.py b/src/asyncio_taskpool/control/server.py similarity index 98% rename from src/asyncio_taskpool/server.py rename to src/asyncio_taskpool/control/server.py index 7b020f5..5656f84 100644 --- a/src/asyncio_taskpool/server.py +++ b/src/asyncio_taskpool/control/server.py @@ -28,10 +28,10 @@ from asyncio.tasks import Task, create_task from pathlib import Path from typing import Optional, Union +from ..pool import TaskPool, SimpleTaskPool +from ..types import ConnectedCallbackT from .client import ControlClient, TCPControlClient, UnixControlClient -from .pool import TaskPool, SimpleTaskPool from .session import ControlSession -from .types import ConnectedCallbackT log = logging.getLogger(__name__) diff --git a/src/asyncio_taskpool/session.py b/src/asyncio_taskpool/control/session.py similarity index 97% rename from src/asyncio_taskpool/session.py rename to src/asyncio_taskpool/control/session.py index 0e733ac..457e54c 100644 --- a/src/asyncio_taskpool/session.py +++ b/src/asyncio_taskpool/control/session.py @@ -26,10 +26,10 @@ from asyncio.streams import StreamReader, StreamWriter from inspect import isfunction, signature from typing import Callable, Optional, Union, TYPE_CHECKING -from .constants import CLIENT_INFO, CMD, CMD_OK, SESSION_MSG_BYTES, STREAM_WRITER -from .exceptions import HelpRequested -from .helpers import return_or_exception -from .pool import TaskPool, SimpleTaskPool +from ..constants import CLIENT_INFO, CMD, CMD_OK, SESSION_MSG_BYTES, STREAM_WRITER +from ..exceptions import HelpRequested +from ..helpers import return_or_exception +from ..pool import TaskPool, SimpleTaskPool from .parser import ControlParser if TYPE_CHECKING: @@ -131,7 +131,7 @@ class ControlSession: STREAM_WRITER: self._writer, CLIENT_INFO.TERMINAL_WIDTH: client_info[CLIENT_INFO.TERMINAL_WIDTH], 'prog': '', - 'usage': f'%(prog)s [-h] [{CMD}] ...' + 'usage': f'[-h] [{CMD}] ...' } self._parser = ControlParser(**parser_kwargs) self._parser.add_subparsers(title="Commands", diff --git a/src/asyncio_taskpool/pool.py b/src/asyncio_taskpool/pool.py index 183cbc7..7abcdee 100644 --- a/src/asyncio_taskpool/pool.py +++ b/src/asyncio_taskpool/pool.py @@ -120,7 +120,7 @@ class BaseTaskPool: @property def is_locked(self) -> bool: - """Returns `True` if more the pool has been locked (see below).""" + """Returns `True` if the pool has been locked (see below).""" return self._locked def lock(self) -> None: diff --git a/tests/test_control/__init__.py b/tests/test_control/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_client.py b/tests/test_control/test_client.py similarity index 98% rename from tests/test_client.py rename to tests/test_control/test_client.py index 084c6d9..683e5f3 100644 --- a/tests/test_client.py +++ b/tests/test_control/test_client.py @@ -27,7 +27,7 @@ from pathlib import Path from unittest import IsolatedAsyncioTestCase, skipIf from unittest.mock import AsyncMock, MagicMock, patch -from asyncio_taskpool import client +from asyncio_taskpool.control import client from asyncio_taskpool.constants import CLIENT_INFO, SESSION_MSG_BYTES @@ -37,7 +37,7 @@ FOO, BAR = 'foo', 'bar' class ControlClientTestCase(IsolatedAsyncioTestCase): def setUp(self) -> None: - self.abstract_patcher = patch('asyncio_taskpool.client.ControlClient.__abstractmethods__', set()) + self.abstract_patcher = patch('asyncio_taskpool.control.client.ControlClient.__abstractmethods__', set()) self.print_patcher = patch.object(client, 'print') self.mock_abstract_methods = self.abstract_patcher.start() self.mock_print = self.print_patcher.start() diff --git a/tests/test_parser.py b/tests/test_control/test_parser.py similarity index 99% rename from tests/test_parser.py rename to tests/test_control/test_parser.py index 04b39bb..ab60db8 100644 --- a/tests/test_parser.py +++ b/tests/test_control/test_parser.py @@ -24,7 +24,7 @@ from inspect import signature from unittest import TestCase from unittest.mock import MagicMock, call, patch -from asyncio_taskpool import parser +from asyncio_taskpool.control import parser from asyncio_taskpool.exceptions import HelpRequested diff --git a/tests/test_server.py b/tests/test_control/test_server.py similarity index 96% rename from tests/test_server.py rename to tests/test_control/test_server.py index f76027d..b61d78d 100644 --- a/tests/test_server.py +++ b/tests/test_control/test_server.py @@ -26,8 +26,8 @@ from pathlib import Path from unittest import IsolatedAsyncioTestCase, skipIf from unittest.mock import AsyncMock, MagicMock, patch -from asyncio_taskpool import server -from asyncio_taskpool.client import ControlClient, UnixControlClient +from asyncio_taskpool.control import server +from asyncio_taskpool.control.client import ControlClient, UnixControlClient FOO, BAR = 'foo', 'bar' @@ -46,7 +46,7 @@ class ControlServerTestCase(IsolatedAsyncioTestCase): server.log.setLevel(cls.log_lvl) def setUp(self) -> None: - self.abstract_patcher = patch('asyncio_taskpool.server.ControlServer.__abstractmethods__', set()) + self.abstract_patcher = patch('asyncio_taskpool.control.server.ControlServer.__abstractmethods__', set()) self.mock_abstract_methods = self.abstract_patcher.start() self.mock_pool = MagicMock() self.kwargs = {FOO: 123, BAR: 456} diff --git a/tests/test_session.py b/tests/test_control/test_session.py similarity index 99% rename from tests/test_session.py rename to tests/test_control/test_session.py index fec98d7..fd393a0 100644 --- a/tests/test_session.py +++ b/tests/test_control/test_session.py @@ -24,7 +24,7 @@ from argparse import ArgumentError, Namespace from unittest import IsolatedAsyncioTestCase from unittest.mock import AsyncMock, MagicMock, patch, call -from asyncio_taskpool import session +from asyncio_taskpool.control import session from asyncio_taskpool.constants import CLIENT_INFO, CMD, SESSION_MSG_BYTES, STREAM_WRITER from asyncio_taskpool.exceptions import HelpRequested from asyncio_taskpool.pool import SimpleTaskPool @@ -107,7 +107,7 @@ class ControlServerTestCase(IsolatedAsyncioTestCase): STREAM_WRITER: self.mock_writer, CLIENT_INFO.TERMINAL_WIDTH: width, 'prog': '', - 'usage': f'%(prog)s [-h] [{CMD}] ...' + 'usage': f'[-h] [{CMD}] ...' } expected_subparsers_kwargs = { 'title': "Commands",