Skip to content

Commit

Permalink
upgrade to python 3.12
Browse files Browse the repository at this point in the history
including updating linters
  • Loading branch information
apple1417 committed Jan 28, 2024
1 parent f8ac820 commit 99f5a84
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "[email protected]:bl-sdk/common_dotfiles.git",
"commit": "fb06ff8c773806b3f8cc69dbda60c0a7b481c6de",
"commit": "e5fa8d6e372d18cb22415511cc02831cc706e061",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
27 changes: 9 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
XWIN_VERSION: xwin-0.5.0-x86_64-unknown-linux-musl
XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.5.0/xwin-0.5.0-x86_64-unknown-linux-musl.tar.gz
# Python settings
PYTHON_VERSION: "3.11.5"
PYTHON_VERSION: "3.12.1"

jobs:
cache-clang:
Expand Down Expand Up @@ -352,19 +352,6 @@ jobs:
- name: Check spelling
uses: crate-ci/typos@master

black:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Check formatting
uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src"

pyright:
runs-on: ubuntu-latest

Expand All @@ -387,10 +374,16 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run Ruff
- name: Run Ruff Linting
uses: chartboost/ruff-action@v1
with:
src: ./src

- name: Run Ruff Formatting
uses: chartboost/ruff-action@v1
with:
src: "./src"
src: ./src
args: format --check

# ==============================================================================

Expand All @@ -407,7 +400,6 @@ jobs:
- clang-tidy
- clang-format
- spelling
- black
- pyright
- ruff

Expand Down Expand Up @@ -444,7 +436,6 @@ jobs:
- clang-tidy
- clang-format
- spelling
- black
- pyright
- ruff

Expand Down
32 changes: 26 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
[tool.black]
target-version = ["py311"]
line-length = 100

[tool.pyright]
pythonVersion = "3.11"
pythonVersion = "3.12"
typeCheckingMode = "strict"

include = ["src"]
stubPath = "libs/pyunrealsdk/stubs"
reportMissingModuleSource = false

