Skip to content

Commit

Permalink
Merge pull request #128 from randovania/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
henriquegemignani authored Jun 20, 2024
2 parents 4d7d170 + cd88838 commit 1ab76d1
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 49 deletions.
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ default_language_version:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
rev: v0.4.9
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
2 changes: 1 addition & 1 deletion parse_pwe_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def to_stream(self, data: typing.BinaryIO, default_override: dict | None = None)
has_root_size_offset = False

if self.is_struct:
null_bytes = repr(b"\xFF\xFF\xFF\xFF")
null_bytes = repr(b"\xff\xff\xff\xff")
self.class_code += f" data.write({null_bytes}) # struct object id\n"
placeholder = repr(b"\x00\x00")
self.class_code += " root_size_offset = data.tell()\n"
Expand Down
18 changes: 7 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ markers = [

[tool.ruff]
line-length = 120
target-version = "py310"
src = ["src"]

[tool.ruff.lint]
select = [
"E", "F", "W", "C90", "I", "UP", "C4",
"RSE",
Expand All @@ -75,23 +79,15 @@ select = [
"PLW",
]
extend-ignore = [
"ISC001", # may cause conflicts with formatter
"PLR0913", # Too many arguments to function call
"PLR2004", # Magic values show up everywhere in construct defs
]

src = ["src"]

# Version to target for generated code.
target-version = "py310"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 25.
# Defaults to 10, but we're being very flexible right now
max-complexity = 25

[tool.ruff.isort]
[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.black]
line-length = 120
target-version = ['py310', 'py311']
10 changes: 3 additions & 7 deletions src/retro_data_structures/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,8 @@ def id_generator(asset_type):

for converted_asset in converter.converted_assets.values():
print(
" {}: {:08x} from {:08x} ({})".format(
converted_asset.type,
converted_asset.id,
reverse_converted_ids[converted_asset.id][1],
reverse_converted_ids[converted_asset.id][0].name,
)
f" {converted_asset.type}: {converted_asset.id:08x} from {reverse_converted_ids[converted_asset.id][1]:08x}"
f" ({reverse_converted_ids[converted_asset.id][0].name})"
)


Expand All @@ -300,7 +296,7 @@ def decode_encode_compare_file(file_path: Path, game: Game, file_format: str):

encoded = construct_class.build(decoded_from_raw, target_game=game)

if raw != encoded and raw.rstrip(b"\xFF") != encoded:
if raw != encoded and raw.rstrip(b"\xff") != encoded:
return f"{file_path}: Results differ (len(raw): {len(raw)}; len(encoded): {len(encoded)})"
return None

Expand Down
7 changes: 2 additions & 5 deletions src/retro_data_structures/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ def _encode(self, uncompressed, context, path):
decompressed_size = construct.evaluate(self.decompressed_size, context)
if decompressed_size != len(uncompressed):
raise ValueError(
"Decompressed size {} doesn't match size of data to compress ({}) at {}".format(
decompressed_size,
len(uncompressed),
path,
)
f"Decompressed size {decompressed_size} doesn't match size of data "
f"to compress ({len(uncompressed)}) at {path}"
)

segment_size = self.segment_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _build(self, obj, stream, context, path):


class AlignedPrefixed(Subconstruct):
def __init__(self, length_field, subcon, modulus, length_size, pad_byte=b"\xFF"):
def __init__(self, length_field, subcon, modulus, length_size, pad_byte=b"\xff"):
super().__init__(subcon)
self.length_field = length_field
self.modulus = modulus
Expand Down
7 changes: 3 additions & 4 deletions src/retro_data_structures/construct_extensions/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ def _build(self, obj: construct.Container, stream, context, path):
self.value_type._build(value, stream, context, field_path)

def _emitparse(self, code):
return "Container(({}, {}) for i in range({}))".format(
self.key_type._compileparse(code),
self.value_type._compileparse(code),
self.count_type._compileparse(code),
return (
f"Container(({self.key_type._compileparse(code)}, {self.value_type._compileparse(code)}) "
f"for i in range({self.count_type._compileparse(code)}))"
)

def _emitbuild(self, code):
Expand Down
2 changes: 1 addition & 1 deletion src/retro_data_structures/formats/anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_descriptor(this):
ANIM = Struct(
anim_version=Int32ub,
anim=IfThenElse(construct.this.anim_version == 0x00000000, UncompressedAnimation, CompressedAnimation),
trailing_bytes=GreedyRange(Const(b"\xFF")),
trailing_bytes=GreedyRange(Const(b"\xff")),
_terminated=Terminated,
)

Expand Down
2 changes: 1 addition & 1 deletion src/retro_data_structures/formats/cinf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
build_order_id=PrefixedArray(Int32ub, Int32ub),
bone_names=PrefixedArray(Int32ub, BoneName),
),
pattern=b"\xFF",
pattern=b"\xff",
)


Expand Down
2 changes: 1 addition & 1 deletion src/retro_data_structures/formats/mapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __str__(self):
),
),
),
b"\xFF",
b"\xff",
)


