Skip to content

Commit

Permalink
Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquegemignani committed Oct 14, 2024
1 parent 8682d77 commit d79c46d
Show file tree
Hide file tree
Showing 58 changed files with 278 additions and 135 deletions.
4 changes: 2 additions & 2 deletions src/mercury_engine_data_structures/adapters/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,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
Expand Down Expand Up @@ -88,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
Expand Down Expand Up @@ -178,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

Expand Down Expand Up @@ -212,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
Expand Down
15 changes: 9 additions & 6 deletions src/mercury_engine_data_structures/file_tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
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__)
Expand Down
6 changes: 5 additions & 1 deletion src/mercury_engine_data_structures/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +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
Expand Down Expand Up @@ -49,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,
Expand Down
10 changes: 7 additions & 3 deletions src/mercury_engine_data_structures/formats/bapd.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

import construct
from typing import TYPE_CHECKING

from mercury_engine_data_structures.formats.base_resource import BaseResource
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")

Expand Down
8 changes: 6 additions & 2 deletions src/mercury_engine_data_structures/formats/bcmdl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import construct
from construct.core import (
Array,
Expand All @@ -26,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
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bcskla.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,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

Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bctex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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(
Expand Down
10 changes: 7 additions & 3 deletions src/mercury_engine_data_structures/formats/bgsnds.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from construct 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 construct import Construct

from mercury_engine_data_structures.game_check import Game


class Bgsnds(BaseResource):
Expand Down
10 changes: 7 additions & 3 deletions src/mercury_engine_data_structures/formats/bldef.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from construct import Construct, Container
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):
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/blsnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,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(
Expand Down
8 changes: 6 additions & 2 deletions src/mercury_engine_data_structures/formats/blut.py
Original file line number Diff line number Diff line change
@@ -1,10 +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))

Expand Down
10 changes: 7 additions & 3 deletions src/mercury_engine_data_structures/formats/bmbls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

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:
import construct

from mercury_engine_data_structures.game_check import Game

BMBLS = standard_format.create("base::animation::CBlendSpaceResource", "1.2.2")

Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,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(
Expand Down
11 changes: 7 additions & 4 deletions src/mercury_engine_data_structures/formats/bmmap.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

import functools
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 construct import Construct, Container

from mercury_engine_data_structures.game_check import Game

BMMAP = standard_format.create("CMinimapData", "1.0.2")

Expand Down
8 changes: 6 additions & 2 deletions src/mercury_engine_data_structures/formats/bmmdef.py
Original file line number Diff line number Diff line change
@@ -1,10 +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")

Expand Down
6 changes: 4 additions & 2 deletions src/mercury_engine_data_structures/formats/bmsad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import copy
import functools
import typing
from collections.abc import Sequence

import construct
from construct.core import (
Expand All @@ -25,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,
Expand All @@ -37,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,
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,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

Expand Down
10 changes: 7 additions & 3 deletions src/mercury_engine_data_structures/formats/bmsat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations

from construct 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 construct import Construct

from mercury_engine_data_structures.game_check import Game


class Bmsat(BaseResource):
Expand Down
7 changes: 5 additions & 2 deletions src/mercury_engine_data_structures/formats/bmsbk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import functools
from typing import TYPE_CHECKING

from construct import (
Array,
Expand All @@ -15,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,
Expand Down
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/formats/bmscc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,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

Expand Down
Loading

0 comments on commit d79c46d

Please sign in to comment.