ines-parser 1.4.0__tar.gz → 1.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {ines_parser-1.4.0 → ines_parser-1.5.0}/PKG-INFO +20 -5
  2. {ines_parser-1.4.0 → ines_parser-1.5.0}/README.md +18 -3
  3. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/__init__.py +14 -2
  4. ines_parser-1.5.0/ines_parser/cli/ines_analyze_rom.py +329 -0
  5. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/cli/ines_rom_stats.py +3 -4
  6. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/cli/ines_scan_roms.py +5 -5
  7. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/cli/ines_split_rom.py +6 -7
  8. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/cli/rom_fs.py +2 -3
  9. ines_parser-1.5.0/ines_parser/filename.py +397 -0
  10. ines_parser-1.5.0/ines_parser/py.typed +0 -0
  11. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/PKG-INFO +20 -5
  12. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/SOURCES.txt +5 -1
  13. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/entry_points.txt +1 -0
  14. {ines_parser-1.4.0 → ines_parser-1.5.0}/pyproject.toml +3 -2
  15. ines_parser-1.5.0/tests/test_filename.py +292 -0
  16. {ines_parser-1.4.0 → ines_parser-1.5.0}/LICENSE +0 -0
  17. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/cli/__init__.py +0 -0
  18. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/mappers.py +0 -0
  19. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/parser.py +0 -0
  20. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser/tables.py +0 -0
  21. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/dependency_links.txt +0 -0
  22. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/requires.txt +0 -0
  23. {ines_parser-1.4.0 → ines_parser-1.5.0}/ines_parser.egg-info/top_level.txt +0 -0
  24. {ines_parser-1.4.0 → ines_parser-1.5.0}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ines-parser
3
- Version: 1.4.0
4
- Summary: Parse iNES/NES 2.0 ROM headers; CLI to scan, export, summarize, and split ROMs
3
+ Version: 1.5.0
4
+ Summary: Parse iNES/NES 2.0 ROM headers and ROM filename tags; CLI to scan, export, summarize, analyze, and split ROMs
5
5
  Author: Leonid Kabanov
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/ponchick/ines-parser
@@ -28,7 +28,7 @@ Dynamic: license-file
28
28
 
29
29
  # iNES Parser
30
30
 
31
- Python library and CLI for NES ROMs in iNES / NES 2.0 format: parse headers, scan collections, export reports, summarize mappers, and split PRG/CHR. Requires Python 3.10+.
31
+ Python library and CLI for NES ROMs in iNES / NES 2.0 format: parse headers and ROM filename tags, scan collections, export reports, summarize mappers, analyze single ROMs, and split PRG/CHR. Requires Python 3.10+.
32
32
 
33
33
  ```bash
34
34
  pip install ines-parser
@@ -44,7 +44,7 @@ ines_scan_roms.py /path/to/roms
44
44
  # or: python -m ines_parser.cli.ines_scan_roms /path/to/roms
45
45
  ```
46
46
 
47
- Same idea for `ines_rom_stats.py` and `ines_split_rom.py`.
47
+ Same idea for `ines_rom_stats.py`, `ines_split_rom.py`, and `ines_analyze_rom.py`.
48
48
 
49
49
  ### Scan
50
50
 
@@ -74,10 +74,19 @@ ines_split_rom.py game.nes
74
74
  ines_split_rom.py roms.7z # prompts before overwrite; use --force to skip
75
75
  ```
76
76
 
77
+ ### Analyze
78
+
79
+ ```bash
80
+ ines_analyze_rom.py game.nes
81
+ ines_analyze_rom.py game.nes --json
82
+ ```
83
+
84
+ Full report for one ROM file: file size, iNES header, and naming-convention tags parsed from the filename — GoodTools style (`(JU) [!] [b] [hIR] [T+Rus] (VS) (PC10)`) and No-Intro style (`(USA) (Rev A) (Beta 1) (En,Fr,De)`) — plus cross-checks between them: file size vs. header, filename region vs. TV system, `(VS)`/`(PC10)` vs. console type, `[!]` vs. header validity. Unrecognised tags are listed as unknown, never guessed.
85
+
77
86
  ## Library
78
87
 
79
88
  ```python
80
- from ines_parser import parse_ines_header
89
+ from ines_parser import parse_ines_header, parse_rom_filename
81
90
 
82
91
  with open("game.nes", "rb") as f:
83
92
  header = parse_ines_header(f.read(16))
