generated from daniil-berg/boilerplate-py
moved control-related modules to a sub-package; minor corrections
This commit is contained in:
parent
c72a5035ea
commit
9fde231250
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = asyncio-taskpool
|
name = asyncio-taskpool
|
||||||
version = 0.6.0
|
version = 0.6.1
|
||||||
author = Daniil Fajnberg
|
author = Daniil Fajnberg
|
||||||
author_email = mail@daniil.fajnberg.de
|
author_email = mail@daniil.fajnberg.de
|
||||||
description = Dynamically manage pools of asyncio tasks
|
description = Dynamically manage pools of asyncio tasks
|
||||||
|
@ -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 .pool import TaskPool, SimpleTaskPool
|
||||||
from .server import TCPControlServer, UnixControlServer
|
|
||||||
|
0
src/asyncio_taskpool/control/__init__.py
Normal file
0
src/asyncio_taskpool/control/__init__.py
Normal file
@ -25,9 +25,9 @@ from asyncio import run
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
from ..constants import PACKAGE_NAME
|
||||||
|
from ..pool import TaskPool
|
||||||
from .client import ControlClient, TCPControlClient, UnixControlClient
|
from .client import ControlClient, TCPControlClient, UnixControlClient
|
||||||
from .constants import PACKAGE_NAME
|
|
||||||
from .pool import TaskPool
|
|
||||||
from .server import TCPControlServer, UnixControlServer
|
from .server import TCPControlServer, UnixControlServer
|
||||||
|
|
||||||
|
|
@ -27,8 +27,8 @@ from asyncio.streams import StreamReader, StreamWriter, open_connection
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
from .constants import CLIENT_EXIT, CLIENT_INFO, SESSION_MSG_BYTES
|
from ..constants import CLIENT_EXIT, CLIENT_INFO, SESSION_MSG_BYTES
|
||||||
from .types import ClientConnT, PathT
|
from ..types import ClientConnT, PathT
|
||||||
|
|
||||||
|
|
||||||
class ControlClient(ABC):
|
class ControlClient(ABC):
|
@ -25,9 +25,9 @@ from inspect import Parameter, getmembers, isfunction, signature
|
|||||||
from shutil import get_terminal_size
|
from shutil import get_terminal_size
|
||||||
from typing import Callable, Container, Dict, Set, Type, TypeVar
|
from typing import Callable, Container, Dict, Set, Type, TypeVar
|
||||||
|
|
||||||
from .constants import CLIENT_INFO, CMD, STREAM_WRITER
|
from ..constants import CLIENT_INFO, CMD, STREAM_WRITER
|
||||||
from .exceptions import HelpRequested
|
from ..exceptions import HelpRequested
|
||||||
from .helpers import get_first_doc_line
|
from ..helpers import get_first_doc_line
|
||||||
|
|
||||||
|
|
||||||
FmtCls = TypeVar('FmtCls', bound=Type[HelpFormatter])
|
FmtCls = TypeVar('FmtCls', bound=Type[HelpFormatter])
|
@ -28,10 +28,10 @@ from asyncio.tasks import Task, create_task
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
|
from ..pool import TaskPool, SimpleTaskPool
|
||||||
|
from ..types import ConnectedCallbackT
|
||||||
from .client import ControlClient, TCPControlClient, UnixControlClient
|
from .client import ControlClient, TCPControlClient, UnixControlClient
|
||||||
from .pool import TaskPool, SimpleTaskPool
|
|
||||||
from .session import ControlSession
|
from .session import ControlSession
|
||||||
from .types import ConnectedCallbackT
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
@ -26,10 +26,10 @@ from asyncio.streams import StreamReader, StreamWriter
|
|||||||
from inspect import isfunction, signature
|
from inspect import isfunction, signature
|
||||||
from typing import Callable, Optional, Union, TYPE_CHECKING
|
from typing import Callable, Optional, Union, TYPE_CHECKING
|
||||||
|
|
||||||
from .constants import CLIENT_INFO, CMD, CMD_OK, SESSION_MSG_BYTES, STREAM_WRITER
|
from ..constants import CLIENT_INFO, CMD, CMD_OK, SESSION_MSG_BYTES, STREAM_WRITER
|
||||||
from .exceptions import HelpRequested
|
from ..exceptions import HelpRequested
|
||||||
from .helpers import return_or_exception
|
from ..helpers import return_or_exception
|
||||||
from .pool import TaskPool, SimpleTaskPool
|
from ..pool import TaskPool, SimpleTaskPool
|
||||||
from .parser import ControlParser
|
from .parser import ControlParser
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -131,7 +131,7 @@ class ControlSession:
|
|||||||
STREAM_WRITER: self._writer,
|
STREAM_WRITER: self._writer,
|
||||||
CLIENT_INFO.TERMINAL_WIDTH: client_info[CLIENT_INFO.TERMINAL_WIDTH],
|
CLIENT_INFO.TERMINAL_WIDTH: client_info[CLIENT_INFO.TERMINAL_WIDTH],
|
||||||
'prog': '',
|
'prog': '',
|
||||||
'usage': f'%(prog)s [-h] [{CMD}] ...'
|
'usage': f'[-h] [{CMD}] ...'
|
||||||
}
|
}
|
||||||
self._parser = ControlParser(**parser_kwargs)
|
self._parser = ControlParser(**parser_kwargs)
|
||||||
self._parser.add_subparsers(title="Commands",
|
self._parser.add_subparsers(title="Commands",
|
@ -120,7 +120,7 @@ class BaseTaskPool:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_locked(self) -> bool:
|
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
|
return self._locked
|
||||||
|
|
||||||
def lock(self) -> None:
|
def lock(self) -> None:
|
||||||
|
0
tests/test_control/__init__.py
Normal file
0
tests/test_control/__init__.py
Normal file
@ -27,7 +27,7 @@ from pathlib import Path
|
|||||||
from unittest import IsolatedAsyncioTestCase, skipIf
|
from unittest import IsolatedAsyncioTestCase, skipIf
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
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
|
from asyncio_taskpool.constants import CLIENT_INFO, SESSION_MSG_BYTES
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ FOO, BAR = 'foo', 'bar'
|
|||||||
class ControlClientTestCase(IsolatedAsyncioTestCase):
|
class ControlClientTestCase(IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
def setUp(self) -> None:
|
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.print_patcher = patch.object(client, 'print')
|
||||||
self.mock_abstract_methods = self.abstract_patcher.start()
|
self.mock_abstract_methods = self.abstract_patcher.start()
|
||||||
self.mock_print = self.print_patcher.start()
|
self.mock_print = self.print_patcher.start()
|
@ -24,7 +24,7 @@ from inspect import signature
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, call, patch
|
from unittest.mock import MagicMock, call, patch
|
||||||
|
|
||||||
from asyncio_taskpool import parser
|
from asyncio_taskpool.control import parser
|
||||||
from asyncio_taskpool.exceptions import HelpRequested
|
from asyncio_taskpool.exceptions import HelpRequested
|
||||||
|
|
||||||
|
|
@ -26,8 +26,8 @@ from pathlib import Path
|
|||||||
from unittest import IsolatedAsyncioTestCase, skipIf
|
from unittest import IsolatedAsyncioTestCase, skipIf
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from asyncio_taskpool import server
|
from asyncio_taskpool.control import server
|
||||||
from asyncio_taskpool.client import ControlClient, UnixControlClient
|
from asyncio_taskpool.control.client import ControlClient, UnixControlClient
|
||||||
|
|
||||||
|
|
||||||
FOO, BAR = 'foo', 'bar'
|
FOO, BAR = 'foo', 'bar'
|
||||||
@ -46,7 +46,7 @@ class ControlServerTestCase(IsolatedAsyncioTestCase):
|
|||||||
server.log.setLevel(cls.log_lvl)
|
server.log.setLevel(cls.log_lvl)
|
||||||
|
|
||||||
def setUp(self) -> None:
|
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_abstract_methods = self.abstract_patcher.start()
|
||||||
self.mock_pool = MagicMock()
|
self.mock_pool = MagicMock()
|
||||||
self.kwargs = {FOO: 123, BAR: 456}
|
self.kwargs = {FOO: 123, BAR: 456}
|
@ -24,7 +24,7 @@ from argparse import ArgumentError, Namespace
|
|||||||
from unittest import IsolatedAsyncioTestCase
|
from unittest import IsolatedAsyncioTestCase
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch, call
|
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.constants import CLIENT_INFO, CMD, SESSION_MSG_BYTES, STREAM_WRITER
|
||||||
from asyncio_taskpool.exceptions import HelpRequested
|
from asyncio_taskpool.exceptions import HelpRequested
|
||||||
from asyncio_taskpool.pool import SimpleTaskPool
|
from asyncio_taskpool.pool import SimpleTaskPool
|
||||||
@ -107,7 +107,7 @@ class ControlServerTestCase(IsolatedAsyncioTestCase):
|
|||||||
STREAM_WRITER: self.mock_writer,
|
STREAM_WRITER: self.mock_writer,
|
||||||
CLIENT_INFO.TERMINAL_WIDTH: width,
|
CLIENT_INFO.TERMINAL_WIDTH: width,
|
||||||
'prog': '',
|
'prog': '',
|
||||||
'usage': f'%(prog)s [-h] [{CMD}] ...'
|
'usage': f'[-h] [{CMD}] ...'
|
||||||
}
|
}
|
||||||
expected_subparsers_kwargs = {
|
expected_subparsers_kwargs = {
|
||||||
'title': "Commands",
|
'title': "Commands",
|
Loading…
Reference in New Issue
Block a user