Skip to content

Commit 5f2b0fc

Browse files
Ran python linting, created pyproject
1 parent 6b5e863 commit 5f2b0fc

17 files changed

Lines changed: 94 additions & 61 deletions

.github/workflows/ci.yaml

Whitespace-only changes.

pyproject.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[project]
2+
name = "totk-vscode-python"
3+
version = "0.1.0"
4+
description = "Python scripts for TOTK VSCode extension"
5+
requires-python = ">=3.9"
6+
dependencies = [
7+
"oead>=1.2.9.post4",
8+
"zstandard>=0.22.0",
9+
"mmh3>=4.0.0",
10+
"Pillow>=10.0.0",
11+
"texture2ddecoder>=1.0.4",
12+
"PyYAML>=6.0"
13+
]
14+
15+
[tool.ruff]
16+
line-length = 100
17+
target-version = "py39"
18+
19+
[tool.ruff.lint]
20+
select = [
21+
"E", # pycodestyle errors
22+
"W", # pycodestyle warnings
23+
"F", # pyflakes
24+
"I", # isort
25+
"B", # flake8-bugbear
26+
"C4", # flake8-comprehensions
27+
]
28+
ignore = [
29+
"E501", # line too long, handled by formatter
30+
]
31+
32+
[tool.ruff.format]
33+
quote-style = "double"
34+
indent-style = "space"

python/aamp_io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66

77
import oead
8-
98
from zstd_totk import compress_container, decompress_container
109

1110
_EXTENSIONS_PATH = Path(__file__).parent.parent / 'config' / 'aamp-extensions.json'

python/archive_resolve.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pathlib import Path
55

66
import oead
7-
87
from bntx_reader import is_bntx, list_textures, read_texture_data
98
from zstd_totk import compress_container, decompress_container
109

