xgparse 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: xgparse
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: parser for eXtreme Gammon files
5
5
  Author: Gergely Elias
6
6
  Author-email: Gergely Elias <gergely.elias@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xgparse"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  authors = [
5
5
  { name="Gergely Elias", email="gergely.elias@gmail.com" },
6
6
  ]
@@ -0,0 +1,3 @@
1
+ from xgparse.convertxg import convert_xg_to_text
2
+ from xgparse.convertxg import convert_xg_to_py_dataclasses
3
+ from xgparse.extractxgdata import main as extract_xg_data
@@ -1,5 +1,5 @@
1
1
  #
2
- # convertxg2txt.py - XG data to text conversion tool
2
+ # convertxg.py - XG data to text conversion tool
3
3
  # Copyright (C) 2026 Gergely Elias <gergely.elias@gmail.com>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
@@ -19,15 +19,23 @@
19
19
  from __future__ import annotations
20
20
 
21
21
  import pprint
22
+ from collections.abc import Generator
22
23
 
23
24
  from . import xgimport
24
25
  from . import xgstruct
25
26
 
26
27
 
27
- def convert_xg_to_text(path: str) -> bytes:
28
- """Convert XG data to text format, returning the text as bytes."""
28
+ def convert_xg_to_py_dataclasses(
29
+ path: str,
30
+ ) -> Generator[xgstruct.GameRecord | xgstruct.RolloutContextEntry, None, None]:
31
+ """Yield parsed records from an XG file as dataclass objects.
32
+
33
+ Produces the same sequence as :func:`convert_xg_to_text` but returns
34
+ live dataclass instances instead of a text dump. :class:`~xgstruct.UnimplementedEntry`
35
+ records are skipped (matching the text-dump behaviour). Rollout records
36
+ are yielded after all game records.
37
+ """
29
38
  importer = xgimport.Import(path)
30
- output = []
31
39
  file_version = -1
32
40
 
33
41
  for segment in importer.get_file_segments():
@@ -40,7 +48,7 @@ def convert_xg_to_text(path: str) -> bytes:
40
48
  if isinstance(rec, xgstruct.HeaderMatchEntry):
41
49
  file_version = rec.version
42
50
  if not isinstance(rec, xgstruct.UnimplementedEntry):
43
- output.append(pprint.pformat(rec, width=160))
51
+ yield rec
44
52
 
45
53
  elif segment.seg_type is xgimport.SegmentType.XG_ROLLOUTS:
46
54
  segment.fd.seek(0)
@@ -48,6 +56,10 @@ def convert_xg_to_text(path: str) -> bytes:
48
56
  rec = xgstruct.read_rollout_record(segment.fd)
49
57
  if rec is None:
50
58
  break
51
- output.append(pprint.pformat(rec, width=160))
59
+ yield rec
52
60
 
61
+
62
+ def convert_xg_to_text(path: str) -> bytes:
63
+ """Convert XG data to text format, returning the text as bytes."""
64
+ output = [pprint.pformat(rec, width=160) for rec in convert_xg_to_py_dataclasses(path)]
53
65
  return "\n".join(output).encode("utf-8")
@@ -31,12 +31,20 @@ import struct
31
31
  import uuid
32
32
  from dataclasses import dataclass, field
33
33
  from enum import IntEnum
34
- from typing import BinaryIO
34
+ from typing import BinaryIO, TypeAlias
35
35
 
36
36
  from . import xgutils
37
37
 
38
38
  # Convenience alias used throughout: a 26-element signed-byte board position.
39
- Position = tuple[int, ...]
39
+ Position: TypeAlias = tuple[
40
+ int, int, int, int, int, int, int, int, int, int,
41
+ int, int, int, int, int, int, int, int, int, int,
42
+ int, int, int, int, int, int
43
+ ]
44
+
45
+ # An 8-element move tuple: up to 4 checker moves encoded as (src1, dst1, src2, dst2, ...),
46
+ # padded with -1 sentinels for unused slots.
47
+ MoveTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int]
40
48
 
41
49
 
42
50
  # ---------------------------------------------------------------------------
@@ -1,2 +0,0 @@
1
- from xgparse.convertxg2txt import convert_xg_to_text
2
- from xgparse.extractxgdata import main as extract_xg_data
File without changes
File without changes
File without changes
File without changes
File without changes