diff --git a/.github/workflows/dependency.yml b/.github/workflows/dependency.yml index 774850df..f1816605 100644 --- a/.github/workflows/dependency.yml +++ b/.github/workflows/dependency.yml @@ -17,4 +17,4 @@ jobs: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - name: Automatically approve the PR - uses: hmarr/auto-approve-action@v4 \ No newline at end of file + uses: hmarr/auto-approve-action@v4 diff --git a/pyproject.toml b/pyproject.toml index fcbd4333..87485a30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,11 +64,34 @@ filterwarnings = [ [tool.ruff] line-length = 120 -lint.select = ["E", "F", "W", "C90", "I", "UP"] src = ["src"] -# Version to target for generated code. -target-version = "py310" +[tool.ruff.lint] +select = [ + "E", "F", "W", "C90", "I", "UP", "C4", + "RSE", + "TCH", + # "PTH", + "COM818", "COM819", + "ISC", + "PIE", + # "PT", + + "PLC", + "PLC0208", # iterating over set is also not deterministic, so we shouldn't do that! + + "PLE", + "PLR0402", "PLR1711", "PLR1722", "PLR0206", "PLR0133", "PLR0124", + "PLW", + "SIM101", +] +extend-ignore = [ + "ISC001", # may cause conflicts with formatter + "PLW2901", # `for` loop variable `key` overwritten by assignment target +] + +[tool.ruff.lint.isort] +required-imports = ["from __future__ import annotations"] [tool.ruff.lint.mccabe] # Flag errors (`C901`) whenever the complexity level exceeds 25. diff --git a/setup.py b/setup.py index 6ff6d170..900ead58 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import subprocess import sys diff --git a/src/mercury_engine_data_structures/__main__.py b/src/mercury_engine_data_structures/__main__.py index 3c2f77b3..7b7ecfe4 100644 --- a/src/mercury_engine_data_structures/__main__.py +++ b/src/mercury_engine_data_structures/__main__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from mercury_engine_data_structures import cli if __name__ == "__main__": diff --git a/src/mercury_engine_data_structures/__pyinstaller/__init__.py b/src/mercury_engine_data_structures/__pyinstaller/__init__.py index 2e6eb36f..efa30f5e 100644 --- a/src/mercury_engine_data_structures/__pyinstaller/__init__.py +++ b/src/mercury_engine_data_structures/__pyinstaller/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os # Functions diff --git a/src/mercury_engine_data_structures/__pyinstaller/hook-mercury_engine_data_structures.py b/src/mercury_engine_data_structures/__pyinstaller/hook-mercury_engine_data_structures.py index 43b3b311..379cb8ed 100644 --- a/src/mercury_engine_data_structures/__pyinstaller/hook-mercury_engine_data_structures.py +++ b/src/mercury_engine_data_structures/__pyinstaller/hook-mercury_engine_data_structures.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from PyInstaller.utils.hooks import collect_data_files # https://pyinstaller.readthedocs.io/en/stable/hooks.html#provide-hooks-with-package diff --git a/src/mercury_engine_data_structures/_dread_data_construct.py b/src/mercury_engine_data_structures/_dread_data_construct.py index 5a90a66b..e3a6cdab 100644 --- a/src/mercury_engine_data_structures/_dread_data_construct.py +++ b/src/mercury_engine_data_structures/_dread_data_construct.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import struct import construct diff --git a/src/mercury_engine_data_structures/adapters/enum_adapter.py b/src/mercury_engine_data_structures/adapters/enum_adapter.py index 8e831371..0d94b03b 100644 --- a/src/mercury_engine_data_structures/adapters/enum_adapter.py +++ b/src/mercury_engine_data_structures/adapters/enum_adapter.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from construct import Adapter, Enum, Int32ub diff --git a/src/mercury_engine_data_structures/adapters/offset.py b/src/mercury_engine_data_structures/adapters/offset.py index b5d7a63d..2b1e9f3e 100644 --- a/src/mercury_engine_data_structures/adapters/offset.py +++ b/src/mercury_engine_data_structures/adapters/offset.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from construct import AdaptationError, Adapter @@ -5,10 +7,10 @@ class OffsetAdapter(Adapter): # stores offsets as indices def _get_table(self, context): - raise NotImplementedError() + raise NotImplementedError def _get_table_length(self, context): - raise NotImplementedError() + raise NotImplementedError def _get_base_offset(self, context): return 0 diff --git a/src/mercury_engine_data_structures/formats/base_resource.py b/src/mercury_engine_data_structures/base_resource.py similarity index 90% rename from src/mercury_engine_data_structures/formats/base_resource.py rename to src/mercury_engine_data_structures/base_resource.py index 8b5ed30b..f14d83fc 100644 --- a/src/mercury_engine_data_structures/formats/base_resource.py +++ b/src/mercury_engine_data_structures/base_resource.py @@ -2,14 +2,12 @@ import typing -from construct import Construct, Container - -from mercury_engine_data_structures.game_check import Game - if typing.TYPE_CHECKING: import typing_extensions + from construct import Construct, Container from mercury_engine_data_structures.file_tree_editor import FileTreeEditor + from mercury_engine_data_structures.game_check import Game class BaseResource: @@ -24,7 +22,7 @@ def __init__(self, raw: Container, target_game: Game, editor: FileTreeEditor | N @classmethod def construct_class(cls, target_game: Game) -> Construct: - raise NotImplementedError() + raise NotImplementedError @classmethod def parse(cls, data: bytes, target_game: Game, editor: FileTreeEditor | None = None) -> typing_extensions.Self: diff --git a/src/mercury_engine_data_structures/cli.py b/src/mercury_engine_data_structures/cli.py index 299e4631..c56c6e2b 100644 --- a/src/mercury_engine_data_structures/cli.py +++ b/src/mercury_engine_data_structures/cli.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import asyncio import itertools diff --git a/src/mercury_engine_data_structures/common_types.py b/src/mercury_engine_data_structures/common_types.py index e1102c74..86583799 100644 --- a/src/mercury_engine_data_structures/common_types.py +++ b/src/mercury_engine_data_structures/common_types.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy import functools import struct diff --git a/src/mercury_engine_data_structures/construct_extensions/__init__.py b/src/mercury_engine_data_structures/construct_extensions/__init__.py index 559fe9cf..04ec4078 100644 --- a/src/mercury_engine_data_structures/construct_extensions/__init__.py +++ b/src/mercury_engine_data_structures/construct_extensions/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import operator import construct.expr diff --git a/src/mercury_engine_data_structures/construct_extensions/alignment.py b/src/mercury_engine_data_structures/construct_extensions/alignment.py index f15016a3..23ebc5d9 100644 --- a/src/mercury_engine_data_structures/construct_extensions/alignment.py +++ b/src/mercury_engine_data_structures/construct_extensions/alignment.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import io import construct diff --git a/src/mercury_engine_data_structures/construct_extensions/enum.py b/src/mercury_engine_data_structures/construct_extensions/enum.py index 84e157ab..13bb173b 100644 --- a/src/mercury_engine_data_structures/construct_extensions/enum.py +++ b/src/mercury_engine_data_structures/construct_extensions/enum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import enum import construct diff --git a/src/mercury_engine_data_structures/construct_extensions/function_complex.py b/src/mercury_engine_data_structures/construct_extensions/function_complex.py index 7203be26..0925c273 100644 --- a/src/mercury_engine_data_structures/construct_extensions/function_complex.py +++ b/src/mercury_engine_data_structures/construct_extensions/function_complex.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import re import construct diff --git a/src/mercury_engine_data_structures/construct_extensions/json.py b/src/mercury_engine_data_structures/construct_extensions/json.py index 0e0ba64a..4128241e 100644 --- a/src/mercury_engine_data_structures/construct_extensions/json.py +++ b/src/mercury_engine_data_structures/construct_extensions/json.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any from construct import EnumIntegerString diff --git a/src/mercury_engine_data_structures/construct_extensions/misc.py b/src/mercury_engine_data_structures/construct_extensions/misc.py index 1ce273da..b32f952a 100644 --- a/src/mercury_engine_data_structures/construct_extensions/misc.py +++ b/src/mercury_engine_data_structures/construct_extensions/misc.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct import Const, Construct, FocusedSeq, Optional, stream_tell diff --git a/src/mercury_engine_data_structures/construct_extensions/strings.py b/src/mercury_engine_data_structures/construct_extensions/strings.py index 32e51178..77088dca 100644 --- a/src/mercury_engine_data_structures/construct_extensions/strings.py +++ b/src/mercury_engine_data_structures/construct_extensions/strings.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct.core import ( FixedSized, @@ -50,7 +52,7 @@ def PaddedStringRobust(length, encoding): macro = StringEncodedRobust(FixedSized(length, NullStripped(GreedyBytes, pad=encodingunit(encoding))), encoding) def _emitfulltype(ksy, bitwise): - return dict(size=length, type="strz", encoding=encoding) + return {"size": length, "type": "strz", "encoding": encoding} macro._emitfulltype = _emitfulltype return macro @@ -86,8 +88,8 @@ def _emitparse(code): def _emitseq(ksy, bitwise): return [ - dict(id="lengthfield", type=lengthfield._compileprimitivetype(ksy, bitwise)), - dict(id="data", size="lengthfield", type="str", encoding=encoding), + {"id": "lengthfield", "type": lengthfield._compileprimitivetype(ksy, bitwise)}, + {"id": "data", "size": "lengthfield", "type": "str", "encoding": encoding}, ] macro._emitseq = _emitseq @@ -176,7 +178,7 @@ def read_util_term_{i}(io, this): macro._emitparse = _emitparse def _emitfulltype(ksy, bitwise): - return dict(type="strz", encoding=encoding) + return {"type": "strz", "encoding": encoding} macro._emitfulltype = _emitfulltype @@ -210,7 +212,7 @@ def GreedyStringRobust(encoding): macro = StringEncodedRobust(GreedyBytes, encoding) def _emitfulltype(ksy, bitwise): - return dict(size_eos=True, type="str", encoding=encoding) + return {"size_eos": True, "type": "str", "encoding": encoding} macro._emitfulltype = _emitfulltype return macro diff --git a/src/mercury_engine_data_structures/construct_extensions/version.py b/src/mercury_engine_data_structures/construct_extensions/version.py index 5c8f1871..cd713f75 100644 --- a/src/mercury_engine_data_structures/construct_extensions/version.py +++ b/src/mercury_engine_data_structures/construct_extensions/version.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import enum from functools import partial diff --git a/src/mercury_engine_data_structures/crc.py b/src/mercury_engine_data_structures/crc.py index 419a7bd3..51163de5 100644 --- a/src/mercury_engine_data_structures/crc.py +++ b/src/mercury_engine_data_structures/crc.py @@ -2,6 +2,8 @@ Module for calculating CRC hashes with the algorithm and data used by Mercury Engine. """ +from __future__ import annotations + _crc32_constants = [ 0x00000000, 0x77073096, diff --git a/src/mercury_engine_data_structures/dread_data.py b/src/mercury_engine_data_structures/dread_data.py index 8720d365..c6fc46e9 100644 --- a/src/mercury_engine_data_structures/dread_data.py +++ b/src/mercury_engine_data_structures/dread_data.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import json import typing diff --git a/src/mercury_engine_data_structures/file_tree_editor.py b/src/mercury_engine_data_structures/file_tree_editor.py index 0f646c8c..1c6781c4 100644 --- a/src/mercury_engine_data_structures/file_tree_editor.py +++ b/src/mercury_engine_data_structures/file_tree_editor.py @@ -1,20 +1,25 @@ +from __future__ import annotations + import copy import enum import json import logging import os.path import typing -from collections.abc import Iterator -from pathlib import Path - -import construct from mercury_engine_data_structures import dread_data, formats, samus_returns_data +from mercury_engine_data_structures.base_resource import AssetId, BaseResource, NameOrAssetId, resolve_asset_id from mercury_engine_data_structures.formats import Toc -from mercury_engine_data_structures.formats.base_resource import AssetId, BaseResource, NameOrAssetId, resolve_asset_id from mercury_engine_data_structures.formats.pkg import Pkg from mercury_engine_data_structures.game_check import Game -from mercury_engine_data_structures.romfs import RomFs + +if typing.TYPE_CHECKING: + from collections.abc import Iterator + from pathlib import Path + + import construct + + from mercury_engine_data_structures.romfs import RomFs _T = typing.TypeVar("_T", bound=BaseResource) logger = logging.getLogger(__name__) diff --git a/src/mercury_engine_data_structures/formats/__init__.py b/src/mercury_engine_data_structures/formats/__init__.py index 760e7d45..37ba59b7 100644 --- a/src/mercury_engine_data_structures/formats/__init__.py +++ b/src/mercury_engine_data_structures/formats/__init__.py @@ -1,5 +1,8 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from mercury_engine_data_structures.formats.bapd import Bapd -from mercury_engine_data_structures.formats.base_resource import AssetType, BaseResource from mercury_engine_data_structures.formats.bcmdl import Bcmdl from mercury_engine_data_structures.formats.bcskla import Bcskla from mercury_engine_data_structures.formats.bctex import Bctex @@ -47,6 +50,9 @@ from mercury_engine_data_structures.formats.toc import Toc from mercury_engine_data_structures.formats.txt import Txt +if TYPE_CHECKING: + from mercury_engine_data_structures.base_resource import AssetType, BaseResource + ALL_FORMATS = { "PKG": Pkg, "BAPD": Bapd, diff --git a/src/mercury_engine_data_structures/formats/bapd.py b/src/mercury_engine_data_structures/formats/bapd.py index 936607bc..f329e2b3 100644 --- a/src/mercury_engine_data_structures/formats/bapd.py +++ b/src/mercury_engine_data_structures/formats/bapd.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations -from mercury_engine_data_structures.formats.base_resource import BaseResource +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats.standard_format import game_model -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game BAPD = game_model("sound::CAudioPresets", "2.3.2") diff --git a/src/mercury_engine_data_structures/formats/bcmdl.py b/src/mercury_engine_data_structures/formats/bcmdl.py index be629545..2f5b6298 100644 --- a/src/mercury_engine_data_structures/formats/bcmdl.py +++ b/src/mercury_engine_data_structures/formats/bcmdl.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import construct from construct.core import ( Array, @@ -24,9 +28,11 @@ stream_seek, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Float, StrId -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game # Partial implementation to generate material variants # Based off Joschuka's MMDL implementation in Noesis diff --git a/src/mercury_engine_data_structures/formats/bcskla.py b/src/mercury_engine_data_structures/formats/bcskla.py index a957583a..fedf6bf9 100644 --- a/src/mercury_engine_data_structures/formats/bcskla.py +++ b/src/mercury_engine_data_structures/formats/bcskla.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct.core import ( Adapter, @@ -20,9 +22,9 @@ this, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Float, VersionAdapter from mercury_engine_data_structures.construct_extensions.alignment import AlignTo -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.property_enum import PropertyEnumDoubleUnsafe from mercury_engine_data_structures.game_check import Game diff --git a/src/mercury_engine_data_structures/formats/bctex.py b/src/mercury_engine_data_structures/formats/bctex.py index 080b381b..483b1a33 100644 --- a/src/mercury_engine_data_structures/formats/bctex.py +++ b/src/mercury_engine_data_structures/formats/bctex.py @@ -1,10 +1,12 @@ +from __future__ import annotations + from enum import Enum import construct from construct.core import Error +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, UInt -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game BlockType = construct.Enum( diff --git a/src/mercury_engine_data_structures/formats/bgsnds.py b/src/mercury_engine_data_structures/formats/bgsnds.py index 3fef394b..e3c9efa9 100644 --- a/src/mercury_engine_data_structures/formats/bgsnds.py +++ b/src/mercury_engine_data_structures/formats/bgsnds.py @@ -1,8 +1,14 @@ -from construct import Construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct + + from mercury_engine_data_structures.game_check import Game class Bgsnds(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/bldef.py b/src/mercury_engine_data_structures/formats/bldef.py index 15177b01..8d0ae0f2 100644 --- a/src/mercury_engine_data_structures/formats/bldef.py +++ b/src/mercury_engine_data_structures/formats/bldef.py @@ -1,8 +1,14 @@ -from construct import Construct, Container +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct, Container + + from mercury_engine_data_structures.game_check import Game class Bldef(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/blsnd.py b/src/mercury_engine_data_structures/formats/blsnd.py index 317d173b..8a2b22eb 100644 --- a/src/mercury_engine_data_structures/formats/blsnd.py +++ b/src/mercury_engine_data_structures/formats/blsnd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import construct @@ -9,8 +11,8 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game, current_game_at_most BLSND = Struct( diff --git a/src/mercury_engine_data_structures/formats/blut.py b/src/mercury_engine_data_structures/formats/blut.py index 5187183a..8242d319 100644 --- a/src/mercury_engine_data_structures/formats/blut.py +++ b/src/mercury_engine_data_structures/formats/blut.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from construct.core import Const, Construct, Int32ul, PrefixedArray, Struct +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Float, VersionAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game BLUT = Struct(magic=Const(b"LUT"), ver=VersionAdapter("1.1.0"), data=PrefixedArray(Int32ul, Float)) diff --git a/src/mercury_engine_data_structures/formats/bmbls.py b/src/mercury_engine_data_structures/formats/bmbls.py index fc78942e..bf3f9ebf 100644 --- a/src/mercury_engine_data_structures/formats/bmbls.py +++ b/src/mercury_engine_data_structures/formats/bmbls.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game BMBLS = standard_format.create("base::animation::CBlendSpaceResource", "1.2.2") diff --git a/src/mercury_engine_data_structures/formats/bmdefs.py b/src/mercury_engine_data_structures/formats/bmdefs.py index ac3173b9..5f13ad57 100644 --- a/src/mercury_engine_data_structures/formats/bmdefs.py +++ b/src/mercury_engine_data_structures/formats/bmdefs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct import ( Const, @@ -8,9 +10,9 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game EnemyStruct = Struct( diff --git a/src/mercury_engine_data_structures/formats/bmmap.py b/src/mercury_engine_data_structures/formats/bmmap.py index 26319173..9039cfe7 100644 --- a/src/mercury_engine_data_structures/formats/bmmap.py +++ b/src/mercury_engine_data_structures/formats/bmmap.py @@ -1,10 +1,15 @@ -import functools +from __future__ import annotations -from construct import Construct, Container +import functools +from typing import TYPE_CHECKING +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct, Container + + from mercury_engine_data_structures.game_check import Game BMMAP = standard_format.create("CMinimapData", "1.0.2") diff --git a/src/mercury_engine_data_structures/formats/bmmdef.py b/src/mercury_engine_data_structures/formats/bmmdef.py index 5e986bfa..67c4b753 100644 --- a/src/mercury_engine_data_structures/formats/bmmdef.py +++ b/src/mercury_engine_data_structures/formats/bmmdef.py @@ -1,8 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + from construct import Construct, Container +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game BMMDEF = standard_format.create("CMinimapDef", "1.0.2") diff --git a/src/mercury_engine_data_structures/formats/bmsad.py b/src/mercury_engine_data_structures/formats/bmsad.py index 8122ee83..29fa7098 100644 --- a/src/mercury_engine_data_structures/formats/bmsad.py +++ b/src/mercury_engine_data_structures/formats/bmsad.py @@ -1,7 +1,8 @@ +from __future__ import annotations + import copy import functools import typing -from collections.abc import Sequence import construct from construct.core import ( @@ -23,6 +24,7 @@ from construct.lib.containers import Container, ListContainer from mercury_engine_data_structures import common_types, type_lib +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import ( Char, CVector3D, @@ -35,12 +37,14 @@ from mercury_engine_data_structures.construct_extensions.alignment import PrefixedAllowZeroLen from mercury_engine_data_structures.construct_extensions.function_complex import ComplexIf, SwitchComplexKey from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.bmsas import BMSAS_SR, Bmsas from mercury_engine_data_structures.formats.property_enum import PropertyEnum from mercury_engine_data_structures.game_check import Game, GameSpecificStruct from mercury_engine_data_structures.type_lib import get_type_lib_dread, get_type_lib_for_game +if typing.TYPE_CHECKING: + from collections.abc import Sequence + # Functions FunctionArgument = Struct( "type" / Char, @@ -501,7 +505,7 @@ def __set__(self, inst: ActorDefFunc, value: T): class ComponentFields: - def __init__(self, parent: "Component") -> None: + def __init__(self, parent: Component) -> None: self.parent = parent def _get_extra_field(self, fields: Container, name: str) -> FieldType: diff --git a/src/mercury_engine_data_structures/formats/bmsas.py b/src/mercury_engine_data_structures/formats/bmsas.py index ec8af1c1..0a39d087 100644 --- a/src/mercury_engine_data_structures/formats/bmsas.py +++ b/src/mercury_engine_data_structures/formats/bmsas.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import construct @@ -18,10 +20,10 @@ Switch, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Char, CVector3D, DictAdapter, Float, VersionAdapter, make_vector from mercury_engine_data_structures.common_types import StrId as StrIdSR from mercury_engine_data_structures.construct_extensions.strings import PascalStringRobust -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.property_enum import PropertyEnum, PropertyEnumDoubleUnsafe from mercury_engine_data_structures.game_check import Game, GameSpecificStruct diff --git a/src/mercury_engine_data_structures/formats/bmsat.py b/src/mercury_engine_data_structures/formats/bmsat.py index 27656e6d..76528335 100644 --- a/src/mercury_engine_data_structures/formats/bmsat.py +++ b/src/mercury_engine_data_structures/formats/bmsat.py @@ -1,8 +1,14 @@ -from construct import Construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct + + from mercury_engine_data_structures.game_check import Game class Bmsat(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/bmsbk.py b/src/mercury_engine_data_structures/formats/bmsbk.py index 241cfb45..03fc0037 100644 --- a/src/mercury_engine_data_structures/formats/bmsbk.py +++ b/src/mercury_engine_data_structures/formats/bmsbk.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import functools +from typing import TYPE_CHECKING from construct import ( Array, @@ -13,9 +16,11 @@ Terminated, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import CVector3D, StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game Block = Struct( "pos" / CVector3D, diff --git a/src/mercury_engine_data_structures/formats/bmscc.py b/src/mercury_engine_data_structures/formats/bmscc.py index f93e7374..aaee9a30 100644 --- a/src/mercury_engine_data_structures/formats/bmscc.py +++ b/src/mercury_engine_data_structures/formats/bmscc.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct import ( Const, @@ -11,9 +13,9 @@ ) from mercury_engine_data_structures import game_check +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.collision import collision_formats from mercury_engine_data_structures.game_check import Game diff --git a/src/mercury_engine_data_structures/formats/bmscu.py b/src/mercury_engine_data_structures/formats/bmscu.py index 09fe40f3..ec2cd619 100644 --- a/src/mercury_engine_data_structures/formats/bmscu.py +++ b/src/mercury_engine_data_structures/formats/bmscu.py @@ -1,8 +1,14 @@ -from construct import Construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct + + from mercury_engine_data_structures.game_check import Game BMSCU = standard_format.create("CCutSceneDef", "8.3.2") diff --git a/src/mercury_engine_data_structures/formats/bmsem.py b/src/mercury_engine_data_structures/formats/bmsem.py index 50d02bed..5211d6ef 100644 --- a/src/mercury_engine_data_structures/formats/bmsem.py +++ b/src/mercury_engine_data_structures/formats/bmsem.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import construct from construct import ( Const, @@ -7,9 +11,11 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game BMSEM = Struct( _magic=Const(b"MSEM"), diff --git a/src/mercury_engine_data_structures/formats/bmses.py b/src/mercury_engine_data_structures/formats/bmses.py index 0407e7ac..39669efd 100644 --- a/src/mercury_engine_data_structures/formats/bmses.py +++ b/src/mercury_engine_data_structures/formats/bmses.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import functools +from typing import TYPE_CHECKING import construct from construct.core import ( @@ -9,9 +12,11 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game BMSES = Struct( "_magic" / Const(b"MSES"), diff --git a/src/mercury_engine_data_structures/formats/bmsld.py b/src/mercury_engine_data_structures/formats/bmsld.py index 77f6508b..7c7c3874 100644 --- a/src/mercury_engine_data_structures/formats/bmsld.py +++ b/src/mercury_engine_data_structures/formats/bmsld.py @@ -1,16 +1,22 @@ +from __future__ import annotations + import logging -from collections.abc import Iterator +from typing import TYPE_CHECKING import construct from construct import Const, Construct, Container, Flag, Float32l, Hex, Int32ul, Struct, Switch +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import CVector3D, Float, StrId, VersionAdapter, make_dict, make_vector from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage from mercury_engine_data_structures.construct_extensions.strings import StaticPaddedString from mercury_engine_data_structures.crc import crc32 -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.collision import collision_formats -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from collections.abc import Iterator + + from mercury_engine_data_structures.game_check import Game logger = logging.getLogger(__name__) diff --git a/src/mercury_engine_data_structures/formats/bmslgroup.py b/src/mercury_engine_data_structures/formats/bmslgroup.py index d2a21dc3..ff31b675 100644 --- a/src/mercury_engine_data_structures/formats/bmslgroup.py +++ b/src/mercury_engine_data_structures/formats/bmslgroup.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game BMSLGROUP = standard_format.create("navmesh::CDynamicSmartLinkGroup", "1.0.2") diff --git a/src/mercury_engine_data_structures/formats/bmslink.py b/src/mercury_engine_data_structures/formats/bmslink.py index 4afc0352..2b06c610 100644 --- a/src/mercury_engine_data_structures/formats/bmslink.py +++ b/src/mercury_engine_data_structures/formats/bmslink.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import construct from construct import Construct from construct.core import ( @@ -9,9 +13,11 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Float, StrId, VersionAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game UnkStruct = Struct( unk1=StrId, diff --git a/src/mercury_engine_data_structures/formats/bmsmd.py b/src/mercury_engine_data_structures/formats/bmsmd.py index 9ae10592..d7498271 100644 --- a/src/mercury_engine_data_structures/formats/bmsmd.py +++ b/src/mercury_engine_data_structures/formats/bmsmd.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import functools +from typing import TYPE_CHECKING from construct.core import ( Array, @@ -11,9 +14,11 @@ Struct, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game BMSMD = Struct( "_magic" / Const(b"MSMD"), diff --git a/src/mercury_engine_data_structures/formats/bmsmsd.py b/src/mercury_engine_data_structures/formats/bmsmsd.py index 7d767666..179cf222 100644 --- a/src/mercury_engine_data_structures/formats/bmsmsd.py +++ b/src/mercury_engine_data_structures/formats/bmsmsd.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import functools +from typing import TYPE_CHECKING import construct from construct.core import Const, Construct, Enum, FlagsEnum, Float32l, Int32sl, Int32ul, Struct +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import CVector2D, CVector3D, StrId, VersionAdapter, make_vector -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game TileBorders = FlagsEnum( Int32sl, diff --git a/src/mercury_engine_data_structures/formats/bmsnav.py b/src/mercury_engine_data_structures/formats/bmsnav.py index 2a75dd39..f23fa15a 100644 --- a/src/mercury_engine_data_structures/formats/bmsnav.py +++ b/src/mercury_engine_data_structures/formats/bmsnav.py @@ -1,7 +1,9 @@ +from __future__ import annotations + from construct.core import Array, Byte, Const, Construct, Flag, Hex, Int32ul, PrefixedArray, Struct, Terminated +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import CVector2D, CVector3D, Float, StrId, VersionAdapter, make_dict -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game ### A ton of barely-understood structs :] diff --git a/src/mercury_engine_data_structures/formats/bmssd.py b/src/mercury_engine_data_structures/formats/bmssd.py index b07eaa60..14712b9f 100644 --- a/src/mercury_engine_data_structures/formats/bmssd.py +++ b/src/mercury_engine_data_structures/formats/bmssd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct import ( Byte, @@ -10,9 +12,9 @@ ) from mercury_engine_data_structures import game_check +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import CVector3D, StrId, VersionAdapter, make_vector from mercury_engine_data_structures.construct_extensions.strings import StaticPaddedString -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game BMSSD = Struct( diff --git a/src/mercury_engine_data_structures/formats/bmtre.py b/src/mercury_engine_data_structures/formats/bmtre.py index 7fcdaede..6f5c15ee 100644 --- a/src/mercury_engine_data_structures/formats/bmtre.py +++ b/src/mercury_engine_data_structures/formats/bmtre.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import construct from construct.core import ( Array, @@ -13,10 +17,12 @@ Switch, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Float, StrId, VersionAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.formats.property_enum import PropertyEnum -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game ArgumentCases = { "b": Flag, diff --git a/src/mercury_engine_data_structures/formats/bmtun.py b/src/mercury_engine_data_structures/formats/bmtun.py index 0aa060bf..4dc1912b 100644 --- a/src/mercury_engine_data_structures/formats/bmtun.py +++ b/src/mercury_engine_data_structures/formats/bmtun.py @@ -1,4 +1,7 @@ +from __future__ import annotations + import functools +from typing import TYPE_CHECKING import construct from construct.core import ( @@ -10,10 +13,12 @@ Switch, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Char, CVector3D, Float, StrId, VersionAdapter, make_dict from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game # Functions TunableParam = Struct( diff --git a/src/mercury_engine_data_structures/formats/bnvib.py b/src/mercury_engine_data_structures/formats/bnvib.py index 5981ce1e..ff238437 100644 --- a/src/mercury_engine_data_structures/formats/bnvib.py +++ b/src/mercury_engine_data_structures/formats/bnvib.py @@ -1,4 +1,7 @@ +from __future__ import annotations + from enum import Enum +from typing import TYPE_CHECKING import construct from construct.core import ( @@ -13,8 +16,10 @@ ) from mercury_engine_data_structures.adapters.enum_adapter import EnumAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game +from mercury_engine_data_structures.base_resource import BaseResource + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game # Standard switch format. https://switchbrew.org/wiki/BNVIB#Normal_Vibration diff --git a/src/mercury_engine_data_structures/formats/bpsi.py b/src/mercury_engine_data_structures/formats/bpsi.py index bfcc4ece..4bca60ed 100644 --- a/src/mercury_engine_data_structures/formats/bpsi.py +++ b/src/mercury_engine_data_structures/formats/bpsi.py @@ -1,9 +1,11 @@ +from __future__ import annotations + from construct.core import Const, Construct, IfThenElse, Int32ul, PrefixedArray, Struct, Terminated from mercury_engine_data_structures import game_check +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import VersionAdapter from mercury_engine_data_structures.construct_extensions.strings import PascalStringRobust -from mercury_engine_data_structures.formats.base_resource import BaseResource BPSI = Struct( _magic=Const(b"MPSI"), diff --git a/src/mercury_engine_data_structures/formats/bptdat.py b/src/mercury_engine_data_structures/formats/bptdat.py index b1540e2f..bbd8762d 100644 --- a/src/mercury_engine_data_structures/formats/bptdat.py +++ b/src/mercury_engine_data_structures/formats/bptdat.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game BPTDAT = standard_format.create("CPlaythrough", "1.0.2") BPTDEF = standard_format.create("CPlaythroughDef", "1.0.2") diff --git a/src/mercury_engine_data_structures/formats/brem.py b/src/mercury_engine_data_structures/formats/brem.py index 29346fab..b7f879e0 100644 --- a/src/mercury_engine_data_structures/formats/brem.py +++ b/src/mercury_engine_data_structures/formats/brem.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game class Brem(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/bres.py b/src/mercury_engine_data_structures/formats/bres.py index 90d9660f..d65ae418 100644 --- a/src/mercury_engine_data_structures/formats/bres.py +++ b/src/mercury_engine_data_structures/formats/bres.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game class Bres(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/brev.py b/src/mercury_engine_data_structures/formats/brev.py index a0b048bd..c3ad86c2 100644 --- a/src/mercury_engine_data_structures/formats/brev.py +++ b/src/mercury_engine_data_structures/formats/brev.py @@ -1,8 +1,14 @@ -import construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + import construct + + from mercury_engine_data_structures.game_check import Game class Brev(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/brfld.py b/src/mercury_engine_data_structures/formats/brfld.py index 3536ff20..5172bef8 100644 --- a/src/mercury_engine_data_structures/formats/brfld.py +++ b/src/mercury_engine_data_structures/formats/brfld.py @@ -1,12 +1,18 @@ +from __future__ import annotations + import functools import logging -from collections.abc import Iterator - -import construct +from typing import TYPE_CHECKING +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from collections.abc import Iterator + + import construct + + from mercury_engine_data_structures.game_check import Game logger = logging.getLogger(__name__) diff --git a/src/mercury_engine_data_structures/formats/brsa.py b/src/mercury_engine_data_structures/formats/brsa.py index cd9b6064..660b8d55 100644 --- a/src/mercury_engine_data_structures/formats/brsa.py +++ b/src/mercury_engine_data_structures/formats/brsa.py @@ -1,11 +1,17 @@ -import functools -from collections.abc import Iterator +from __future__ import annotations -from construct import Construct, Container +import functools +from typing import TYPE_CHECKING +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from collections.abc import Iterator + + from construct import Construct, Container + + from mercury_engine_data_structures.game_check import Game class Brsa(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/brspd.py b/src/mercury_engine_data_structures/formats/brspd.py index 098b941f..026c78b4 100644 --- a/src/mercury_engine_data_structures/formats/brspd.py +++ b/src/mercury_engine_data_structures/formats/brspd.py @@ -1,8 +1,14 @@ -from construct import Construct +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct + + from mercury_engine_data_structures.game_check import Game class Brspd(BaseResource): diff --git a/src/mercury_engine_data_structures/formats/bsmat.py b/src/mercury_engine_data_structures/formats/bsmat.py index d579c76a..c470443c 100644 --- a/src/mercury_engine_data_structures/formats/bsmat.py +++ b/src/mercury_engine_data_structures/formats/bsmat.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import construct from construct.core import ( Array, @@ -14,9 +18,11 @@ Switch, ) +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import Char, Float, StrId, VersionAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game # these seem to be using Unity ShaderLab, or at least the gist I borrowed this from uses similar teminology # source for most binary info: https://gist.github.com/KillzXGaming/9817455559544cb3613f99184aa3ed68 diff --git a/src/mercury_engine_data_structures/formats/btunda.py b/src/mercury_engine_data_structures/formats/btunda.py index 062eb89c..c8133228 100644 --- a/src/mercury_engine_data_structures/formats/btunda.py +++ b/src/mercury_engine_data_structures/formats/btunda.py @@ -1,13 +1,17 @@ -from typing import Any +from __future__ import annotations + +from typing import TYPE_CHECKING, Any import construct from construct import Struct from mercury_engine_data_structures import type_lib +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import VersionAdapter -from mercury_engine_data_structures.formats import BaseResource from mercury_engine_data_structures.formats.property_enum import PropertyEnum -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from mercury_engine_data_structures.game_check import Game VALID_BTUNDA_VERSIONS = [ "119.0.2", # 1.0.0 diff --git a/src/mercury_engine_data_structures/formats/buct.py b/src/mercury_engine_data_structures/formats/buct.py index 57d2a407..f4b7cd77 100644 --- a/src/mercury_engine_data_structures/formats/buct.py +++ b/src/mercury_engine_data_structures/formats/buct.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct.core import ( Array, @@ -13,8 +15,8 @@ ) from mercury_engine_data_structures import game_check +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import VersionAdapter -from mercury_engine_data_structures.formats.base_resource import BaseResource BUCT = Struct( _magic=Const(b"MUCT"), diff --git a/src/mercury_engine_data_structures/formats/collision.py b/src/mercury_engine_data_structures/formats/collision.py index bc232f82..f733688b 100644 --- a/src/mercury_engine_data_structures/formats/collision.py +++ b/src/mercury_engine_data_structures/formats/collision.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from construct import Array, Flag, Hex, Int16ul, Rebuild, Struct diff --git a/src/mercury_engine_data_structures/formats/gui_files.py b/src/mercury_engine_data_structures/formats/gui_files.py index e50d472a..aec3f88c 100644 --- a/src/mercury_engine_data_structures/formats/gui_files.py +++ b/src/mercury_engine_data_structures/formats/gui_files.py @@ -1,8 +1,14 @@ -from construct import Construct, Container +from __future__ import annotations +from typing import TYPE_CHECKING + +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.formats import standard_format -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game + +if TYPE_CHECKING: + from construct import Construct, Container + + from mercury_engine_data_structures.game_check import Game BMSCP = standard_format.create("GUI::CDisplayObjectContainer", "1.2.2", explicit_root=True) BMSSH = standard_format.create("GUI::CGUIManager::ShapeContainer", "1.2.2", explicit_root=True) diff --git a/src/mercury_engine_data_structures/formats/ini.py b/src/mercury_engine_data_structures/formats/ini.py index a81b8c6c..4c5533e6 100644 --- a/src/mercury_engine_data_structures/formats/ini.py +++ b/src/mercury_engine_data_structures/formats/ini.py @@ -7,11 +7,11 @@ from construct import Construct, Container, GreedyString, Struct -from mercury_engine_data_structures.formats.base_resource import BaseResource -from mercury_engine_data_structures.game_check import Game +from mercury_engine_data_structures.base_resource import BaseResource if typing.TYPE_CHECKING: from mercury_engine_data_structures.file_tree_editor import FileTreeEditor + from mercury_engine_data_structures.game_check import Game INI = Struct("text" / GreedyString("utf-8")) diff --git a/src/mercury_engine_data_structures/formats/lua.py b/src/mercury_engine_data_structures/formats/lua.py index 2a6abbe8..7603d199 100644 --- a/src/mercury_engine_data_structures/formats/lua.py +++ b/src/mercury_engine_data_structures/formats/lua.py @@ -4,8 +4,8 @@ import construct +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import StrId -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game if typing.TYPE_CHECKING: diff --git a/src/mercury_engine_data_structures/formats/pkg.py b/src/mercury_engine_data_structures/formats/pkg.py index c861e2a2..9635d09c 100644 --- a/src/mercury_engine_data_structures/formats/pkg.py +++ b/src/mercury_engine_data_structures/formats/pkg.py @@ -15,8 +15,8 @@ ) from mercury_engine_data_structures import dread_data, samus_returns_data +from mercury_engine_data_structures.base_resource import AssetId, BaseResource, NameOrAssetId, resolve_asset_id from mercury_engine_data_structures.construct_extensions.alignment import AlignTo -from mercury_engine_data_structures.formats.base_resource import AssetId, BaseResource, NameOrAssetId, resolve_asset_id from mercury_engine_data_structures.game_check import Game diff --git a/src/mercury_engine_data_structures/formats/property_enum.py b/src/mercury_engine_data_structures/formats/property_enum.py index c9bd7544..11d60bd4 100644 --- a/src/mercury_engine_data_structures/formats/property_enum.py +++ b/src/mercury_engine_data_structures/formats/property_enum.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import enum import functools import warnings diff --git a/src/mercury_engine_data_structures/formats/standard_format.py b/src/mercury_engine_data_structures/formats/standard_format.py index 39566ce3..2b6c0711 100644 --- a/src/mercury_engine_data_structures/formats/standard_format.py +++ b/src/mercury_engine_data_structures/formats/standard_format.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import typing diff --git a/src/mercury_engine_data_structures/formats/toc.py b/src/mercury_engine_data_structures/formats/toc.py index 8b205af3..0d40311c 100644 --- a/src/mercury_engine_data_structures/formats/toc.py +++ b/src/mercury_engine_data_structures/formats/toc.py @@ -1,12 +1,17 @@ +from __future__ import annotations + import functools -from collections.abc import Iterator +from typing import TYPE_CHECKING import construct from mercury_engine_data_structures import common_types -from mercury_engine_data_structures.formats.base_resource import BaseResource, NameOrAssetId, resolve_asset_id +from mercury_engine_data_structures.base_resource import BaseResource, NameOrAssetId, resolve_asset_id from mercury_engine_data_structures.game_check import Game +if TYPE_CHECKING: + from collections.abc import Iterator + TOC_SR = construct.Struct( files=common_types.make_dict( value=construct.Int32ul, diff --git a/src/mercury_engine_data_structures/formats/txt.py b/src/mercury_engine_data_structures/formats/txt.py index ff06c295..72e9848a 100644 --- a/src/mercury_engine_data_structures/formats/txt.py +++ b/src/mercury_engine_data_structures/formats/txt.py @@ -1,11 +1,13 @@ +from __future__ import annotations + import functools import construct from construct.core import Const, Construct, GreedyRange, Struct +from mercury_engine_data_structures.base_resource import BaseResource from mercury_engine_data_structures.common_types import DictAdapter, DictElement, VersionAdapter from mercury_engine_data_structures.construct_extensions.strings import CStringRobust -from mercury_engine_data_structures.formats.base_resource import BaseResource from mercury_engine_data_structures.game_check import Game, is_sr_or_else _string_range = GreedyRange(DictElement(CStringRobust("utf-16-le"))) diff --git a/src/mercury_engine_data_structures/game_check.py b/src/mercury_engine_data_structures/game_check.py index 3b1314e5..a6948a61 100644 --- a/src/mercury_engine_data_structures/game_check.py +++ b/src/mercury_engine_data_structures/game_check.py @@ -2,16 +2,20 @@ For checking which game is being parsed """ -from collections.abc import Callable +from __future__ import annotations + from enum import Enum from functools import cached_property -from typing import Any +from typing import TYPE_CHECKING, Any import construct from construct.core import IfThenElse from mercury_engine_data_structures import crc +if TYPE_CHECKING: + from collections.abc import Callable + class Game(Enum): SAMUS_RETURNS = 10 diff --git a/src/mercury_engine_data_structures/object.py b/src/mercury_engine_data_structures/object.py index 8992de93..48d8b7a0 100644 --- a/src/mercury_engine_data_structures/object.py +++ b/src/mercury_engine_data_structures/object.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import construct from mercury_engine_data_structures.construct_extensions.function_complex import ( diff --git a/src/mercury_engine_data_structures/pointer_set.py b/src/mercury_engine_data_structures/pointer_set.py index 39127e43..200d7392 100644 --- a/src/mercury_engine_data_structures/pointer_set.py +++ b/src/mercury_engine_data_structures/pointer_set.py @@ -2,6 +2,8 @@ Helper class to handle objects that contain a pointer to objects of varied types, usually all with the same base type. """ +from __future__ import annotations + import copy import struct diff --git a/src/mercury_engine_data_structures/romfs.py b/src/mercury_engine_data_structures/romfs.py index d38a68b7..af102ce9 100644 --- a/src/mercury_engine_data_structures/romfs.py +++ b/src/mercury_engine_data_structures/romfs.py @@ -1,8 +1,13 @@ -import io +from __future__ import annotations + from abc import ABC, abstractmethod -from collections.abc import Iterator from contextlib import contextmanager -from pathlib import Path +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + import io + from collections.abc import Iterator + from pathlib import Path class RomFs(ABC): @@ -13,7 +18,6 @@ def get_pkg_stream(self, file_path: str) -> Iterator[io.BufferedIOBase]: :param file_path: File path to the pkg file """ - pass @abstractmethod def read_file_with_entry(self, file_path: str, entry) -> bytes: @@ -22,7 +26,6 @@ def read_file_with_entry(self, file_path: str, entry) -> bytes: :param file_path: File path to the pkg file :param entry: An entry object containing the end_offset and start_offset within the pkg """ - pass @abstractmethod def get_file(self, file_path: str) -> bytes: @@ -30,12 +33,10 @@ def get_file(self, file_path: str) -> bytes: :param file_path: Path to the file """ - pass @abstractmethod def all_files(self) -> Iterator[str]: """Returns an Iterator for all files within the RomFS""" - pass class ExtractedRomFs(RomFs): diff --git a/src/mercury_engine_data_structures/samus_returns_data.py b/src/mercury_engine_data_structures/samus_returns_data.py index 6da3ab13..5f78504c 100644 --- a/src/mercury_engine_data_structures/samus_returns_data.py +++ b/src/mercury_engine_data_structures/samus_returns_data.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import functools import json import typing diff --git a/tests/conftest.py b/tests/conftest.py index e201491f..a9add0c9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os from pathlib import Path @@ -60,5 +62,5 @@ def pytest_addoption(parser): def pytest_configure(config: pytest.Config): - global _FAIL_INSTEAD_OF_SKIP + global _FAIL_INSTEAD_OF_SKIP # noqa: PLW0603 _FAIL_INSTEAD_OF_SKIP = config.option.fail_if_missing diff --git a/tests/formats/test_bapd.py b/tests/formats/test_bapd.py index c77e5026..8409cd8c 100644 --- a/tests/formats/test_bapd.py +++ b/tests/formats/test_bapd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bcmdl.py b/tests/formats/test_bcmdl.py index eeb05c3c..582c0b50 100644 --- a/tests/formats/test_bcmdl.py +++ b/tests/formats/test_bcmdl.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import contextlib import pytest diff --git a/tests/formats/test_bcskla.py b/tests/formats/test_bcskla.py index 90718f92..dc8cb7bc 100644 --- a/tests/formats/test_bcskla.py +++ b/tests/formats/test_bcskla.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bctex.py b/tests/formats/test_bctex.py index d6f91ecd..510cd55a 100644 --- a/tests/formats/test_bctex.py +++ b/tests/formats/test_bctex.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor_parsed diff --git a/tests/formats/test_bgsnds.py b/tests/formats/test_bgsnds.py index c1a53a3d..0cfe4f42 100644 --- a/tests/formats/test_bgsnds.py +++ b/tests/formats/test_bgsnds.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from tests.test_lib import parse_build_compare_editor from mercury_engine_data_structures.formats.bgsnds import Bgsnds diff --git a/tests/formats/test_blsnd.py b/tests/formats/test_blsnd.py index 7c6ee288..ba496b4e 100644 --- a/tests/formats/test_blsnd.py +++ b/tests/formats/test_blsnd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_blut.py b/tests/formats/test_blut.py index 2551f290..8aa52829 100644 --- a/tests/formats/test_blut.py +++ b/tests/formats/test_blut.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmbls.py b/tests/formats/test_bmbls.py index 61af8c98..fda6370d 100644 --- a/tests/formats/test_bmbls.py +++ b/tests/formats/test_bmbls.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmdefs.py b/tests/formats/test_bmdefs.py index ba0ec841..efad0bb1 100644 --- a/tests/formats/test_bmdefs.py +++ b/tests/formats/test_bmdefs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from tests.test_lib import parse_build_compare_editor from mercury_engine_data_structures.formats.bmdefs import Bmdefs diff --git a/tests/formats/test_bmmap.py b/tests/formats/test_bmmap.py index 133b7669..ce6420db 100644 --- a/tests/formats/test_bmmap.py +++ b/tests/formats/test_bmmap.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmmdef.py b/tests/formats/test_bmmdef.py index f761168f..e2c25518 100644 --- a/tests/formats/test_bmmdef.py +++ b/tests/formats/test_bmmdef.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from tests.test_lib import parse_build_compare_editor from mercury_engine_data_structures.formats.bmmdef import Bmmdef diff --git a/tests/formats/test_bmsad.py b/tests/formats/test_bmsad.py index 680acdb9..1c9887ab 100644 --- a/tests/formats/test_bmsad.py +++ b/tests/formats/test_bmsad.py @@ -1,11 +1,17 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest from tests.test_lib import parse_build_compare_editor, parse_build_compare_editor_parsed from mercury_engine_data_structures import dread_data, samus_returns_data -from mercury_engine_data_structures.file_tree_editor import FileTreeEditor from mercury_engine_data_structures.formats import dread_types from mercury_engine_data_structures.formats.bmsad import ActorDefFunc, Bmsad +if TYPE_CHECKING: + from mercury_engine_data_structures.file_tree_editor import FileTreeEditor + dread_must_reencode = ["actors/props/pf_mushr_fr/charclasses/pf_mushr_fr.bmsad"] expected_sr_failures = set() diff --git a/tests/formats/test_bmsas.py b/tests/formats/test_bmsas.py index 7fbd4a68..7ec033d7 100644 --- a/tests/formats/test_bmsas.py +++ b/tests/formats/test_bmsas.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsat.py b/tests/formats/test_bmsat.py index d7a0b383..30484de7 100644 --- a/tests/formats/test_bmsat.py +++ b/tests/formats/test_bmsat.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsbk.py b/tests/formats/test_bmsbk.py index 7c2e46a3..980e60c0 100644 --- a/tests/formats/test_bmsbk.py +++ b/tests/formats/test_bmsbk.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmscu.py b/tests/formats/test_bmscu.py index 21e7da6d..52cbf191 100644 --- a/tests/formats/test_bmscu.py +++ b/tests/formats/test_bmscu.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsem.py b/tests/formats/test_bmsem.py index 25a246f5..d45995ce 100644 --- a/tests/formats/test_bmsem.py +++ b/tests/formats/test_bmsem.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmses.py b/tests/formats/test_bmses.py index b60ba854..1195de69 100644 --- a/tests/formats/test_bmses.py +++ b/tests/formats/test_bmses.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsld.py b/tests/formats/test_bmsld.py index faf31eaf..7430f243 100644 --- a/tests/formats/test_bmsld.py +++ b/tests/formats/test_bmsld.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsmd.py b/tests/formats/test_bmsmd.py index 8a293e57..a8e69e82 100644 --- a/tests/formats/test_bmsmd.py +++ b/tests/formats/test_bmsmd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsmsd.py b/tests/formats/test_bmsmsd.py index 8a84c8c8..9422dcb6 100644 --- a/tests/formats/test_bmsmsd.py +++ b/tests/formats/test_bmsmsd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmsnav.py b/tests/formats/test_bmsnav.py index b9891397..f9575d01 100644 --- a/tests/formats/test_bmsnav.py +++ b/tests/formats/test_bmsnav.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmssd.py b/tests/formats/test_bmssd.py index 9b455d2f..ef5243d7 100644 --- a/tests/formats/test_bmssd.py +++ b/tests/formats/test_bmssd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmtre.py b/tests/formats/test_bmtre.py index 774c8192..bf6cf8f5 100644 --- a/tests/formats/test_bmtre.py +++ b/tests/formats/test_bmtre.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bmtun.py b/tests/formats/test_bmtun.py index f67a382e..8092b4d2 100644 --- a/tests/formats/test_bmtun.py +++ b/tests/formats/test_bmtun.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bnvib.py b/tests/formats/test_bnvib.py index 5ca31120..5e65ee88 100644 --- a/tests/formats/test_bnvib.py +++ b/tests/formats/test_bnvib.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bpsi.py b/tests/formats/test_bpsi.py index e557409d..5f8b95ef 100644 --- a/tests/formats/test_bpsi.py +++ b/tests/formats/test_bpsi.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bptdat.py b/tests/formats/test_bptdat.py index 61865418..06dcf8b7 100644 --- a/tests/formats/test_bptdat.py +++ b/tests/formats/test_bptdat.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_brem.py b/tests/formats/test_brem.py index 6ae4500a..9c2ef24e 100644 --- a/tests/formats/test_brem.py +++ b/tests/formats/test_brem.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bres.py b/tests/formats/test_bres.py index 3fbe1fe1..688a2426 100644 --- a/tests/formats/test_bres.py +++ b/tests/formats/test_bres.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_brev.py b/tests/formats/test_brev.py index 81d0d061..cafeb5d3 100644 --- a/tests/formats/test_brev.py +++ b/tests/formats/test_brev.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_brfld.py b/tests/formats/test_brfld.py index 8a2ad4a6..76693908 100644 --- a/tests/formats/test_brfld.py +++ b/tests/formats/test_brfld.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_brsa.py b/tests/formats/test_brsa.py index 5d4c42a0..cff92172 100644 --- a/tests/formats/test_brsa.py +++ b/tests/formats/test_brsa.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_brspd.py b/tests/formats/test_brspd.py index a6e4b192..fbfbd13a 100644 --- a/tests/formats/test_brspd.py +++ b/tests/formats/test_brspd.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_bsmat.py b/tests/formats/test_bsmat.py index 15b31c35..c78daaa6 100644 --- a/tests/formats/test_bsmat.py +++ b/tests/formats/test_bsmat.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from construct.core import ListContainer from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_btunda.py b/tests/formats/test_btunda.py index 16cfbb71..2167e112 100644 --- a/tests/formats/test_btunda.py +++ b/tests/formats/test_btunda.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_buct.py b/tests/formats/test_buct.py index a09ff259..ab3dd976 100644 --- a/tests/formats/test_buct.py +++ b/tests/formats/test_buct.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/formats/test_collision.py b/tests/formats/test_collision.py index e6a0d3dc..b1357738 100644 --- a/tests/formats/test_collision.py +++ b/tests/formats/test_collision.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor_parsed diff --git a/tests/formats/test_gui.py b/tests/formats/test_gui.py index acb4a406..30a453ad 100644 --- a/tests/formats/test_gui.py +++ b/tests/formats/test_gui.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import contextlib import construct diff --git a/tests/formats/test_ini.py b/tests/formats/test_ini.py index ea0e8bd9..9b86ac72 100644 --- a/tests/formats/test_ini.py +++ b/tests/formats/test_ini.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from tests.test_lib import parse_build_compare_editor from mercury_engine_data_structures.formats.ini import Ini diff --git a/tests/formats/test_lua.py b/tests/formats/test_lua.py index 5dff1a0d..7f0de561 100644 --- a/tests/formats/test_lua.py +++ b/tests/formats/test_lua.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from construct import Container from mercury_engine_data_structures.formats.lua import Lua diff --git a/tests/formats/test_pkg.py b/tests/formats/test_pkg.py index 4b642320..8e630d3f 100644 --- a/tests/formats/test_pkg.py +++ b/tests/formats/test_pkg.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from construct import Container, ListContainer from tests.test_lib import parse_and_build_compare diff --git a/tests/formats/test_toc.py b/tests/formats/test_toc.py index 7c943da2..da65367f 100644 --- a/tests/formats/test_toc.py +++ b/tests/formats/test_toc.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from mercury_engine_data_structures.formats.toc import Toc from mercury_engine_data_structures.game_check import Game diff --git a/tests/formats/test_txt.py b/tests/formats/test_txt.py index 9740333b..973a775c 100644 --- a/tests/formats/test_txt.py +++ b/tests/formats/test_txt.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from tests.test_lib import parse_build_compare_editor diff --git a/tests/test_common_types.py b/tests/test_common_types.py index 6951b6b4..2d44ea8e 100644 --- a/tests/test_common_types.py +++ b/tests/test_common_types.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from mercury_engine_data_structures import common_types from mercury_engine_data_structures.common_types import Float diff --git a/tests/test_file_tree_editor.py b/tests/test_file_tree_editor.py index 30275107..ae8fc981 100644 --- a/tests/test_file_tree_editor.py +++ b/tests/test_file_tree_editor.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import re import pytest diff --git a/tests/test_lib.py b/tests/test_lib.py index 7fdffac7..4307ca9a 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -1,12 +1,19 @@ -from pathlib import Path +from __future__ import annotations + +from typing import TYPE_CHECKING -import construct import pytest -from mercury_engine_data_structures.file_tree_editor import FileTreeEditor -from mercury_engine_data_structures.formats import BaseResource from mercury_engine_data_structures.game_check import Game, GameSpecificStruct +if TYPE_CHECKING: + from pathlib import Path + + import construct + + from mercury_engine_data_structures.base_resource import BaseResource + from mercury_engine_data_structures.file_tree_editor import FileTreeEditor + def parse_and_build_compare(module, game: Game, file_path: Path, print_data=False, save_file=None): if not file_path.is_file(): diff --git a/tests/test_object.py b/tests/test_object.py index 6c538d8b..94233b2d 100644 --- a/tests/test_object.py +++ b/tests/test_object.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from mercury_engine_data_structures import common_types diff --git a/tests/test_pointer_set.py b/tests/test_pointer_set.py index 97fd6557..0ba7f2e1 100644 --- a/tests/test_pointer_set.py +++ b/tests/test_pointer_set.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from mercury_engine_data_structures import common_types diff --git a/tests/test_type_lib.py b/tests/test_type_lib.py index af029d70..955dd53f 100644 --- a/tests/test_type_lib.py +++ b/tests/test_type_lib.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import contextlib import pytest diff --git a/tools/create_class_definitions.py b/tools/create_class_definitions.py index ea5a9d2b..872be6f9 100644 --- a/tools/create_class_definitions.py +++ b/tools/create_class_definitions.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import collections import copy diff --git a/tools/create_sr_file_names.py b/tools/create_sr_file_names.py index 55bddceb..7673dff9 100644 --- a/tools/create_sr_file_names.py +++ b/tools/create_sr_file_names.py @@ -1,3 +1,5 @@ +from __future__ import annotations + all_levels = [ "s000_surface", "s010_area1", diff --git a/tools/extract_pkg.py b/tools/extract_pkg.py index b8e67119..8c757ecb 100644 --- a/tools/extract_pkg.py +++ b/tools/extract_pkg.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import json from pathlib import Path diff --git a/tools/filter_file_names.py b/tools/filter_file_names.py index 8324696e..22f0f482 100644 --- a/tools/filter_file_names.py +++ b/tools/filter_file_names.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import json import os.path diff --git a/tools/ghidra_export.py b/tools/ghidra_export.py index 853967e0..679db058 100644 --- a/tools/ghidra_export.py +++ b/tools/ghidra_export.py @@ -1,3 +1,12 @@ +# /// script +# dependencies = [ +# "ghidra_bridge", +# "mercury-engine-data-structures", +# ] +# /// + +from __future__ import annotations + import collections import functools import json @@ -13,6 +22,9 @@ from mercury_engine_data_structures import dread_data from mercury_engine_data_structures.type_lib import PrimitiveKind, TypeKind +# ruff: noqa: PLW0603 +# ruff: noqa: PLW2901 + # New JSON Format known_types_to_construct = { "bool": PrimitiveKind.BOOL, diff --git a/tools/list_known_paths_in_toc.py b/tools/list_known_paths_in_toc.py index 502794e6..506c6fbd 100644 --- a/tools/list_known_paths_in_toc.py +++ b/tools/list_known_paths_in_toc.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse from pathlib import Path diff --git a/tools/plot_simple_map.py b/tools/plot_simple_map.py index e3932e76..089d0c05 100644 --- a/tools/plot_simple_map.py +++ b/tools/plot_simple_map.py @@ -1,3 +1,13 @@ +# /// script +# dependencies = [ +# "numpy", +# "shapely", +# "mercury-engine-data-structures", +# ] +# /// + +from __future__ import annotations + import copy import json import os @@ -5,7 +15,6 @@ import typing from pathlib import Path -import construct import numpy from shapely.geometry import Point from shapely.geometry.polygon import Polygon @@ -16,6 +25,12 @@ from mercury_engine_data_structures.game_check import Game from mercury_engine_data_structures.romfs import ExtractedRomFs +if typing.TYPE_CHECKING: + import construct + +# ruff: noqa: PLW0603 +# ruff: noqa: PLW2901 + world_names = { "maps/levels/c10_samus/s010_cave/s010_cave.brfld": "Artaria", "maps/levels/c10_samus/s020_magma/s020_magma.brfld": "Cataris", diff --git a/tools/sr_export_rdv_database.py b/tools/sr_export_rdv_database.py index 57c63d60..6dc592c6 100644 --- a/tools/sr_export_rdv_database.py +++ b/tools/sr_export_rdv_database.py @@ -1,3 +1,14 @@ +# /// script +# dependencies = [ +# "numpy", +# "matplotlib", +# "shapely", +# "mercury-engine-data-structures", +# ] +# /// + +from __future__ import annotations + import argparse import copy import hashlib @@ -7,7 +18,6 @@ import typing from pathlib import Path -import construct import numpy from matplotlib.patches import Polygon as mtPolygon from shapely.geometry import Point @@ -19,6 +29,11 @@ from mercury_engine_data_structures.game_check import Game from mercury_engine_data_structures.romfs import ExtractedRomFs +if typing.TYPE_CHECKING: + import construct + +# ruff: noqa: PLW0603 + world_names = { "maps/levels/c10_samus/s000_surface/s000_surface.bmsld": "Surface - East", "maps/levels/c10_samus/s010_area1/s010_area1.bmsld": "Area 1", @@ -713,7 +728,7 @@ def add_node(target_area: str, node_def: NodeDefinition): raise ValueError("What kind of actor is this?!") handles_by_label = {} - handles_by_label = {key: value for key, value in sorted(handles_by_label.items(), key=lambda it: it[0])} + handles_by_label = dict(sorted(handles_by_label.items(), key=lambda it: it[0])) plt.legend(handles_by_label.values(), handles_by_label.keys()) plt.plot() diff --git a/tools/update_hashes_with_field_names.py b/tools/update_hashes_with_field_names.py index b00c90ab..4e6a9b58 100644 --- a/tools/update_hashes_with_field_names.py +++ b/tools/update_hashes_with_field_names.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import typing from pathlib import Path