Recent commits to derivepassphrase.git (d4a0d475385ea6bd9d559eb1cd23f2f98a259cf9) https://git.schokokeks.org/derivepassphrase.git/tree/d4a0d475385ea6bd9d559eb1cd23f2f98a259cf9 Recent commits feed provided by GitList. Merge topic branch 'logging' into master * t/logging: Document the switch to the logging and warning systems in the changelog https://git.schokokeks.org/derivepassphrase.git/commit/d4a0d475385ea6bd9d559eb1cd23f2f98a259cf9 software@the13thletter.info (Marco Ricci) Sun, 08 Dec 2024 19:03:08 +0100 d4a0d475385ea6bd9d559eb1cd23f2f98a259cf9 Document the switch to the logging and warning systems in the changelog https://git.schokokeks.org/derivepassphrase.git/commit/ad0fe1ec36de50d886fc4b0ed988203bc557c90f software@the13thletter.info (Marco Ricci) Sun, 08 Dec 2024 19:02:03 +0100 ad0fe1ec36de50d886fc4b0ed988203bc557c90f Refactor code to run under Python 3.9's LL(1) parser Though it does not do so by default, Python 3.9 can run with the old LL(1) parser instead of the PEG-based parser. Most importantly, the LL(1) parser does not support parenthesized context manager expressions, and this is why they have only become officially supported in Python 3.10, once the PEG-based parser became mandatory. Therefore, for compatibility, we replace every "proper" parenthesized context manager expression with equivalent explicit use of a `contextlib.ExitStack`, and every degenerate such expression by removing the parentheses. We now also explicitly test `derivepassphrase` with the LL(1) parser, for as long as Python 3.9 remains supported. While the use of a `contextlib.ExitStack` comes with additional runtime cost, by a lucky coincidence, all such proper usage of parenthesized context manager expressions is confined to the test suite, where we really don't care too much about slightly higher runtimes if it buys us more clarity, correctness and compatibility instead. https://git.schokokeks.org/derivepassphrase.git/commit/1ec3538850a7af2723f17b8ca8dfe93158b421cb software@the13thletter.info (Marco Ricci) Sun, 08 Dec 2024 17:44:25 +0100 1ec3538850a7af2723f17b8ca8dfe93158b421cb Merge topic branch 'logging' into master * t/logging: Adapt the test suite to use the logging system properly Emit new info messages and better debug messages in the exporter modules Use the logging system to emit warnings and error messages Shift option parsing and grouping machinery to a separate section Reimplement deprecated subcommands, properly, in `click` https://git.schokokeks.org/derivepassphrase.git/commit/c60c4077952fd420bc5ba0e86174e27289d96e2e software@the13thletter.info (Marco Ricci) Sun, 08 Dec 2024 12:36:36 +0100 c60c4077952fd420bc5ba0e86174e27289d96e2e Adapt the test suite to use the logging system properly Given the previous changes to warning and error reporting, the test suite needs new helper code to deal with them. Again, the changes to mosts tests are straight-forward (the location and formatting of messages changes slightly), but the new logging machinery itself now also needs to be tested... particularly the code that hooks into Python's logging system, into Python's warning system, and between those two. `pytest` actually includes test fixtures to capture and interact with warnings and logging calls, but these work on the library level: warnings are captured as warnings, logging calls are captured as log records. To be useful to application testing, it is necessary to inspect and assert both the low-level warnings/log records as well as the standard error output they ultimately translate to. The `hypothesis`-based tests need particular (manual) care, because `hypothesis` rejects tests using function-scoped `pytest` fixtures. https://git.schokokeks.org/derivepassphrase.git/commit/e1017eeffe4f16747629724b8f48ba298508ba80 software@the13thletter.info (Marco Ricci) Sat, 07 Dec 2024 09:30:38 +0100 e1017eeffe4f16747629724b8f48ba298508ba80 Emit new info messages and better debug messages in the exporter modules https://git.schokokeks.org/derivepassphrase.git/commit/5f2870876eb2317c57560fbbda87ed8f80917f97 software@the13thletter.info (Marco Ricci) Sat, 07 Dec 2024 09:30:38 +0100 5f2870876eb2317c57560fbbda87ed8f80917f97 Use the logging system to emit warnings and error messages Employ the Python standard library module `logging` to issue warning and error messages, as well as (partially new) debug messages. Operational warning messages and operational deprecation messages are handled via the `derivepassphrase` and `derivepassphrase.deprecation` loggers with a custom handler that prints the resulting formatted message to standard error. (Errors, info and debug messages use the same system, but differ slightly in the formatting.) Most of the rewriting of warnings and error messages to fit this new machinery is pretty straight-forward. The messy parts are the integration of the `logging` machinery and the `warnings` machinery into `click`, which isn't really designed with this in mind. Concretely, this entails writing a custom logging handler that uses `click.echo`, a custom formatter that prefixes messages with the program name (and "warning", "deprecation warning" or "debug" as necessary), a singleton configuration of this handler and formatter, various wrappers around standard `click` infrastructure to ensure that this integration code actually runs during normal operation, and finally, new command-line options to control the level of output on standard error. https://git.schokokeks.org/derivepassphrase.git/commit/aa248f1632393352772ba4d8969f6e983dc1a47b software@the13thletter.info (Marco Ricci) Sat, 07 Dec 2024 09:30:38 +0100 aa248f1632393352772ba4d8969f6e983dc1a47b Shift option parsing and grouping machinery to a separate section We expect to add new option categories that apply to multiple super- and subcommands, not just the "vault" subcommand. https://git.schokokeks.org/derivepassphrase.git/commit/6e2d2728b76c22a0d2280c34a55dba45885084cb software@the13thletter.info (Marco Ricci) Sat, 07 Dec 2024 08:50:03 +0100 6e2d2728b76c22a0d2280c34a55dba45885084cb Reimplement deprecated subcommands, properly, in `click` Our previous method of dispatching to subcommands was not tying the supercommand and the subcommand together properly; each command essentially ran in its own isolated context. This lead to unnecessary double-parsing of the command-line arguments, and to `click` becoming confused as to what the full command-line actually was; in particular, the help and usage messages gave a wrong command summary. Instead, we now use custom `click.Group` objects as the supercommands which default to the "vault" subcommand (with a deprecation warning) if no explicit subcommand could be matched, rather than throwing an error; this all happens internally using the normal mechanism for subcommand dispatch. Additionally, if the supercommand callback actually is invoked -- which only happens if the supercommand is given without any arguments -- we emit a deprecation warning and dispatch manually to the "vault" subcommand using the same code path as the `click` implementation would otherwise do. We assert that the old and new code paths work via new tests as necessary, particularly for the "supercommand without arguments" case. This implementation necessarily messes with some `click` internals, duplicating the code as it currently stands. Being a non-public API, there is of course no guarantee that this will work with future versions of `click`. However, we use this solely to implement a compatibility interface, which should vanish with `derivepassphrase` v1.0 anyway. The alternative -- rewriting `derivepassphrase` for another command-line framework, or rolling our own command-line interface from scratch -- seems even more expensive/wasteful than this solution. https://git.schokokeks.org/derivepassphrase.git/commit/10c7604bf033455d3e777bdeb028ee7d034a9bb7 software@the13thletter.info (Marco Ricci) Sat, 07 Dec 2024 08:50:03 +0100 10c7604bf033455d3e777bdeb028ee7d034a9bb7 Fix minor formatting quibbles in documentation and code style In particular, in online documentation builds, the URLs are slightly different, so the CSS rules weren't triggering correctly. https://git.schokokeks.org/derivepassphrase.git/commit/f2624c769d0c1bcf8596488f550e78e438e849e0 software@the13thletter.info (Marco Ricci) Thu, 28 Nov 2024 21:30:03 +0100 f2624c769d0c1bcf8596488f550e78e438e849e0