From 421b05ec61babfc281fccda37c0640f6c4a973b4 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Fri, 25 Oct 2024 23:08:15 +0100 Subject: [PATCH 1/3] Add generated types for `c` in `config.py` --- qutebrowser/config/configcontainer_types.py | 2492 +++++++++++++++++++ qutebrowser/config/configtypes.py | 112 + scripts/dev/generate_config_types.py | 160 ++ scripts/dev/run_vulture.py | 3 +- scripts/dev/src2asciidoc.py | 3 + tests/unit/config/test_configtypes.py | 7 + 6 files changed, 2776 insertions(+), 1 deletion(-) create mode 100644 qutebrowser/config/configcontainer_types.py create mode 100644 scripts/dev/generate_config_types.py diff --git a/qutebrowser/config/configcontainer_types.py b/qutebrowser/config/configcontainer_types.py new file mode 100644 index 000000000..1f9f870c0 --- /dev/null +++ b/qutebrowser/config/configcontainer_types.py @@ -0,0 +1,2492 @@ +# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# DO NOT EDIT THIS FILE DIRECTLY! +# It is autogenerated by running: +# $ python3 scripts/dev/src2asciidoc.py +# vim: readonly: + +"""This file defines static types for the `c` variable in `config.py`. + +This is auto-generated from the `scripts/dev/generate_config_types.py` file. + +It is not intended to be used at runtime. + +Example usage: +```py +from typing import TYPE_CHECKING, cast + +if TYPE_CHECKING: + from qutebrowser.config.configfiles import ConfigAPI + from qutebrowser.config.configcontainer import ConfigContainer + + # note: these expressions aren't executed at runtime + c = cast(ConfigContainer, ...) + config = cast(ConfigAPI, ...) +``` +""" + +# pylint: disable=line-too-long, invalid-name + +import re +from dataclasses import dataclass +from collections.abc import Mapping +from typing import Optional, Union, Literal + + +@dataclass +class ConfigContainer: + """Type for the `c` variable in `config.py`.""" + + aliases: Optional[Mapping[str, str]] + """Aliases for commands. + + The keys of the given dictionary are the aliases, while the values are the commands they map to. + """ + + confirm_quit: list[Literal["always", "multiple-tabs", "downloads", "never"]] + """Require a confirmation before quitting the application.""" + + history_gap_interval: int + """Maximum time (in minutes) between two history items for them to be considered being from the same browsing session. + + Items with less time between them are grouped when being displayed in `:history`. Use -1 to disable separation. + """ + + changelog_after_upgrade: Literal["major", "minor", "patch", "never"] + """When to show a changelog after qutebrowser was upgraded.""" + + search: "_Search" + + @dataclass + class _Search: + ignore_case: Literal["always", "never", "smart"] + """When to find text on a page case-insensitively.""" + + incremental: bool + """Find text on a page incrementally, renewing the search for each typed character.""" + + wrap: bool + """Wrap around at the top and bottom of the page when advancing through text matches using `:search-next` and `:search-prev`.""" + + wrap_messages: bool + """Display messages when advancing through text matches at the top and bottom of the page, e.g. `Search hit TOP`.""" + + new_instance_open_target: Literal[ + "tab", "tab-bg", "tab-silent", "tab-bg-silent", "window", "private-window" + ] + """How to open links in an existing instance if a new one is launched. + + This happens when e.g. opening a link from a terminal. + + See `new_instance_open_target_window` to customize in which window the link is opened in. + """ + + new_instance_open_target_window: Literal[ + "first-opened", "last-opened", "last-focused", "last-visible" + ] + """Which window to choose when opening links as new tabs. + + When `new_instance_open_target` is set to `window`, this is ignored. + """ + + session: "_Session" + + @dataclass + class _Session: + default_name: Optional[Optional[str]] + """Name of the session to save by default. + + If this is set to null, the session which was last loaded is saved. + """ + + lazy_restore: bool + """Load a restored tab as soon as it takes focus.""" + + backend: Literal["webengine", "webkit"] + """Backend to use to display websites. + + qutebrowser supports two different web rendering engines / backends, QtWebEngine and QtWebKit (not recommended). + + QtWebEngine is Qt's official successor to QtWebKit, and both the default/recommended backend. It's based on a stripped-down Chromium and regularly updated with security fixes and new features by the Qt project: https://wiki.qt.io/QtWebEngine + + QtWebKit was qutebrowser's original backend when the project was started. However, support for QtWebKit was discontinued by the Qt project with Qt 5.6 in 2016. The development of QtWebKit was picked up in an official fork: https://github.com/qtwebkit/qtwebkit - however, the project seems to have stalled again. The latest release (5.212.0 Alpha 4) from March 2020 is based on a WebKit version from 2016, with many known security vulnerabilities. Additionally, there is no process isolation and sandboxing. Due to all those issues, while support for QtWebKit is still available in qutebrowser for now, using it is strongly discouraged. + """ + + qt: "_Qt" + + @dataclass + class _Qt: + args: Optional[list[str]] + """Additional arguments to pass to Qt, without leading `--`. + + With QtWebEngine, some Chromium arguments (see https://peter.sh/experiments/chromium-command-line-switches/ for a list) will work. + """ + + environ: Optional[Mapping[str, Optional[str]]] + """Additional environment variables to set. + + Setting an environment variable to null/None will unset it. + """ + + force_software_rendering: Literal[ + "software-opengl", "qt-quick", "chromium", "none" + ] + """Force software rendering for QtWebEngine. + + This is needed for QtWebEngine to work with Nouveau drivers and can be useful in other scenarios related to graphic issues. + """ + + force_platform: Optional[Optional[str]] + """Force a Qt platform to use. + + This sets the `QT_QPA_PLATFORM` environment variable and is useful to force using the XCB plugin when running QtWebEngine on Wayland. + """ + + force_platformtheme: Optional[Optional[str]] + """Force a Qt platformtheme to use. + + This sets the `QT_QPA_PLATFORMTHEME` environment variable which controls dialogs like the filepicker. By default, Qt determines the platform theme based on the desktop environment. + """ + + chromium: "_Chromium" + + @dataclass + class _Chromium: + process_model: Literal[ + "process-per-site-instance", "process-per-site", "single-process" + ] + """Which Chromium process model to use. + + Alternative process models use less resources, but decrease security and robustness. + + See the following pages for more details: + + + + - https://www.chromium.org/developers/design-documents/process-models + + - https://doc.qt.io/qt-6/qtwebengine-features.html#process-models + """ + + low_end_device_mode: Literal["always", "auto", "never"] + """When to use Chromium's low-end device mode. + + This improves the RAM usage of renderer processes, at the expense of performance. + """ + + sandboxing: Literal["enable-all", "disable-seccomp-bpf", "disable-all"] + """What sandboxing mechanisms in Chromium to use. + + Chromium has various sandboxing layers, which should be enabled for normal browser usage. Mainly for testing and development, it's possible to disable individual sandboxing layers via this setting. + + Open `chrome://sandbox` to see the current sandbox status. + + Changing this setting is only recommended if you know what you're doing, as it **disables one of Chromium's security layers**. To avoid sandboxing being accidentally disabled persistently, this setting can only be set via `config.py`, not via `:set`. + + See the Chromium documentation for more details: + + - https://chromium.googlesource.com/chromium/src/\\+/HEAD/docs/linux/sandboxing.md[Linux] - https://chromium.googlesource.com/chromium/src/\\+/HEAD/docs/design/sandbox.md[Windows] - https://chromium.googlesource.com/chromium/src/\\+/HEAD/docs/design/sandbox_faq.md[FAQ (Windows-centric)] + """ + + experimental_web_platform_features: Literal["always", "auto", "never"] + """Enables Web Platform features that are in development. + + This passes the `--enable-experimental-web-platform-features` flag to Chromium. By default, this is enabled with Qt 5 to maximize compatibility despite an aging Chromium base. + """ + + highdpi: bool + """Turn on Qt HighDPI scaling. + + This is equivalent to setting QT_ENABLE_HIGHDPI_SCALING=1 (Qt >= 5.14) in the environment. + + It's off by default as it can cause issues with some bitmap fonts. As an alternative to this, it's possible to set font sizes and the `zoom.default` setting. + """ + + workarounds: "_Workarounds" + + @dataclass + class _Workarounds: + remove_service_workers: bool + """Delete the QtWebEngine Service Worker directory on every start. + + This workaround can help with certain crashes caused by an unknown QtWebEngine bug related to Service Workers. Those crashes happen seemingly immediately on Windows; after one hour of operation on other systems. + + Note however that enabling this option *can lead to data loss* on some pages (as Service Worker data isn't persisted) and will negatively impact start-up time. + """ + + locale: bool + """Work around locale parsing issues in QtWebEngine 5.15.3. + + With some locales, QtWebEngine 5.15.3 is unusable without this workaround. In affected scenarios, QtWebEngine will log "Network service crashed, restarting service." and only display a blank page. + + However, It is expected that distributions shipping QtWebEngine 5.15.3 follow up with a proper fix soon, so it is disabled by default. + """ + + disable_accelerated_2d_canvas: Literal["always", "auto", "never"] + """Disable accelerated 2d canvas to avoid graphical glitches. + + On some setups graphical issues can occur on sites like Google sheets and PDF.js. These don't occur when accelerated 2d canvas is turned off, so we do that by default. + + So far these glitches only occur on some Intel graphics devices. + """ + + disable_hangouts_extension: bool + """Disable the Hangouts extension. + + The Hangouts extension provides additional APIs for Google domains only. + + Hangouts has been replaced with Meet, which appears to work without this extension. + + Note this setting gets ignored and the Hangouts extension is always disabled to avoid crashes on Qt 6.5.0 to 6.5.3 if dark mode is enabled, as well as on Qt 6.6.0. + """ + + auto_save: "_AutoSave" + + @dataclass + class _AutoSave: + interval: int + """Time interval (in milliseconds) between auto-saves of config/cookies/etc.""" + + session: bool + """Always restore open sites when qutebrowser is reopened. + + Without this option set, `:wq` (`:quit --save`) needs to be used to save open tabs (and restore them), while quitting qutebrowser in any other way will not save/restore the session. + + By default, this will save to the session which was last loaded. This behavior can be customized via the `session.default_name` setting. + """ + + content: "_Content" + + @dataclass + class _Content: + autoplay: bool + """Automatically start playing `