@@ -307,7 +306,7 @@ def read_archive_file_bytes(disk_archive_path: str, file_path: str, romfs_path:
307306
def _reject_bntx_mutation(disk_archive_path: str, operation: str, target_path: str = '') -> None:
308307
if _is_bntx_name(disk_archive_path):
309308
raise PermissionError(f'Cannot {operation} inside a BNTX texture container (read-only)')
310-
309+
311310
if target_path:
312311
segments = [s for s in target_path.split('/') if s]
313312
if any(_is_bntx_name(seg) for seg in segments[:-1]):

python/bntx_renderer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import tempfile
1010

11-
from bntx_reader import _parse_textures, _log
11+
from bntx_reader import _log, _parse_textures
1212

1313
_FORMAT_TABLE: dict[int, tuple[str, int, int, int, str]] = {
1414
0x01: ('R4G4_UNORM', 1, 1, 1, 'r8'),
@@ -344,10 +344,10 @@ def _apply_channel_swizzle(
344344
from PIL import Image
345345
img = Image.frombytes('RGBA', (width, height), pixels, 'raw', raw_mode)
346346
bands = img.split()
347-
347+
348348
zero_band = None
349349
one_band = None
350-
350+
351351
def get_band(ch_val):
352352
nonlocal zero_band, one_band
353353
if ch_val == 0:

python/byml_yaml_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import re
44

5-
65
_U64_DECIMAL_PATTERN = re.compile(
76
r'(?P<prefix>:\s*|,\s*|\{\s*)(?P<num>\d{10,})(?=\s*(?:$|[,}\]]))',
87
re.MULTILINE,

python/msbt_editor_format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
if str(_VENDOR_PYMSBT) not in sys.path:
99
sys.path.insert(0, str(_VENDOR_PYMSBT))
1010

11-
from pymsbt.classes import TextCommand, TextComponent
1211
from msbt_tag_formatter import command_to_tag, tag_to_command
12+
from pymsbt.classes import TextCommand, TextComponent
1313

1414
_CMD_PATTERN = re.compile(
1515
r'\{cmd:([^:}]+):(\d+):(\d+):([^}]*)\}|\{\{([^}]+)\}\}',
@@ -70,7 +70,7 @@ def display_to_components(text: str) -> list:
7070
magic, group, cmd_type, hexdata = 14, 0, 0, ''
7171
else:
7272
magic, group, cmd_type, hexdata = match.group(1), match.group(2), match.group(3), match.group(4)
73-
73+
7474
hex_clean = hexdata.replace('0x', '').replace(' ', '') if hexdata else ''
7575
data_size = (len(hex_clean) + 1) // 2
7676
command = TextCommand.__new__(TextCommand)
@@ -172,4 +172,4 @@ def from_editor_text(text: str) -> dict[str, list]:
172172
label = line[:colon].strip()
173173
value = _parse_value(line[colon + 1 :])
174174
labels[label] = display_to_components(value)
175-
return labels
175+
return labels

python/msbt_tag_formatter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import struct
21
import shlex
2+
import struct
3+
34
from msbt_tags import MSBT_TAGS_BY_ID, MSBT_TAGS_BY_NAME
45

6+
57
def _decode_str_arg(raw: str):
68
"""Strip the leading Nintendo ctrl char from a decoded str argument.
79
@@ -85,7 +87,7 @@ def command_to_tag(magic, group, type_, hexdata):
8587
if str_run_start is None:
8688
str_run_start = i
8789
else:
88-
str_run_start = None
90+
str_run_start = None
8991

9092
for i, arg in enumerate(args_def):
9193
dtype = arg.get('dataType')
@@ -215,4 +217,4 @@ def tag_to_command(tag_content):
215217
b.extend(val_str.encode('utf-16-le'))
216218
b.extend(b'\x00\x00')
217219

218-
return str(magic), group, type_, b.hex()
220+
return str(magic), group, type_, b.hex()

python/romfs_index.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from archive_resolve import list_archive_files
1010

11-
1211
_ARCHIVE_EXTENSIONS = (
1312
'.pack',
1413
'.sarc',

python/tag_product_format.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import yaml
21
import json
3-
import oead
42
import os
53

4+
import oead
5+
import yaml
6+
7+
68
def to_editor_text(byml_doc: oead.byml.Hash) -> str:
79
path_list = byml_doc.get("PathList", [])
810
tag_list = [str(x) for x in byml_doc.get("TagList", [])]
911
bit_table = bytes(byml_doc.get("BitTable", b""))
10-
12+
1113
actor_tag_data = {}
1214
path_list_count = len(path_list)
1315
tag_list_count = len(tag_list)
14-
16+
1517
def get_bit(data: bytes, index: int) -> bool:
1618
byte_idx = index // 8
1719
bit_idx = index % 8
@@ -26,12 +28,12 @@ def get_bit(data: bytes, index: int) -> bool:
2628
if get_bit(bit_table, i * tag_list_count + k):
2729
actor_tag_list.append(tag_list[k])
2830
actor_tag_data[actor_path] = actor_tag_list
29-
31+
3032
data = {
3133
"PathList": actor_tag_data,
3234
"TagList": tag_list
3335
}
34-
36+
3537
fmt = os.environ.get('TOTK_TAG_PRODUCT_FORMAT', 'json')
3638
if fmt == 'yaml':
3739
return yaml.safe_dump(data, sort_keys=False, allow_unicode=True, width=float('inf'))
@@ -42,41 +44,41 @@ def from_editor_text(editor_text: str, big_endian: bool, version: int) -> bytes:
4244
json_data = yaml.safe_load(editor_text)
4345
cached_tag_list = json_data.get("TagList", [])
4446
path_list_map = json_data.get("PathList", {})
45-
47+
4648
path_vec = list(path_list_map.items())
4749
def sort_key(item):
4850
key = item[0]
4951
parts = key.split('|')
5052
extract = parts[1] if len(parts) > 1 else key
5153
return (extract, key)
52-
54+
5355
path_vec.sort(key=sort_key)
54-
56+
5557
path_list_out = []
5658
bit_table_bits = []
57-
59+
5860
for path, tag_entries in path_vec:
5961
if '|' in path:
6062
slices = path.split('|')
6163
path_list_out.extend(slices)
62-
64+
6365
for tag in cached_tag_list:
6466
bit_table_bits.append(tag in tag_entries)
65-
67+
6668
# Pack bits to bytes (LSB0)
6769
bit_table_bytes = bytearray((len(bit_table_bits) + 7) // 8)
6870
for i, bit in enumerate(bit_table_bits):
6971
if bit:
7072
byte_idx = i // 8
7173
bit_idx = i % 8
7274
bit_table_bytes[byte_idx] |= (1 << bit_idx)
73-
75+
7476
byml_dict = {
7577
"PathList": path_list_out,
7678
"BitTable": bytes(bit_table_bytes),
7779
"RankTable": "",
7880
"TagList": cached_tag_list
7981
}
80-
82+
8183
byml_doc = oead.byml.Hash(byml_dict)
8284
return oead.byml.to_binary(byml_doc, big_endian=big_endian, version=version)

0 commit comments

Comments
 (0)