@@ -85,6 +94,12 @@ with open("game.nes", "rb") as f:
85
94
  if header and header.is_valid():
86
95
  print(header)
87
96
  print(header.detailed_str())
97
+
98
+ info = parse_rom_filename("Super Mario Bros. (JU) [!].nes")
99
+ print(info.title) # Super Mario Bros.
100
+ print(info.regions) # ('Japan', 'USA')
101
+ print(info.verified) # True
102
+ print(info.to_dict()) # JSON-friendly; adds expected_tv_system
88
103
  ```
89
104
 
90
105
  ## Docs
@@ -1,6 +1,6 @@
1
1
  # iNES Parser
2
2
 
3
- Python library and CLI for NES ROMs in iNES / NES 2.0 format: parse headers, scan collections, export reports, summarize mappers, and split PRG/CHR. Requires Python 3.10+.
3
+ Python library and CLI for NES ROMs in iNES / NES 2.0 format: parse headers and ROM filename tags, scan collections, export reports, summarize mappers, analyze single ROMs, and split PRG/CHR. Requires Python 3.10+.
4
4
 
5
5
  ```bash
6
6
  pip install ines-parser
@@ -16,7 +16,7 @@ ines_scan_roms.py /path/to/roms
16
16
  # or: python -m ines_parser.cli.ines_scan_roms /path/to/roms
17
17
  ```
18
18
 
19
- Same idea for `ines_rom_stats.py` and `ines_split_rom.py`.
19
+ Same idea for `ines_rom_stats.py`, `ines_split_rom.py`, and `ines_analyze_rom.py`.
20
20
 
21
21
  ### Scan
22
22
 
@@ -46,10 +46,19 @@ ines_split_rom.py game.nes
46
46
  ines_split_rom.py roms.7z # prompts before overwrite; use --force to skip
47
47
  ```
48
48
 
49
+ ### Analyze
50
+
51
+ ```bash
52
+ ines_analyze_rom.py game.nes
53
+ ines_analyze_rom.py game.nes --json
54
+ ```
55
+
56
+ Full report for one ROM file: file size, iNES header, and naming-convention tags parsed from the filename — GoodTools style (`(JU) [!] [b] [hIR] [T+Rus] (VS) (PC10)`) and No-Intro style (`(USA) (Rev A) (Beta 1) (En,Fr,De)`) — plus cross-checks between them: file size vs. header, filename region vs. TV system, `(VS)`/`(PC10)` vs. console type, `[!]` vs. header validity. Unrecognised tags are listed as unknown, never guessed.
57
+
49
58
  ## Library
50
59
 
51
60
  ```python
52
- from ines_parser import parse_ines_header
61
+ from ines_parser import parse_ines_header, parse_rom_filename
53
62
 
54
63
  with open("game.nes", "rb") as f:
55
64
  header = parse_ines_header(f.read(16))
@@ -57,6 +66,12 @@ with open("game.nes", "rb") as f:
57
66
  if header and header.is_valid():
58
67
  print(header)
59
68
  print(header.detailed_str())
69
+
70
+ info = parse_rom_filename("Super Mario Bros. (JU) [!].nes")
71
+ print(info.title) # Super Mario Bros.
72
+ print(info.regions) # ('Japan', 'USA')
73
+ print(info.verified) # True
74
+ print(info.to_dict()) # JSON-friendly; adds expected_tv_system
60
75
  ```
61
76
 
62
77
  ## Docs
@@ -2,7 +2,8 @@
2
2
  iNES Parser Library
3
3
 
4
4
  A Python library for parsing iNES format NES ROM files.
