2026-07-22 22:19:16 +02:00
|
|
|
from typing import Any, override
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
import asyncio
|
|
|
|
|
import os
|
|
|
|
|
import shlex
|
|
|
|
|
import shutil
|
|
|
|
|
import signal
|
|
|
|
|
import sys
|
2026-03-21 04:29:58 +01:00
|
|
|
|
2026-07-22 22:22:05 +02:00
|
|
|
import asyncssh # type: ignore[import-not-found, unused-ignore]
|
2026-03-21 04:29:58 +01:00
|
|
|
|
2026-04-16 11:23:05 +02:00
|
|
|
from ...base import Result
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
from ...log import DEBUG, ERR, NOTICE, log
|
2026-03-21 04:29:58 +01:00
|
|
|
from ..SSHClient import SSHClient as Base
|
2026-04-10 14:58:29 +02:00
|
|
|
from .util import join_cmd
|
|
|
|
|
|
2026-03-21 04:29:58 +01:00
|
|
|
_USE_DEFAULT_KNOWN_HOSTS = object()
|
|
|
|
|
|
|
|
|
|
class AsyncSSH(Base):
|
2026-04-15 21:49:40 +02:00
|
|
|
|
2026-03-21 04:29:58 +01:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
uri: str,
|
|
|
|
|
*,
|
|
|
|
|
client_keys: list[str] | None = None,
|
2026-04-19 14:04:27 +02:00
|
|
|
known_hosts = _USE_DEFAULT_KNOWN_HOSTS,
|
2026-03-21 04:29:58 +01:00
|
|
|
term_type: str | None = None,
|
|
|
|
|
connect_timeout: float | None = 30.0,
|
|
|
|
|
**kwargs,
|
|
|
|
|
) -> None:
|
|
|
|
|
|
|
|
|
|
super().__init__(
|
|
|
|
|
uri,
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
caps = self.Caps.LogOutput
|
|
|
|
|
| self.Caps.Wd
|
|
|
|
|
| self.Caps.Interactive
|
|
|
|
|
| self.Caps.ModEnv,
|
|
|
|
|
**kwargs,
|
2026-03-21 04:29:58 +01:00
|
|
|
)
|
|
|
|
|
|
2026-04-19 19:52:18 +02:00
|
|
|
self.__client_keys = client_keys
|
|
|
|
|
self.__known_hosts = known_hosts
|
|
|
|
|
self.__term_type = term_type or os.environ.get('TERM', 'xterm')
|
|
|
|
|
self.__connect_timeout = connect_timeout
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
self.__conn: asyncssh.SSHClientConnection | None = None
|
2026-03-21 04:29:58 +01:00
|
|
|
|
App, lib, cmds: Fix mypy.explicit-override fallout
This commit adds @override decorators to approximately 300 methods
across 76 files that inherit from base classes such as AbstractCmd,
FileContext, ExecContext, Distro, SSHClient, and others.
The decorator ensures the type checker can verify that overridden
methods have compatible signatures and prevents accidental shadowing
of inherited methods without intent.
Files modified include command classes, library modules, distro
implementations, and SSH client implementations.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 15:51:14 +02:00
|
|
|
@override
|
2026-04-22 07:55:44 +02:00
|
|
|
async def _open(self) -> None:
|
|
|
|
|
await super()._open()
|
|
|
|
|
await self._conn
|
|
|
|
|
|
App, lib, cmds: Fix mypy.explicit-override fallout
This commit adds @override decorators to approximately 300 methods
across 76 files that inherit from base classes such as AbstractCmd,
FileContext, ExecContext, Distro, SSHClient, and others.
The decorator ensures the type checker can verify that overridden
methods have compatible signatures and prevents accidental shadowing
of inherited methods without intent.
Files modified include command classes, library modules, distro
implementations, and SSH client implementations.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 15:51:14 +02:00
|
|
|
@override
|
2026-04-19 19:52:18 +02:00
|
|
|
async def _close(self) -> None:
|
|
|
|
|
if self.__conn is not None:
|
|
|
|
|
try:
|
|
|
|
|
self.__conn.close()
|
|
|
|
|
await self.__conn.wait_closed()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log(DEBUG, f'Failed to close connection ({str(e)}, ignored)')
|
|
|
|
|
self.__conn = None
|
2026-04-19 14:04:35 +02:00
|
|
|
|
2026-07-22 22:19:16 +02:00
|
|
|
def _connect_kwargs(self, hide_secrets: bool = False) -> dict[str, Any]:
|
|
|
|
|
kwargs: dict[str, Any] = {
|
2026-04-19 14:04:27 +02:00
|
|
|
'host': self.hostname,
|
|
|
|
|
'port': self.port,
|
|
|
|
|
'username': self.username,
|
|
|
|
|
'password': self.password,
|
2026-04-19 19:52:18 +02:00
|
|
|
'client_keys': self.__client_keys,
|
|
|
|
|
'connect_timeout': self.__connect_timeout,
|
2026-03-21 04:29:58 +01:00
|
|
|
}
|
2026-04-19 19:52:18 +02:00
|
|
|
if self.__known_hosts is not _USE_DEFAULT_KNOWN_HOSTS:
|
|
|
|
|
kwargs['known_hosts'] = self.__known_hosts
|
2026-04-19 14:04:35 +02:00
|
|
|
ret = {k: v for k, v in kwargs.items() if v is not None}
|
|
|
|
|
if hide_secrets and 'password' in kwargs:
|
|
|
|
|
kwargs['password'] = '<hidden>'
|
|
|
|
|
return ret
|
2026-03-21 04:29:58 +01:00
|
|
|
|
2026-04-19 19:19:10 +02:00
|
|
|
@property
|
|
|
|
|
async def _conn(self) -> asyncssh.SSHClientConnection:
|
|
|
|
|
if self.__conn is None:
|
|
|
|
|
try:
|
|
|
|
|
self.__conn = await asyncssh.connect(**self._connect_kwargs())
|
|
|
|
|
except Exception as e:
|
|
|
|
|
msg = f'-------------------- Failed to connect ({str(e)})'
|
|
|
|
|
log(ERR, ',', msg)
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
for key, val in self._connect_kwargs(hide_secrets = True).items():
|
2026-04-19 19:19:10 +02:00
|
|
|
log(ERR, f'| {key:<20} = {val}')
|
|
|
|
|
log(ERR, '`', msg)
|
|
|
|
|
raise
|
|
|
|
|
return self.__conn
|
|
|
|
|
|
2026-04-19 19:52:18 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def _build_remote_command(cmd: list[str], wd: str | None) -> str:
|
|
|
|
|
inner = f'exec {join_cmd(cmd)}'
|
|
|
|
|
if wd is not None:
|
|
|
|
|
inner = f'cd {shlex.quote(wd)} && {inner}'
|
|
|
|
|
return f'/bin/sh -lc {shlex.quote(inner)}'
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _has_local_tty() -> bool:
|
|
|
|
|
try:
|
|
|
|
|
return sys.stdin.isatty() and sys.stdout.isatty()
|
|
|
|
|
except Exception:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _get_local_term_size() -> tuple[int, int, int, int]:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
cols, rows = shutil.get_terminal_size(fallback = (80, 24))
|
2026-04-19 19:52:18 +02:00
|
|
|
xpixel = ypixel = 0
|
|
|
|
|
try:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
import fcntl
|
|
|
|
|
import struct
|
|
|
|
|
import termios
|
|
|
|
|
|
2026-04-19 19:52:18 +02:00
|
|
|
packed = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, b'\0' * 8)
|
|
|
|
|
rows2, cols2, xpixel, ypixel = struct.unpack('HHHH', packed)
|
|
|
|
|
if cols2 > 0 and rows2 > 0:
|
|
|
|
|
cols, rows = cols2, rows2
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
return (cols, rows, xpixel, ypixel)
|
2026-04-19 19:19:10 +02:00
|
|
|
|
2026-03-21 04:29:58 +01:00
|
|
|
async def _read_stream(
|
|
|
|
|
self,
|
|
|
|
|
stream,
|
|
|
|
|
prio,
|
|
|
|
|
collector: list[bytes],
|
|
|
|
|
*,
|
|
|
|
|
verbose: bool,
|
|
|
|
|
log_prefix: str,
|
|
|
|
|
log_enc: str,
|
|
|
|
|
) -> None:
|
2026-04-19 14:04:27 +02:00
|
|
|
buf = b''
|
2026-03-21 04:29:58 +01:00
|
|
|
while True:
|
|
|
|
|
chunk = await stream.read(4096)
|
|
|
|
|
if not chunk:
|
|
|
|
|
break
|
|
|
|
|
collector.append(chunk)
|
|
|
|
|
if verbose:
|
|
|
|
|
buf += chunk
|
2026-04-19 14:04:27 +02:00
|
|
|
while b'\n' in buf:
|
|
|
|
|
line, buf = buf.split(b'\n', 1)
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
log(prio, log_prefix, line.decode(log_enc, errors = 'replace'))
|
2026-03-21 04:29:58 +01:00
|
|
|
if verbose and buf:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
log(prio, log_prefix, buf.decode(log_enc, errors = 'replace'))
|
2026-03-21 04:29:58 +01:00
|
|
|
|
2026-03-21 11:34:35 +01:00
|
|
|
async def _run_interactive_on_conn(
|
|
|
|
|
self,
|
|
|
|
|
cmd: list[str],
|
|
|
|
|
wd: str | None,
|
2026-04-15 14:02:44 +02:00
|
|
|
cmd_input: bytes | None,
|
2026-04-19 14:04:35 +02:00
|
|
|
mod_env: dict[str, str] | None,
|
2026-03-21 11:34:35 +01:00
|
|
|
) -> Result:
|
2026-04-19 14:04:35 +02:00
|
|
|
|
2026-04-19 19:19:10 +02:00
|
|
|
conn = await self._conn
|
2026-03-21 11:34:35 +01:00
|
|
|
command = self._build_remote_command(cmd, wd)
|
|
|
|
|
stdout_parts: list[bytes] = []
|
|
|
|
|
|
|
|
|
|
proc = await conn.create_process(
|
2026-04-19 14:04:27 +02:00
|
|
|
command = command,
|
|
|
|
|
env = mod_env,
|
|
|
|
|
stdin = asyncssh.PIPE,
|
|
|
|
|
stdout = asyncssh.PIPE,
|
|
|
|
|
stderr = asyncssh.STDOUT,
|
|
|
|
|
encoding = None,
|
|
|
|
|
request_pty = 'force',
|
2026-04-19 19:52:18 +02:00
|
|
|
term_type = self.__term_type,
|
2026-04-19 14:04:27 +02:00
|
|
|
term_size = self._get_local_term_size(),
|
2026-03-21 11:34:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
loop = asyncio.get_running_loop()
|
|
|
|
|
stdin_fd = sys.stdin.fileno()
|
|
|
|
|
|
|
|
|
|
stdin_queue: asyncio.Queue[bytes | None] = asyncio.Queue()
|
|
|
|
|
old_tty_state = None
|
|
|
|
|
old_winch_handler = None
|
|
|
|
|
stdin_reader_installed = False
|
|
|
|
|
|
|
|
|
|
def _write_local(data: bytes) -> None:
|
|
|
|
|
try:
|
|
|
|
|
sys.stdout.buffer.write(data)
|
|
|
|
|
sys.stdout.buffer.flush()
|
|
|
|
|
except AttributeError:
|
|
|
|
|
os.write(sys.stdout.fileno(), data)
|
|
|
|
|
|
|
|
|
|
def _on_stdin_ready() -> None:
|
|
|
|
|
try:
|
|
|
|
|
data = os.read(stdin_fd, 4096)
|
|
|
|
|
except OSError:
|
2026-04-19 14:04:27 +02:00
|
|
|
data = b''
|
2026-03-21 11:34:35 +01:00
|
|
|
|
|
|
|
|
if data:
|
|
|
|
|
stdin_queue.put_nowait(data)
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
loop.remove_reader(stdin_fd)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
stdin_queue.put_nowait(None)
|
|
|
|
|
|
|
|
|
|
async def _pump_stdin() -> None:
|
|
|
|
|
if cmd_input is not None and proc.stdin is not None:
|
2026-04-15 14:02:44 +02:00
|
|
|
proc.stdin.write(cmd_input)
|
2026-03-21 11:34:35 +01:00
|
|
|
await proc.stdin.drain()
|
|
|
|
|
while True:
|
|
|
|
|
data = await stdin_queue.get()
|
|
|
|
|
if data is None:
|
|
|
|
|
if proc.stdin is not None:
|
|
|
|
|
try:
|
|
|
|
|
proc.stdin.write_eof()
|
|
|
|
|
except (BrokenPipeError, OSError):
|
|
|
|
|
pass
|
|
|
|
|
return
|
2026-07-22 22:42:18 +02:00
|
|
|
if proc.stdin is not None:
|
|
|
|
|
proc.stdin.write(data)
|
2026-03-21 11:34:35 +01:00
|
|
|
await proc.stdin.drain()
|
|
|
|
|
|
|
|
|
|
async def _pump_stdout() -> None:
|
|
|
|
|
while True:
|
|
|
|
|
chunk = await proc.stdout.read(4096)
|
|
|
|
|
if not chunk:
|
|
|
|
|
break
|
|
|
|
|
stdout_parts.append(chunk)
|
|
|
|
|
_write_local(chunk)
|
|
|
|
|
|
|
|
|
|
def _on_winch(*_args) -> None:
|
2026-04-15 21:49:40 +02:00
|
|
|
|
2026-03-21 11:34:35 +01:00
|
|
|
try:
|
|
|
|
|
proc.change_terminal_size(*self._get_local_term_size())
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
|
|
|
|
|
try:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
import termios
|
|
|
|
|
import tty
|
2026-03-21 11:34:35 +01:00
|
|
|
|
|
|
|
|
old_tty_state = termios.tcgetattr(stdin_fd)
|
|
|
|
|
tty.setraw(stdin_fd)
|
|
|
|
|
except Exception:
|
|
|
|
|
old_tty_state = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
loop.add_reader(stdin_fd, _on_stdin_ready)
|
|
|
|
|
stdin_reader_installed = True
|
|
|
|
|
except (NotImplementedError, RuntimeError):
|
|
|
|
|
stdin_queue.put_nowait(None)
|
|
|
|
|
|
2026-04-19 14:04:27 +02:00
|
|
|
if hasattr(signal, 'SIGWINCH'):
|
2026-03-21 11:34:35 +01:00
|
|
|
try:
|
|
|
|
|
old_winch_handler = signal.getsignal(signal.SIGWINCH)
|
|
|
|
|
signal.signal(signal.SIGWINCH, _on_winch)
|
|
|
|
|
except Exception:
|
|
|
|
|
old_winch_handler = None
|
|
|
|
|
|
|
|
|
|
stdin_task = asyncio.create_task(_pump_stdin())
|
|
|
|
|
stdout_task = asyncio.create_task(_pump_stdout())
|
|
|
|
|
|
2026-04-19 14:04:27 +02:00
|
|
|
completed = await proc.wait(check = False)
|
2026-03-21 11:34:35 +01:00
|
|
|
await stdout_task
|
|
|
|
|
|
|
|
|
|
if not stdin_task.done():
|
|
|
|
|
stdin_task.cancel()
|
|
|
|
|
try:
|
|
|
|
|
await stdin_task
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
exit_code = completed.exit_status
|
|
|
|
|
if exit_code is None:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
exit_code = (
|
|
|
|
|
completed.returncode if completed.returncode is not None else -1
|
|
|
|
|
)
|
2026-03-21 11:34:35 +01:00
|
|
|
|
2026-04-19 14:04:27 +02:00
|
|
|
stdout = b''.join(stdout_parts) if stdout_parts else None
|
2026-06-13 04:43:34 +02:00
|
|
|
return Result(stdout, None, exit_code, cmd = cmd)
|
2026-03-21 11:34:35 +01:00
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
if stdin_reader_installed:
|
|
|
|
|
try:
|
|
|
|
|
loop.remove_reader(stdin_fd)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
2026-04-19 14:04:27 +02:00
|
|
|
if old_winch_handler is not None and hasattr(signal, 'SIGWINCH'):
|
2026-03-21 11:34:35 +01:00
|
|
|
try:
|
|
|
|
|
signal.signal(signal.SIGWINCH, old_winch_handler)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if old_tty_state is not None:
|
|
|
|
|
try:
|
|
|
|
|
import termios
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
|
2026-03-21 11:34:35 +01:00
|
|
|
termios.tcsetattr(stdin_fd, termios.TCSADRAIN, old_tty_state)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
async def _run_captured_pty_on_conn(
|
|
|
|
|
self,
|
|
|
|
|
cmd: list[str],
|
|
|
|
|
wd: str | None,
|
|
|
|
|
verbose: bool,
|
2026-04-15 14:02:44 +02:00
|
|
|
cmd_input: bytes | None,
|
2026-04-19 14:04:35 +02:00
|
|
|
mod_env: dict[str, str] | None,
|
2026-03-21 11:34:35 +01:00
|
|
|
log_prefix: str,
|
|
|
|
|
) -> Result:
|
2026-04-19 19:19:10 +02:00
|
|
|
|
|
|
|
|
conn = await self._conn
|
2026-03-21 11:34:35 +01:00
|
|
|
command = self._build_remote_command(cmd, wd)
|
|
|
|
|
|
|
|
|
|
stdout_parts: list[bytes] = []
|
2026-04-19 14:04:27 +02:00
|
|
|
stdout_log_enc = sys.stdout.encoding or 'utf-8'
|
2026-03-21 11:34:35 +01:00
|
|
|
|
|
|
|
|
proc = await conn.create_process(
|
2026-04-19 14:04:27 +02:00
|
|
|
command = command,
|
|
|
|
|
env = mod_env,
|
|
|
|
|
stdin = asyncssh.PIPE if cmd_input is not None else asyncssh.DEVNULL,
|
|
|
|
|
stdout = asyncssh.PIPE,
|
|
|
|
|
stderr = asyncssh.STDOUT,
|
|
|
|
|
encoding = None,
|
|
|
|
|
request_pty = 'force',
|
2026-04-19 19:52:18 +02:00
|
|
|
term_type = self.__term_type,
|
2026-03-21 11:34:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
task = asyncio.create_task(
|
|
|
|
|
self._read_stream(
|
|
|
|
|
proc.stdout,
|
|
|
|
|
NOTICE,
|
|
|
|
|
stdout_parts,
|
2026-04-19 14:04:27 +02:00
|
|
|
verbose = verbose,
|
|
|
|
|
log_prefix = log_prefix,
|
|
|
|
|
log_enc = stdout_log_enc,
|
2026-03-21 11:34:35 +01:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if cmd_input is not None and proc.stdin is not None:
|
2026-04-15 14:02:44 +02:00
|
|
|
proc.stdin.write(cmd_input)
|
2026-03-21 11:34:35 +01:00
|
|
|
await proc.stdin.drain()
|
|
|
|
|
proc.stdin.write_eof()
|
|
|
|
|
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
completed = await proc.wait(check = False)
|
2026-03-21 11:34:35 +01:00
|
|
|
await task
|
|
|
|
|
|
|
|
|
|
exit_code = completed.exit_status
|
|
|
|
|
if exit_code is None:
|
|
|
|
|
exit_code = completed.returncode if completed.returncode is not None else -1
|
|
|
|
|
|
2026-04-19 14:04:27 +02:00
|
|
|
stdout = b''.join(stdout_parts) if stdout_parts else None
|
2026-06-13 04:43:34 +02:00
|
|
|
return Result(stdout, None, exit_code, cmd = cmd)
|
2026-03-21 11:34:35 +01:00
|
|
|
|
App, lib, cmds: Fix mypy.explicit-override fallout
This commit adds @override decorators to approximately 300 methods
across 76 files that inherit from base classes such as AbstractCmd,
FileContext, ExecContext, Distro, SSHClient, and others.
The decorator ensures the type checker can verify that overridden
methods have compatible signatures and prevents accidental shadowing
of inherited methods without intent.
Files modified include command classes, library modules, distro
implementations, and SSH client implementations.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 15:51:14 +02:00
|
|
|
@override
|
2026-03-21 04:29:58 +01:00
|
|
|
async def _run_ssh(
|
|
|
|
|
self,
|
|
|
|
|
cmd: list[str],
|
|
|
|
|
wd: str | None,
|
|
|
|
|
verbose: bool,
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
cmd_input: bytes | None,
|
2026-04-19 14:04:35 +02:00
|
|
|
mod_env: dict[str, str] | None,
|
2026-03-21 04:29:58 +01:00
|
|
|
interactive: bool,
|
|
|
|
|
log_prefix: str,
|
|
|
|
|
) -> Result:
|
2026-04-19 19:52:18 +02:00
|
|
|
|
2026-04-19 14:04:35 +02:00
|
|
|
try:
|
2026-04-19 19:52:18 +02:00
|
|
|
if interactive:
|
|
|
|
|
if self._has_local_tty():
|
|
|
|
|
return await self._run_interactive_on_conn(
|
|
|
|
|
cmd = cmd,
|
|
|
|
|
wd = wd,
|
|
|
|
|
cmd_input = cmd_input,
|
|
|
|
|
mod_env = mod_env,
|
|
|
|
|
)
|
|
|
|
|
return await self._run_captured_pty_on_conn(
|
|
|
|
|
cmd = cmd,
|
|
|
|
|
wd = wd,
|
|
|
|
|
verbose = verbose,
|
|
|
|
|
cmd_input = cmd_input,
|
|
|
|
|
mod_env = mod_env,
|
|
|
|
|
log_prefix = log_prefix,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
command = self._build_remote_command(cmd, wd)
|
|
|
|
|
|
|
|
|
|
stdout_parts: list[bytes] = []
|
|
|
|
|
stderr_parts: list[bytes] = []
|
|
|
|
|
|
|
|
|
|
stdout_log_enc = sys.stdout.encoding or 'utf-8'
|
|
|
|
|
stderr_log_enc = sys.stderr.encoding or 'utf-8'
|
|
|
|
|
|
|
|
|
|
stdin_mode = asyncssh.PIPE if cmd_input is not None else asyncssh.DEVNULL
|
|
|
|
|
|
|
|
|
|
conn = await self._conn
|
|
|
|
|
|
|
|
|
|
proc = await conn.create_process(
|
|
|
|
|
command = command,
|
|
|
|
|
env = mod_env,
|
|
|
|
|
stdin = stdin_mode,
|
|
|
|
|
stdout = asyncssh.PIPE,
|
|
|
|
|
stderr = asyncssh.PIPE,
|
|
|
|
|
encoding = None,
|
|
|
|
|
request_pty = False,
|
2026-04-19 19:19:10 +02:00
|
|
|
)
|
2026-04-19 19:52:18 +02:00
|
|
|
|
|
|
|
|
tasks = [
|
|
|
|
|
asyncio.create_task(
|
|
|
|
|
self._read_stream(
|
|
|
|
|
proc.stdout,
|
|
|
|
|
NOTICE,
|
|
|
|
|
stdout_parts,
|
|
|
|
|
verbose = verbose,
|
|
|
|
|
log_prefix = log_prefix,
|
|
|
|
|
log_enc = stdout_log_enc,
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
asyncio.create_task(
|
|
|
|
|
self._read_stream(
|
|
|
|
|
proc.stderr,
|
|
|
|
|
ERR,
|
|
|
|
|
stderr_parts,
|
|
|
|
|
verbose = verbose,
|
|
|
|
|
log_prefix = log_prefix,
|
|
|
|
|
log_enc = stderr_log_enc,
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if cmd_input is not None and proc.stdin is not None:
|
|
|
|
|
proc.stdin.write(cmd_input)
|
|
|
|
|
await proc.stdin.drain()
|
|
|
|
|
proc.stdin.write_eof()
|
|
|
|
|
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
completed = await proc.wait(check = False)
|
2026-04-19 19:52:18 +02:00
|
|
|
await asyncio.gather(*tasks)
|
|
|
|
|
|
|
|
|
|
stdout = b''.join(stdout_parts) if stdout_parts else None
|
|
|
|
|
stderr = b''.join(stderr_parts) if stderr_parts else None
|
|
|
|
|
|
|
|
|
|
exit_code = completed.exit_status
|
|
|
|
|
if exit_code is None:
|
jw.pkg: Fix "make check" static code check fallout
The previous commits have put rules for linting and formatting via
ruff, yapf, mypy and pyright into place. They are checked with the
make check target, and this commit adds the fixes for the target to
succeed.
It does some refactoring where type checking dug up dirty bits, and
also adds lots of churn in the Python code. To a good deal, that's
owed to mere formatting changes. It would have been better to
seperate those from syntax and refactoring fixes into multiple
commits, so that the interesting changes don't drown in the
formatting nose. However, that would have been a lot of additional
work only to be thrown away by later commits, hence this commit has a
big diff in one piece. The size of the diff is regrettable but
hopefully a one-off: What it buys is automatic format checking for CI
and predictble formats for smaller diffs in the future.
Rules that "make check" enforces are, in the following order
- Syntax checkers:
- ruff check .
- mypy .
- pyright
- Format check:
- yapf --diff --recursive .
The refactoring includes:
- Turn the Result class into a more elaborate object, capable of
doing more heavy lifting around stderr and stdout decoding,
summarizing outcome, and matching error strings.
Aside from fixing broken type checks, this also removes lots of
boilerplate calling code which is currently used for handling
possible call outcome scenarios. Trying to access an inexistent,
decoded string should raise a meaningful exception by itself now,
which removes lots of code with case distinctions.
- Fix Cmd type hierarchy:
- Add the AbstractCmd class above Cmd. This is necessary because
the checker rightfully complains it can't instantiate a Cmd
instance where constructor arguments were needed. They never
were, but the type used at the instantiating code's location in
jw.pkg.App so claims.
- Lots of sub- and sub-subcommands are derived from the base
class of the invoking command. That provides some properties
shared across the ancestor hierarchy of a command, but is
semantically unsound. Fix that by introducing jw.pkg.BaseCmd
class as a place to provide basic helpers shared across all
commands used in a jw.pkg.App's context, and derive all command
classes from that afresh. The parent command is still reachable
via a common parent property.
Formatting changes are conforming to PEP-8, mostly, with minor
tweaks. All in all they include the following changes.
- Remove # -*- coding: utf-8 -*-
The line was needed by Python 2 which is not supported anylonger.
For Python 3, the default encoding is UTF-8, anyway.
- Allow to run "make py-format" without having it produce any
changes. It's basically "yapf --in-place --recursive ." with some
code style settings, see conf/topdir/pyproject.toml. The settings
may be debatable. I've had custom tweaks in place on that target,
too, but then again, IDEs would have more hassle to integrate
that.
- Introduce a 88 character line length limit
- One import per line, reshuffle them semantically, see
[tool.isort] in pyproject.toml.
- Hide imports needed for type-checking only behind
if TYPE_CHECKING
- Spaces around assignments accounts for much churn. Having having
no spaces in inline parameter list assignments and default
parameter values would arguably be more compact where it's
useful. On the other hand, I have not found a code formatter
which allows spaces around assignments in parameter lists broken
into one per line and that's often better than a wall of text.
- Add two spaces before # export, as this seems to be mandated by
PEP-8
- Use single quotes by default
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-05-27 07:16:05 +02:00
|
|
|
exit_code = (
|
|
|
|
|
completed.returncode if completed.returncode is not None else -1
|
|
|
|
|
)
|
2026-04-19 19:52:18 +02:00
|
|
|
|
2026-06-13 04:43:34 +02:00
|
|
|
return Result(stdout, stderr, exit_code, cmd = cmd)
|
2026-04-19 19:52:18 +02:00
|
|
|
|
2026-04-19 14:04:35 +02:00
|
|
|
except Exception as e:
|
2026-04-19 19:52:18 +02:00
|
|
|
log(ERR, f'Failed to run command {" ".join(cmd)} ({e})')
|
2026-04-19 14:04:35 +02:00
|
|
|
raise
|