jw-pkg/src/python/jw/pkg/lib/App.py

285 lines
9.3 KiB
Python
Raw Normal View History

from __future__ import annotations
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 cProfile
import os
import sys
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 argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
from typing import TYPE_CHECKING, Any
from .AsyncRunner import AsyncRunner
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, set_log_flags, set_log_level
from .Types import LoadTypes
if TYPE_CHECKING:
from collections.abc import Awaitable
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 typing import TypeVar
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
T = TypeVar('T')
class App: # export
def _add_arguments(self, parser):
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.__parser.add_argument(
'--log-flags', help = 'Log flags', default = self.__default_log_flags
)
self.__parser.add_argument(
'--log-level', help = 'Log level', default = self.__default_log_level
)
self.__parser.add_argument(
'--log-file', help = 'Log file', default = self.__default_log_file
)
self.__parser.add_argument(
'--backtrace',
help = 'Show exception backtraces',
action = 'store_true',
default = self.__back_trace,
)
self.__parser.add_argument(
'--write-profile',
help = 'Profile code and store output to file',
default = 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
def __init__(
self,
description: str = '',
name_filter: str = '^Cmd.*',
modules: list[str] | None = None,
eloop: None = None,
) -> None:
def add_cmd_to_parser(cmd, parsers):
parser = parsers.add_parser(
cmd.name,
help = cmd.help,
description = cmd.description,
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
formatter_class = ArgumentDefaultsHelpFormatter,
)
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
parser.set_defaults(func = cmd.run)
cmd.add_arguments(parser)
cmd.set_parser(parser)
return parser
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
def add_cmds_to_parser(
parent: AbstractCmd | App,
parser: ArgumentParser,
cmds,
all = False
) -> None:
if not cmds:
return
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
class SubCommand:
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
def __init__(self, cmd: AbstractCmd, parser: Any):
self.cmd = cmd
self.parser = parser
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
title = 'Available subcommands'
if hasattr(parent, 'name'):
title += ' of ' + getattr(parent, 'name')
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
subparsers = parser.add_subparsers(
title = title, metavar = '', dest = 'command'
)
scs: dict[str, SubCommand] = {}
for cmd in cmds:
cmd.set_parent(parent)
scs[cmd.name] = SubCommand(cmd, add_cmd_to_parser(cmd, subparsers))
if all:
for sc in scs.values():
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
add_cmds_to_parser(sc.cmd, sc.parser, sc.cmd.children, all = all)
return
args, unknown = self.__parser.parse_known_args()
if args.command in scs:
sc = scs[args.command]
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
add_cmds_to_parser(sc.cmd, sc.parser, sc.cmd.children, all = all)
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 .Cmd import AbstractCmd
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.__args: Namespace | None = None
self.__cmdline: str | None = None
self.__default_log_flags: str = os.getenv(
'JW_DEFAULT_LOG_FLAGS', default = 'stderr,position,prio,color'
)
self.__default_log_level: str | int | None = os.getenv(
'JW_DEFAULT_LOG_LEVEL', default = NOTICE
)
self.__default_log_file: str | None = os.getenv(
'JW_DEFAULT_LOG_FILE', default = None
)
backtrace: str | bool = os.getenv('JW_DEFAULT_SHOW_BACKTRACE', False)
self.__back_trace = isinstance(backtrace, str) and backtrace.lower() in {
'1',
'true',
}
set_log_flags(self.__default_log_flags)
set_log_level(self.__default_log_level)
self.__eloop = eloop
self.__own_eloop = False
if eloop is None:
self.__eloop = asyncio.get_event_loop()
self.__own_eloop = True
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.__async_runner: AsyncRunner | None = 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
self.__parser = ArgumentParser(
formatter_class = ArgumentDefaultsHelpFormatter,
description = description,
add_help = False,
)
self._add_arguments(self.__parser)
args, unknown = self.__parser.parse_known_args()
set_log_flags(args.log_flags)
set_log_level(args.log_level)
log(DEBUG, '-------------- Running: >' + ' '.join(sys.argv) + '<')
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_classes = LoadTypes(
modules if modules else ['__main__'],
type_name_filter = name_filter,
type_filter = [AbstractCmd], # type: ignore[type-abstract]
)
add_all_parsers = (
'-h' in sys.argv or '--help' in sys.argv or '_ARGCOMPLETE' in os.environ
)
add_cmds_to_parser(
self,
self.__parser,
[cmd_class(self) for cmd_class in cmd_classes],
all = add_all_parsers,
)
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
# -- Add help only now, wouldn't want to have parse_known_args() exit
# on --help with subcommands missing
self.__parser.add_argument(
'-h', '--help', action = 'help', help = 'Show this help message and exit'
)
def __del__(self):
if self.__own_eloop:
if self.__eloop is not None:
self.__eloop.close()
self.__eloop = None
self.__own_eloop = False
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
async def __aenter__(self) -> None:
pass
async def __aexit__(self, exc_type, exc, tb) -> None:
pass
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
async def __run(self, argv = None) -> None:
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 argcomplete only here to not require it to be compatible
# with minimal environments
from argcomplete.completers import BaseCompleter # type: ignore[import-not-found]
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
class NoopCompleter(BaseCompleter):
def __call__(self, *args, **kwargs):
return 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
import argcomplete # type: ignore[import-not-found]
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
argcomplete.autocomplete(self.__parser, default_completer = NoopCompleter())
except Exception:
pass
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.__args = self.__parser.parse_args(args = argv)
set_log_flags(self.__args.log_flags)
set_log_level(self.__args.log_level)
self.__back_trace = self.__args.backtrace
exit_status = 0
if not hasattr(self.__args, 'func'):
self.__parser.print_help()
return None
pr = None if self.__args.write_profile is None else cProfile.Profile()
if pr is not None:
pr.enable()
try:
ret = await self._run(self.__args)
if isinstance(ret, int) and ret >= 0 and ret <= 0xFF:
exit_status = ret
except Exception as e:
log(ERR, 'Failed: {}'.format(repr(e) if self.__back_trace else str(e)))
exit_status = 1
# AssertionErrors are programming errors, hence a programmer should
# get a chance to figure it out
if self.__back_trace or isinstance(e, AssertionError):
raise
finally:
if pr is not None:
pr.disable()
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(
NOTICE,
f'Writing profile statistics to {self.__args.write_profile}'
)
assert self.__args.write_profile is not None, 'args.write_profile'
pr.dump_stats(self.__args.write_profile)
if exit_status:
sys.exit(exit_status)
# Run sub-command. Overwrite if you want to do anything before or after
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
async def _run(self, args: Namespace) -> None | int:
return await self.args.func(args)
def call_async(self, awaitable: Awaitable[T], timeout: float | None = None) -> T:
return self.async_runner.call(awaitable, timeout)
@property
def eloop(self) -> asyncio.AbstractEventLoop:
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
if self.__eloop is None:
raise Exception('Tried to get inexistent event loop from application')
return self.__eloop
@property
def async_runner(self) -> AsyncRunner:
if self.__async_runner is None:
self.__async_runner = AsyncRunner()
return self.__async_runner
@property
def cmdline(self) -> str:
if self.__cmdline 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
import shlex
with open('/proc/self/cmdline', 'rb') as f:
raw = f.read().split(b'\0')[:-1]
self.__cmdline = ' '.join(shlex.quote(arg.decode()) for arg in raw)
return self.__cmdline
@property
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
def args(self) -> Namespace:
if self.__args is None:
raise Exception('Tried to get inexistent argument list from application')
return self.__args
@property
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
def parser(self) -> ArgumentParser:
return self.__parser
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
def run(self, argv = None) -> None:
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
ret = self.eloop.run_until_complete(self.__run(argv))
finally:
if self.__async_runner:
self.__async_runner.close()
self.__async_runner = None
return ret
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
def run_sub_commands(
description = '', name_filter = '^Cmd.*', modules = None, argv = None
): # export
app = App(description, name_filter, modules)
return app.run(argv = argv)