5
- Supports iNES 1.0, NES 2.0, Archaic iNES formats, and UNIF detection.
5
+ Supports iNES 1.0, NES 2.0, Archaic iNES formats, and UNIF detection,
6
+ plus GoodTools/No-Intro ROM filename conventions.
6
7
  """
7
8
 
8
9
  from .parser import (
@@ -17,6 +18,13 @@ from .parser import (
17
18
  INES_TRAINER_SIZE,
18
19
  )
19
20
 
21
+ from .filename import (
22
+ parse_rom_filename,
23
+ RomFilenameInfo,
24
+ DumpStatus,
25
+ expected_tv_system,
26
+ )
27
+
20
28
  from .tables import (
21
29
  get_mapper_name,
22
30
  get_mapper_alternate_names,
@@ -31,7 +39,7 @@ from .tables import (
31
39
  is_known_submapper,
32
40
  )
33
41
 
34
- __version__ = "1.4.0"
42
+ __version__ = "1.5.0"
35
43
  __author__ = "Leonid Kabanov"
36
44
  __all__ = [
37
45
  "parse_ines_header",
@@ -43,6 +51,10 @@ __all__ = [
43
51
  "CPUTiming",
44
52
  "INES_HEADER_SIZE",
45
53
  "INES_TRAINER_SIZE",
54
+ "parse_rom_filename",
55
+ "RomFilenameInfo",
56
+ "DumpStatus",
57
+ "expected_tv_system",
46
58
  "get_mapper_name",
47
59
  "get_mapper_alternate_names",
48
60
  "get_mapper_notes",
@@ -0,0 +1,329 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Full analysis of a single iNES ROM file.
4
+
5
+ Combines three sources of information about one ROM:
6
+
7
+ - the file itself (size),
8
+ - the iNES / NES 2.0 header,
9
+ - the filename's naming-convention tags (GoodTools / No-Intro style),
10
+
11
+ and cross-checks them against each other: file size vs. header sizes,
12
+ filename region vs. header TV system, (VS)/(PC10) markers vs. header console
13
+ type, [!] verified marker vs. header validity.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import argparse
19
+ import json
20
+ import sys
21
+ from pathlib import Path
22
+ from typing import Any
23
+
24
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
25
+
26
+ from ines_parser import (
27
+ INES_HEADER_SIZE,
28
+ INES_TRAINER_SIZE,
29
+ ConsoleType,
30
+ INESFormat,
31
+ INESHeader,
32
+ parse_ines_header,
33
+ )
34
+ from ines_parser.filename import RomFilenameInfo, expected_tv_system, parse_rom_filename
35
+
36
+
37
+ def format_size(size_bytes: int) -> str:
38
+ return f"{size_bytes} bytes ({size_bytes / 1024:.1f} KiB)"
39
+
40
+
41
+ def analyze_file(path: Path) -> dict[str, Any]:
42
+ """Build the full report dict for one ROM file."""
43
+ file_size = path.stat().st_size
44
+ with open(path, "rb") as f:
45
+ raw_header = f.read(INES_HEADER_SIZE)
46
+
47
+ header: INESHeader | None = None
48
+ header_dict: dict[str, Any] | None
49
+ if len(raw_header) < INES_HEADER_SIZE:
50
+ header_dict = {
51
+ "valid": False,
52
+ "error": f"file too short for a {INES_HEADER_SIZE}-byte header",
53
+ }
54
+ else:
55
+ header = parse_ines_header(raw_header)
56
+ header_dict = header.to_dict() if header is not None else None
57
+
58
+ name_info = parse_rom_filename(path.name)
59
+
60
+ return {
61
+ "schema_version": 1,
62
+ "file": {
63
+ "path": str(path),
64
+ "size_bytes": file_size,
65
+ },
66
+ "filename": name_info.to_dict(),
67
+ "header": header_dict,
68
+ "cross_checks": build_cross_checks(name_info, header, file_size),
69
+ # Runtime-only helpers for the text renderer; stripped from JSON output.
70
+ "_filename_info": name_info,
71
+ "_header_object": header,
72
+ }
73
+
74
+
75
+ def _check(name: str, status: str, detail: str) -> dict[str, str]:
76
+ return {"check": name, "status": status, "detail": detail}
77
+
78
+
79
+ def build_cross_checks(
80
+ name_info: RomFilenameInfo,
81
+ header: INESHeader | None,
82
+ file_size: int,
83
+ ) -> list[dict[str, str]]:
84
+ """Compare filename facts, header fields and the actual file size."""
85
+ checks: list[dict[str, str]] = []
86
+ header_valid = header is not None and header.is_valid()
87
+
88
+ # --- File size vs sizes declared in the header ---
89
+ if header is not None and header.is_valid():
90
+ expected = (
91
+ INES_HEADER_SIZE
92
+ + (INES_TRAINER_SIZE if header.has_trainer else 0)
93
+ + header.prg_rom_size
94
+ + header.chr_rom_size
95
+ )
96
+ parts = [
97
+ f"{INES_HEADER_SIZE} header",
98
+ f"{header.prg_rom_size} PRG",
99
+ f"{header.chr_rom_size} CHR",
100
+ ]
101
+ if header.has_trainer:
102
+ parts.insert(1, f"{INES_TRAINER_SIZE} trainer")
103
+ composition = " + ".join(parts)
104
+ if header.misc_rom_count:
105
+ checks.append(_check(
106
+ "file size vs header",
107
+ "skipped",
108
+ "header declares miscellaneous ROMs of unstated size",
109
+ ))
110
+ elif file_size == expected:
111
+ checks.append(_check(
112
+ "file size vs header", "ok", f"exactly {composition}"
113
+ ))
114
+ elif file_size > expected:
115
+ checks.append(_check(
116
+ "file size vs header",
117
+ "warning",
118
+ f"{file_size - expected} trailing byte(s) beyond {composition}",
119
+ ))
120
+ else:
121
+ checks.append(_check(
122
+ "file size vs header",
123
+ "warning",
124
+ f"file is {expected - file_size} byte(s) shorter than {composition}",
125
+ ))
126
+
127
+ # --- Filename region vs header TV system ---
128
+ tv_system = header.tv_system
129
+ if tv_system is not None:
130
+ note = "" if header.format == INESFormat.NES_2_0 else \
131
+ " (iNES 1.0 TV bits are unofficial)"
132
+ expected_tv = expected_tv_system(name_info.regions)
133
+ if not name_info.regions:
134
+ checks.append(_check(
135
+ "filename region vs TV system",
136
+ "skipped",
137
+ "no region tags in the filename",
138
+ ))
139
+ elif expected_tv is None:
140
+ checks.append(_check(
141
+ "filename region vs TV system",
142
+ "skipped",
143
+ f"regions {', '.join(name_info.regions)} do not imply a single TV system",
144
+ ))
145
+ elif tv_system.value not in ("NTSC", "PAL"):
146
+ checks.append(_check(
147
+ "filename region vs TV system",
148
+ "skipped",
149
+ f"header TV system {tv_system.value} is not directly comparable",
150
+ ))
151
+ elif expected_tv == tv_system.value:
152
+ checks.append(_check(
153
+ "filename region vs TV system",
154
+ "ok",
155
+ f"{', '.join(name_info.regions)} imply {expected_tv}; "
156
+ f"header says {tv_system.value}{note}",
157
+ ))
158
+ else:
159
+ checks.append(_check(
160
+ "filename region vs TV system",
161
+ "warning",
162
+ f"{', '.join(name_info.regions)} imply {expected_tv}, "
163
+ f"but header says {tv_system.value}{note}",
164
+ ))
165
+
166
+ # --- (VS) / (PC10) filename markers vs header console type ---
167
+ header_is_vs = (
168
+ header.console_type == ConsoleType.VS_SYSTEM or header.is_vs_unisystem
169
+ )
170
+ if name_info.is_vs or header_is_vs:
171
+ both = name_info.is_vs and header_is_vs
172
+ checks.append(_check(
173
+ "Vs. System marker vs header console type",
174
+ "ok" if both else "warning",
175
+ "filename (VS) and header console type agree"
176
+ if both
177
+ else "filename (VS) marker" if name_info.is_vs
178
+ else "header console type says Vs. System",
179
+ ))
180
+
181
+ header_is_pc10 = (
182
+ header.console_type == ConsoleType.PLAYCHOICE_10 or header.is_playchoice_10
183
+ )
184
+ if name_info.is_playchoice or header_is_pc10:
185
+ both = name_info.is_playchoice and header_is_pc10
186
+ checks.append(_check(
187
+ "PlayChoice-10 marker vs header console type",
188
+ "ok" if both else "warning",
189
+ "filename (PC10) and header console type agree"
190
+ if both
191
+ else "filename (PC10) marker" if name_info.is_playchoice
192
+ else "header console type says PlayChoice-10",
193
+ ))
194
+
195
+ # --- [!] verified dump vs header validity ---
196
+ if name_info.verified:
197
+ if header_valid:
198
+ checks.append(_check(
199
+ "verified dump marker vs header",
200
+ "ok",
201
+ "[!] claims a verified dump; header is a valid iNES image",
202
+ ))
203
+ else:
204
+ checks.append(_check(
205
+ "verified dump marker vs header",
206
+ "warning",
207
+ "[!] claims a verified dump, but the header is not a valid iNES image",
208
+ ))
209
+
210
+ return checks
211
+
212
+
213
+ def filename_lines(info: RomFilenameInfo) -> list[tuple[str, str]]:
214
+ """(label, value) pairs for the text report; only non-default facts."""
215
+ lines: list[tuple[str, str]] = []
216
+
217
+ def add(label: str, value: str) -> None:
218
+ lines.append((label, value))
219
+
220
+ if info.regions:
221
+ add("Regions", ", ".join(info.regions))
222
+ if info.languages:
223
+ add("Languages", ", ".join(info.languages))
224
+ add("Dump status", info.dump_status.value)
225
+ extra_flags = [f for f in info.dump_flags if f != info.dump_status.value]
226
+ if extra_flags:
227
+ add("Dump flags", ", ".join(extra_flags))
228
+ if info.is_hack:
229
+ add("Hack", f"yes ({info.hack_tag})" if info.hack_tag else "yes")
230
+ if info.is_translation:
231
+ marker = "+" if info.translation_is_newer else "-"
232
+ language = info.translation_language or "?"
233
+ add("Translation", f"[T{marker}{language}]")
234
+ if info.is_unlicensed:
235
+ add("Unlicensed", "yes")
236
+ if info.is_public_domain:
237
+ add("Public domain", "yes")
238
+ if info.is_vs:
239
+ add("Vs. System", "yes")
240
+ if info.is_playchoice:
241
+ add("PlayChoice-10", "yes")
242
+ if info.is_nintendo_power:
243
+ add("Nintendo Power", "yes")
244
+ if info.multipart_index is not None:
245
+ add("Multipart", str(info.multipart_index))
246
+ if info.prerelease:
247
+ suffix = f" {info.prerelease_index}" if info.prerelease_index else ""
248
+ add("Prerelease", f"{info.prerelease}{suffix}")
249
+ if info.revision:
250
+ add("Revision", info.revision)
251
+ if info.version:
252
+ add("Version", info.version)
253
+ return lines
254
+
255
+
256
+ def print_text_report(report: dict[str, Any]) -> None:
257
+ file_info = report["file"]
258
+ print(f"File: {file_info['path']}")
259
+ print(f"Size: {format_size(file_info['size_bytes'])}")
260
+
261
+ name_dict = report["filename"]
262
+ print("\nFilename analysis")
263
+ print(f" {'Title:':16} {name_dict['title']}")
264
+ for label, value in filename_lines(report["_filename_info"]):
265
+ print(f" {label + ':':16} {value}")
266
+ if name_dict.get("unknown_tokens"):
267
+ print(f" {'Unknown tokens:':16} {' '.join(name_dict['unknown_tokens'])}")
268
+
269
+ print("\niNES header")
270
+ header_dict = report["header"]
271
+ if header_dict is None:
272
+ print(" no header (file too short)")
273
+ elif not header_dict.get("valid"):
274
+ detail = header_dict.get("error") or header_dict.get("format", "unknown")
275
+ print(f" not a valid iNES image ({detail})")
276
+ else:
277
+ print(f" {report['_header_object'].detailed_str()}")
278
+
279
+ print("\nCross-checks")
280
+ checks = report["cross_checks"]
281
+ if not checks:
282
+ print(" (none; header not valid or nothing to compare)")
283
+ return
284
+ for check in checks:
285
+ print(f" {check['status'].upper():8} {check['check']}: {check['detail']}")
286
+
287
+
288
+ def build_argument_parser() -> argparse.ArgumentParser:
289
+ parser = argparse.ArgumentParser(
290
+ prog="ines_analyze_rom.py",
291
+ description="Full analysis of a single ROM: header, filename tags, cross-checks",
292
+ )
293
+ parser.add_argument("rom", metavar="ROM", help="Path to the ROM file (.nes)")
294
+ parser.add_argument(
295
+ "--json",
296
+ action="store_true",
297
+ help="Print machine-readable JSON instead of the text report",
298
+ )
299
+ return parser
300
+
301
+
302
+ def main() -> int:
303
+ parser = build_argument_parser()
304
+ args = parser.parse_args()
305
+
306
+ path = Path(args.rom)
307
+ if not path.exists():
308
+ print(f"Error: File does not exist: {args.rom}", file=sys.stderr)
309
+ return 1
310
+ if not path.is_file():
311
+ print(f"Error: Not a file: {args.rom}", file=sys.stderr)
312
+ return 1
313
+
314
+ try:
315
+ report = analyze_file(path)
316
+ except OSError as exc:
317
+ print(f"Error: Cannot read {args.rom}: {exc}", file=sys.stderr)
318
+ return 1
319
+
320
+ if args.json:
321
+ public = {k: v for k, v in report.items() if not k.startswith("_")}
322
+ print(json.dumps(public, indent=2))
323
+ else:
324
+ print_text_report(report)
325
+ return 0
326
+
327
+
328
+ if __name__ == "__main__":
329
+ sys.exit(main())
@@ -28,7 +28,6 @@ from ines_parser.tables import get_mapper_name
28
28
  from ines_parser.cli.rom_fs import (
29
29
  ALL_ARCHIVE_FORMATS,
30
30
  ARCHIVE_EXTENSIONS,
31
- LIBARCHIVE_AVAILABLE,
32
31
  DEFAULT_ARCHIVE_PATH,
33
32
  SUPPORTED_EXTENSIONS,
34
33
  collect_supported_files,
@@ -73,7 +72,7 @@ def tally_nes_file(file_path: Path, stats: RomStats) -> None:
73
72
 
74
73
 
75
74
  def tally_archive(archive_path: Path, stats: RomStats) -> None:
76
- if not LIBARCHIVE_AVAILABLE or libarchive is None:
75
+ if libarchive is None:
77
76
  return
78
77
  try:
79
78
  with open(archive_path, "rb") as f:
@@ -163,7 +162,7 @@ def print_text_report(report: dict[str, Any]) -> None:
163
162
 
164
163
  def build_argument_parser() -> argparse.ArgumentParser:
165
164
  supported = ", ".join(sorted(SUPPORTED_EXTENSIONS))
166
- if not LIBARCHIVE_AVAILABLE:
165
+ if libarchive is None:
167
166
  supported += " (libarchive not installed — archive members not scanned)"
168
167
 
169
168
  parser = argparse.ArgumentParser(
@@ -226,7 +225,7 @@ def main() -> int:
226
225
  for r in scan_roots:
227
226
  print(f" {r}", file=sys.stderr)
228
227
  print(f"Extensions: {', '.join(sorted(SUPPORTED_EXTENSIONS))}", file=sys.stderr)
229
- if not LIBARCHIVE_AVAILABLE:
228
+ if libarchive is None:
230
229
  print(
231
230
  f"Note: without libarchive, archives {sorted(ALL_ARCHIVE_FORMATS)} are ignored.",
232
231
  file=sys.stderr,
@@ -32,7 +32,6 @@ from ines_parser import parse_ines_header, INESHeader, INES_HEADER_SIZE
32
32
  from ines_parser.cli.rom_fs import (
33
33
  ALL_ARCHIVE_FORMATS,
34
34
  ARCHIVE_EXTENSIONS,
35
- LIBARCHIVE_AVAILABLE,
36
35
  DEFAULT_ARCHIVE_PATH,
37
36
  SUPPORTED_EXTENSIONS,
38
37
  collect_supported_files,
@@ -40,7 +39,8 @@ from ines_parser.cli.rom_fs import (
40
39
  )
41
40
 
42
41
  # Path columns always first, then header fields for the selected detail level.
43
- _PATH_COLUMNS = ("path", "archive_member")
42
+ # Annotated as tuple[str, ...] so column lists built from it stay list[str].
43
+ _PATH_COLUMNS: tuple[str, ...] = ("path", "archive_member")
44
44
 
45
45
  # Default (short) list. Size fields use the same names as full, but values are KiB.
46
46
  _BASIC_COLUMNS = (
@@ -535,7 +535,7 @@ def process_archive(
535
535
  Returns:
536
536
  Number of successfully processed files in the archive
537
537
  """