Expand Down
6 changes: 3 additions & 3 deletions src/retro_data_structures/formats/msbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _context_for_entry(self, context, entry_or_header):
return new_context


LabelsSection = construct.Aligned(16, LabelsSectionBody(), b"\xAB")
LabelsSection = construct.Aligned(16, LabelsSectionBody(), b"\xab")

AttributesSection = construct.Aligned(
16,
Expand All @@ -193,7 +193,7 @@ def _context_for_entry(self, context, entry_or_header):
entry=construct.CString("utf_16_le"),
has_entry_size=True,
),
b"\xAB",
b"\xab",
)

TextsSection = construct.Aligned(
Expand All @@ -203,7 +203,7 @@ def _context_for_entry(self, context, entry_or_header):
entry=construct.StringEncoded(construct.GreedyBytes, "utf_16_le"),
has_entry_size=False,
),
b"\xAB",
b"\xab",
)


Expand Down
2 changes: 1 addition & 1 deletion src/retro_data_structures/formats/pak_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _build(self, obj: PakBody, stream, context, path):

pad = 32 - (len(data) % 32)
if pad < 32:
data += b"\xFF" * pad
data += b"\xff" * pad

header.resources[i].offset = construct.stream_tell(stream, path)
header.resources[i].size = len(data)
Expand Down
8 changes: 4 additions & 4 deletions src/retro_data_structures/game_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def __init__(self, target: Game, subcon1, subcon2):

def _emitparse(self, code: construct.CodeGen):
code.append("from retro_data_structures import game_check")
return "(({}) if (game_check.get_current_game(this) >= game_check.Game.{}) else ({}))".format(
self.thensubcon._compileparse(code),
self.target_game.name,
self.elsesubcon._compileparse(code),
return (
f"(({self.thensubcon._compileparse(code)}) "
f"if (game_check.get_current_game(this) >= game_check.Game.{self.target_game.name}) "
f"else ({self.elsesubcon._compileparse(code)}))"
)

def _emitbuild(self, code: construct.CodeGen):
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/test_pak_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,6 @@ def test_compare_from_build():
for source_file in source.files:
pad = 32 - len(source_file.compressed_data) % 32
if pad < 32:
source_file.compressed_data += b"\xFF" * pad
source_file.compressed_data += b"\xff" * pad

assert decoded == source
2 changes: 1 addition & 1 deletion tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_import_and_create_prime_remastered(path: Path):

def test_door():
data = (
b"\xFF\xFF\xFF\xFF\x06\x9a\x00\x16%ZE\x80\x00H\x00\x04INAM\x00\x05Door\x00XFRM\x00$\xc1\xb6"
b"\xff\xff\xff\xff\x06\x9a\x00\x16%ZE\x80\x00H\x00\x04INAM\x00\x05Door\x00XFRM\x00$\xc1\xb6"
b"\xad\xc9\xc3BwZ\xc26\x9e\xcb\x00\x00\x00\x00\x00\x00\x00\x00C4\x00\x00?\x80\x00\x00?\x80\x00"
b"\x00?\x80\x00\x00ACTV\x00\x01\x01])\x8aC\x00\x04\x00\x00\x00\x03\xf3D\xc0\xb0\x00\x0c>\xb333@"
b"\xa0\x00\x00@\x80\x00\x00.hl*\x00\x0c\xbe333\x00\x00\x00\x00@\x00\x00\x00\xcf\x90\xd1^\x00"
Expand Down

0 comments on commit 1ab76d1

Please sign in to comment.