[tool.ruff]
target-version = "py311"
target-version = "py312"
line-length = 100
select = [
"F",
Expand All @@ -25,13 +21,17 @@ select = [
"YTT",
"ANN",
"ASYNC",
"S",
"BLE",
"B",
"A",
"COM",
"C4",
"DTZ",
"T10",
"FA",
"ISC",
"ICN",
"G",
"PIE",
"PYI",
Expand All @@ -41,11 +41,19 @@ select = [
"SLOT",
"SIM",
"TID",
"TCH",
"INT",
"ARG",
"PTH",
"TD",
"FIX",
"ERA",
"PGH",
"PL",
"FLY",
"PERF",
"FURB",
"LOG",
"RUF",
]
ignore = [
Expand All @@ -69,11 +77,23 @@ ignore = [
"ANN101",
"ANN102",
"ANN401",
"S101",
"S603",
"S607",
"PYI011",
"PYI021",
"PYI029",
"PYI044",
"PGH003",
"PLR0904",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
"PLR6301",
"PLW0603",
"PLW2901",
"FURB140",
]

[tool.ruff.per-file-ignores]
Expand Down
9 changes: 6 additions & 3 deletions src/bl3_mod_menu/dialog_box.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from __future__ import annotations

from collections.abc import Callable, Sequence
from dataclasses import InitVar, dataclass, field
from typing import Any, ClassVar, Self
from typing import TYPE_CHECKING, Any, ClassVar, Self

from mods_base import ENGINE, hook
from unrealsdk import logging, make_struct
from unrealsdk.hooks import Block, Type
from unrealsdk.unreal import BoundFunction, UObject, WrappedStruct

from .native.dialog_box import show_dialog_box

if TYPE_CHECKING:
from collections.abc import Callable, Sequence

from unrealsdk.unreal import BoundFunction, UObject, WrappedStruct

# Track a stack incase someone opens a dialog while another is still open
_dialog_stack: list[DialogBox] = []

Expand Down
8 changes: 3 additions & 5 deletions src/bl3_mod_menu/native/options_getters.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import TypeAlias

from unrealsdk.unreal import UObject

_GbxGFxListItemComboBox: TypeAlias = UObject
_GbxGFxListItemNumber: TypeAlias = UObject
_GbxGFxListItemSpinner: TypeAlias = UObject
type _GbxGFxListItemComboBox = UObject
type _GbxGFxListItemNumber = UObject
type _GbxGFxListItemSpinner = UObject

__all__: tuple[str, ...] = (
"get_combo_box_selected_idx",
Expand Down
4 changes: 1 addition & 3 deletions src/bl3_mod_menu/native/options_setup.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import TypeAlias

from unrealsdk.unreal import UObject

_GFxOptionBase: TypeAlias = UObject
type _GFxOptionBase = UObject

__all__: tuple[str, ...] = (
"add_binding",
Expand Down
5 changes: 2 additions & 3 deletions src/bl3_mod_menu/native/options_transition.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from collections.abc import Callable
from typing import TypeAlias

from unrealsdk.unreal import UObject

_GFxMainAndPauseBaseMenu: TypeAlias = UObject
_GFxOptionBase: TypeAlias = UObject
type _GFxMainAndPauseBaseMenu = UObject
type _GFxOptionBase = UObject

__all__: tuple[str, ...] = ("open_custom_options",)

Expand Down
5 changes: 2 additions & 3 deletions src/bl3_mod_menu/native/outer_menu.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Callable
from typing import TypeAlias

from unrealsdk.unreal import UObject

Expand All @@ -11,8 +10,8 @@ __all__: tuple[str, ...] = (
"get_menu_state",
)

_AddMenuItemCallback: TypeAlias = Callable[[UObject, str, str, bool, int], int]
_GFxMainAndPauseBaseMenu: TypeAlias = UObject
type _AddMenuItemCallback = Callable[[UObject, str, str, bool, int], int]
type _GFxMainAndPauseBaseMenu = UObject

def add_menu_item(
self: _GFxMainAndPauseBaseMenu,
Expand Down
4 changes: 2 additions & 2 deletions src/bl3_mod_menu/options_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from mods_base import (
JSON,
BaseOption,
BoolOption,
ButtonOption,
Expand All @@ -12,7 +13,6 @@
ValueOption,
hook,
)
from mods_base.options import J
from unrealsdk.hooks import Block, Type
from unrealsdk.unreal import BoundFunction, UObject, WrappedStruct

Expand All @@ -29,7 +29,7 @@
)


def update_option_value(option: ValueOption[J], value: J) -> None:
def update_option_value[J: JSON](option: ValueOption[J], value: J) -> None:
"""
Updates an option's value, running the callback if needed.
Expand Down
11 changes: 7 additions & 4 deletions src/bl3_mod_menu/outer_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def add_menu_item_hook(
return idx


# If we have too many mods, they'll end up scrolling behind the news box
# To avoid this, add some dummy entries
# To make it less obvious, since they still have a highlight, only do so when there are too many
NUM_MODS_BEFORE_NEWS_PADDING: int = 8


def draw_mods_list(main_menu: UObject) -> None:
"""
Draws the mods list.
Expand All @@ -112,10 +118,7 @@ def draw_mods_list(main_menu: UObject) -> None:
formatted_name += f" <font size='20'>{mod.get_status()}</font>"
add_menu_item(main_menu, formatted_name, "OnInviteListClearClicked", False, -1)

# If we have too many mods, they'll end up scrolling behind the news box
# To avoid this, add some dummy entries
# To make it less obvious, since they still have a highlight, only do so when there are too many
if len(last_displayed_mod_list) > 8:
if len(last_displayed_mod_list) > NUM_MODS_BEFORE_NEWS_PADDING:
for _ in range(4):
add_menu_item(main_menu, "", "", True, -1)

Expand Down
2 changes: 1 addition & 1 deletion src/console_mod_menu/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def draw(msg: str, indent: int = 0) -> None:
"""
prefix = "Mod Menu | " + (" " * indent)

if msg == "":
if not msg:
print("Mod Menu |")
return

Expand Down
2 changes: 2 additions & 0 deletions src/console_mod_menu/key_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
# Unfortuantly, it doesn't seem to be exposed, so we manually replicate it instead
# Based on Python/suggestions.c:calculate_suggestions

# ruff: noqa: ERA001

MOVE_COST = 2
CASE_COST = 1
MAX_STRING_SIZE = 40
Expand Down
6 changes: 2 additions & 4 deletions src/console_mod_menu/option_formatting.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from typing import TypeVar, overload
from typing import overload

from mods_base import JSON, BaseOption, BoolOption, KeybindOption, ValueOption

from .draw import draw
from .screens import draw_stack_header

J = TypeVar("J", bound=JSON)


@overload
def get_option_value_str(option: ValueOption[J]) -> str:
def get_option_value_str[J: JSON](option: ValueOption[J]) -> str:
...


Expand Down
10 changes: 4 additions & 6 deletions src/console_mod_menu/screens/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

from abc import abstractmethod
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Generic, TypeVar
from typing import TYPE_CHECKING

from mods_base import (
JSON,
BaseOption,
BoolOption,
ButtonOption,
DropdownOption,
Expand All @@ -21,12 +19,12 @@

from . import AbstractScreen, draw_standard_commands, handle_standard_command_input

T = TypeVar("T", bound=BaseOption)
J = TypeVar("J", bound=JSON)
if TYPE_CHECKING:
from mods_base import JSON, BaseOption


@dataclass
class OptionScreen(AbstractScreen, Generic[T, J]):
class OptionScreen[T: BaseOption, J: JSON](AbstractScreen):
name: str = field(init=False)
mod: Mod
option: T
Expand Down
29 changes: 13 additions & 16 deletions src/keybinds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

from .keybinds import deregister_keybind, register_keybind

# from mods_base.raw_keybinds import raw_keybind_callback_stack

__all__: tuple[str, ...] = (
"__author__",
"__version__",
Expand Down Expand Up @@ -86,21 +84,20 @@ def enable_raw_keybind(self: RawKeybind) -> None:
False,
cast(RawKeybindCallback_KeyOnly, self.callback),
)
elif self.event is None:
handle = register_keybind(
self.key,
self.event,
False,
cast(RawKeybindCallback_EventOnly, self.callback),
)
else:
if self.event is None:
handle = register_keybind(
self.key,
self.event,
False,
cast(RawKeybindCallback_EventOnly, self.callback),
)
else:
handle = register_keybind(
self.key,
self.event,
False,
cast(RawKeybindCallback_NoArgs, self.callback),
)
handle = register_keybind(
self.key,
self.event,
False,
cast(RawKeybindCallback_NoArgs, self.callback),
)

self._kb_handle = handle # type: ignore

Expand Down
Loading

0 comments on commit 99f5a84

Please sign in to comment.