538
- if not LIBARCHIVE_AVAILABLE:
538
+ if libarchive is None:
539
539
  return 0
540
540
 
541
541
  relative_path = archive_path.relative_to(base_path)
@@ -715,7 +715,7 @@ def scan_directory(
715
715
  def build_argument_parser() -> argparse.ArgumentParser:
716
716
  """Build the command-line argument parser."""
717
717
  supported_types = ", ".join(sorted(SUPPORTED_EXTENSIONS))
718
- if not LIBARCHIVE_AVAILABLE:
718
+ if libarchive is None:
719
719
  supported_types += " (libarchive not available - archive support disabled)"
720
720
 
721
721
  parser = argparse.ArgumentParser(
@@ -891,7 +891,7 @@ def main() -> int:
891
891
  for root in scan_roots:
892
892
  print(f" {root}", file=sys.stderr)
893
893
  print(f"Looking for: {extensions_str}", file=sys.stderr)
894
- if not LIBARCHIVE_AVAILABLE:
894
+ if libarchive is None:
895
895
  archive_types = ", ".join(sorted(ALL_ARCHIVE_FORMATS))
896
896
  print(
897
897
  f"Warning: libarchive not available - archive support "
@@ -19,9 +19,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
19
19
  # Try to import libarchive - make it optional
20
20
  try:
21
21
  import libarchive
22
- LIBARCHIVE_AVAILABLE = True
23
22
  except ImportError:
24
- LIBARCHIVE_AVAILABLE = False
23
+ libarchive = None # type: ignore
25
24
 
26
25
  # Import from ines_parser package
27
26
  from ines_parser import parse_ines_header, INES_HEADER_SIZE, INES_TRAINER_SIZE
@@ -29,7 +28,7 @@ from ines_parser import parse_ines_header, INES_HEADER_SIZE, INES_TRAINER_SIZE
29
28
  # Constants
30
29
  SUPPORTED_EXTENSIONS = {'.nes'}
31
30
  ALL_ARCHIVE_EXTENSIONS = {'.7z', '.zip', '.rar'}
32
- ARCHIVE_EXTENSIONS = ALL_ARCHIVE_EXTENSIONS if LIBARCHIVE_AVAILABLE else set()
31
+ ARCHIVE_EXTENSIONS = ALL_ARCHIVE_EXTENSIONS if libarchive is not None else set()
33
32
 
34
33
 
35
34
  class ROMExtractionError(Exception):
@@ -204,9 +203,9 @@ def process_archive(filename: str, force: bool = False) -> None:
204
203
  Raises:
205
204
  ROMExtractionError: If processing fails or libarchive not available
206
205
  """
207
- if not LIBARCHIVE_AVAILABLE:
206
+ if libarchive is None:
208
207
  raise ROMExtractionError("libarchive not available - archive support disabled")
209
-
208
+
210
209
  with open(filename, 'rb') as f:
211
210
  with libarchive.fd_reader(f.fileno()) as archive:
212
211
  # First pass: collect all .nes files
@@ -264,7 +263,7 @@ def parse_arguments() -> argparse.Namespace:
264
263
  # Build supported formats string from constants
265
264
  all_extensions = SUPPORTED_EXTENSIONS | ARCHIVE_EXTENSIONS
266
265
  supported_formats = ", ".join(sorted(all_extensions))
267
- if not LIBARCHIVE_AVAILABLE:
266
+ if libarchive is None:
268
267
  supported_formats += " (libarchive not available - archive support disabled)"
269
268
 
270
269
  parser = argparse.ArgumentParser(
@@ -314,7 +313,7 @@ def main() -> int:
314
313
  file_ext = input_path.suffix.lower()
315
314
 
316
315
  if file_ext in ALL_ARCHIVE_EXTENSIONS:
317
- if not LIBARCHIVE_AVAILABLE:
316
+ if libarchive is None:
318
317
  print(f"Error: Unsupported file extension: {file_ext}", file=sys.stderr)
319
318
  print("For archive format support, install libarchive-c: pip install libarchive-c", file=sys.stderr)
320
319
  return 1
@@ -7,16 +7,15 @@ from typing import Optional
7
7
 
8
8
  try:
9
9
  import libarchive # noqa: F401
10
- LIBARCHIVE_AVAILABLE = True
11
10
  except ImportError:
12
- LIBARCHIVE_AVAILABLE = False
11
+ libarchive = None # type: ignore
13
12
 
14
13
  from ines_parser import INES_HEADER_SIZE
15
14
 
16
15
  DEFAULT_ARCHIVE_PATH = "nes_archive/"
17
16
  ALL_ARCHIVE_FORMATS = frozenset({".7z", ".zip", ".rar"})
18
17
  ARCHIVE_EXTENSIONS: frozenset[str] = (
19
- ALL_ARCHIVE_FORMATS if LIBARCHIVE_AVAILABLE else frozenset()
18
+ ALL_ARCHIVE_FORMATS if libarchive is not None else frozenset()
20
19
  )
21
20
  SUPPORTED_EXTENSIONS = ARCHIVE_EXTENSIONS | {".nes"}
22
21