Skip to content

Commit bda4301

Browse files
committed
Favour ruamel.yaml over PyYAML in tools
PyYAML is currently not packaged for MSYS2 UCRT64, nor it is for brew. This forces those platform to install a YAML library manually in addition to the dependencies defined in the ngdevkit package. ruamel.yaml is available in MSYS2, Ubuntu, Debian and Fedora. The missing package in brew is likely not going to change [1], but there are means to download this dependency without using pip directly. Plus, ruamel.yaml is supposed to be better at round-trip parsing and keeps comments metadata, so for the time being, import it in priority in the tools, and fall back to PyYAML when the former is not available, as both libraries share a common API. [1] https://docs.brew.sh/Homebrew-and-Python
1 parent 2e93fff commit bda4301

7 files changed

Lines changed: 79 additions & 34 deletions

File tree

.github/workflows/build-tests.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ jobs:
4040
4141
- name: Install dependencies
4242
run: |
43-
sudo apt-get install -y ngdevkit-toolchain python3 zip pkg-config
43+
sudo apt-get install -y ngdevkit-toolchain python3 python3-pil python3-ruamel.yaml zip pkg-config
4444
4545
- name: Build ngdevkit
4646
run: ./.github/scripts/build.sh
4747

4848
- name: Install dependencies for ngdevkit-examples
4949
run: >
50-
sudo apt-get install -y python3-yaml ngdevkit-gngeo python3-pil imagemagick
50+
sudo apt-get install -y ngdevkit-gngeo imagemagick
5151
sox libsox-fmt-mp3 libglew-dev libsdl2-dev
5252
5353
- name: Test by compiling ngdevkit-examples
@@ -73,24 +73,23 @@ jobs:
7373
msystem: UCRT64
7474
update: true
7575
install:
76-
git autoconf automake make zip
77-
mingw-w64-ucrt-x86_64-pkg-config mingw-w64-ucrt-x86_64-python
78-
mingw-w64-ucrt-x86_64-python-pygame
76+
git autoconf automake make zip rsync pactoys
77+
mingw-w64-ucrt-x86_64-pkg-config
78+
mingw-w64-ucrt-x86_64-python
79+
mingw-w64-ucrt-x86_64-python-pillow
80+
mingw-w64-ucrt-x86_64-python-ruamel-yaml
7981

8082
- name: Install ngdevkit dependencies
8183
run: |
8284
echo -e "[ngdevkit]\nSigLevel = Optional TrustAll\nServer = https://dciabrin.net/msys2-ngdevkit/\$arch" >> /etc/pacman.conf
8385
pacman -Sy
8486
pacman -S --disable-download-timeout --noconfirm mingw-w64-ucrt-x86_64-ngdevkit-toolchain
85-
8687
- name: Build
8788
run: ./.github/scripts/build-msys2.sh
8889

8990
- name: Install dependencies for ngdevkit-examples
9091
run: |
91-
pacman -S --noconfirm pactoys rsync
92-
pacboy -S --noconfirm python:u python-pillow:u toolchain:u zlib:u sox:u imagemagick:u
93-
pip install python-yaml
92+
pacboy -S --noconfirm ngdevkit-gngeo:u toolchain:u zlib:u sox:u imagemagick:u
9493
9594
- name: Test by compiling ngdevkit-examples
9695
run: ./.github/scripts/test.sh
@@ -112,14 +111,14 @@ jobs:
112111
brew install python3 --overwrite
113112
brew install pillow
114113
brew install automake ngdevkit-toolchain zip pkg-config sdl2 sdl2_image
114+
$(brew --prefix python)/libexec/bin/pip install ruamel.yaml --break-system-packages
115115
116116
- name: Build
117117
run: ./.github/scripts/build.sh
118118

119119
- name: Install dependencies for ngdevkit-examples
120120
run: |
121121
brew install ngdevkit-gngeo imagemagick sox glew make
122-
$(brew --prefix python)/libexec/bin/pip install pyyaml --break-system-packages
123122
124123
- name: Test by compiling ngdevkit-examples
125124
run: ./.github/scripts/test.sh

README-linux.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In order to build the devkit you need autoconf, autoconf-archive and
66
GNU Make 4.x, and various additional dependencies to build the
77
toolchain modules such as GCC and SDCC. The devkit tools uses Python 3
8-
and various dependencies (such as pillow and PyYAML).
8+
and various dependencies (such as pillow and yaml).
99
The emulator requires SDL 2 and optionally OpenGL libraries.
1010

1111
Note that older version of the devkit and its example ROMs depended
@@ -19,25 +19,26 @@ For example, on a recent Ubuntu version, you can install the dependencies with:
1919

2020
apt-get install autoconf autoconf-archive automake gcc curl zip unzip
2121
apt-get install libsdl2-dev
22-
apt-get install python3-pil
22+
apt-get install python3-pil python3-ruamel.yaml
2323
apt-get install libreadline-dev
24-
GCC_VERSION_PKG=$(apt-cache depends gcc | awk '/Depends.*gcc/ {print $2}')
25-
# make sure you have src packages enabled for dependency information
26-
echo "deb-src http://archive.ubuntu.com/ubuntu/ noble main restricted" > /etc/apt/sources.list.d/ngdevkit.list
27-
echo "deb-src http://archive.ubuntu.com/ubuntu/ noble universe" >> /etc/apt/sources.list.d/ngdevkit.list
24+
DISTRIB=$(. /etc/os-release; echo $VERSION_CODENAME)
25+
echo "deb-src http://archive.ubuntu.com/ubuntu/ $DISTRIB main restricted" > /etc/apt/sources.list.d/ngdevkit.list
26+
echo "deb-src http://archive.ubuntu.com/ubuntu/ $DISTRIB universe" >> /etc/apt/sources.list.d/ngdevkit.list
2827
apt-get update
2928
# install build-dependency packages
29+
# make sure you have src packages enabled for dependency information
30+
GCC_VERSION_PKG=$(apt-cache depends gcc | awk '/Depends.*gcc/ {print $2}')
3031
apt-get build-dep $GCC_VERSION_PKG
3132
apt-get build-dep --arch-only sdcc
3233
# optional: install GLEW for OpenGL+GLSL shaders in GnGeo
3334
apt-get install libglew-dev
3435
# dependencies for the example ROMs
3536
apt-get install imagemagick sox libsox-fmt-mp3
3637

37-
Debian users (for example Buster) would install the dependencies above
38+
Debian users (for example Trixie) would install the dependencies above
3839
by updating the src packages URL as follows:
3940

40-
echo "deb-src http://deb.debian.org/debian trixie main" > /etc/apt/sources.list.d/ngdevkit.list
41+
echo "deb-src http://deb.debian.org/debian $DISTRIB main" > /etc/apt/sources.list.d/ngdevkit.list
4142
# the remaining dependencies are the same
4243

4344
## Building the toolchain

README-macos.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ first in your PATH.
2525
In order to build the devkit you need autoconf, autoconf-archive and
2626
GNU Make 4.x, and various additional dependencies to build the
2727
toolchain modules such as GCC and SDCC. The devkit tools uses Python 3
28-
and various dependencies (such as pillow and PyYAML). The emulator
28+
and various dependencies (such as pillow and yaml). The emulator
2929
requires SDL 2 and optionally OpenGL libraries.
3030

3131
The examples require ImageMagick for all the graphics
@@ -44,6 +44,8 @@ Then, ngdevkit's dependencies are installed as follows:
4444
brew update
4545
brew install gmake
4646
brew install python3 pillow
47+
# you need a package from pip, either in a virtual env or system-wide, e.g.:
48+
# $(brew --prefix python)/libexec/bin/pip install ruamel.yaml --break-system-packages
4749
brew deps gcc | xargs brew install
4850
brew deps sdcc | xargs brew install
4951
# dependencies for the example ROMs

README-msys2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ngdevkit dependencies:
6363
pacboy -S autoconf autoconf-archive automake pkgconf make tar zip unzip
6464
pacboy -S git flex bison expat gettext ncurses-devel zlib-devel
6565
pacboy -S gmp-devel isl-devel mpc-devel mpfr-devel texinfo
66-
pacboy -S python:u python-yaml python-pillow:u toolchain:u zlib:u
66+
pacboy -S python:u python-ruamel-yaml:u python-pillow:u toolchain:u zlib:u
6767
# dependencies for the example ROMs
6868
pacboy -S rsync sox:u imagemagick:u SDL2:u glew:u boost:u
6969

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ of dependencies for the examples ROMs:
5555

5656
add-apt-repository -y ppa:dciabrin/ngdevkit
5757
apt update
58-
apt install ngdevkit ngdevkit-gngeo
58+
apt install ngdevkit
5959
# the remaining packages are only required for the examples
60-
apt install pkg-config autoconf zip imagemagick sox libsox-fmt-mp3
60+
apt install pkg-config autoconf zip imagemagick sox libsox-fmt-mp3 ngdevkit-gngeo
6161

6262
If you are running a Fedora distribution, pre-built packages are
6363
available in COPR, and can be installed with the following commands:
6464

6565
dnf copr enable dciabrin/ngdevkit
66-
dnf install ngdevkit ngdevkit-gngeo
66+
dnf install ngdevkit
6767
# the remaining packages are only requred for the examples
68-
dnf install install pkg-config autoconf zip ImageMagick sox
68+
dnf install install pkg-config autoconf zip ImageMagick sox ngdevkit-gngeo
6969

7070
#### macOS
7171

@@ -78,9 +78,9 @@ packages, available in the ngdevkit tap:
7878
eval $(/opt/homebrew/bin/brew shellenv)
7979
# install ngdevkit
8080
brew tap dciabrin/ngdevkit
81-
brew install ngdevkit ngdevkit-gngeo
81+
brew install ngdevkit
8282
# the remaining packages are only required for the examples
83-
brew install pkg-config autoconf automake zip imagemagick sox
83+
brew install pkg-config autoconf automake zip imagemagick sox ngdevkit-gngeo
8484

8585
Brew bottles are available for the last two versions of macOS for ARM.
8686
Intel brew bottles are no longer prebuilt. Older versions of macOS are
@@ -98,9 +98,9 @@ configure the pacman repository as follows:
9898
echo -e "\n[ngdevkit]\nSigLevel = Optional TrustAll\nServer = https://dciabrin.net/msys2-ngdevkit/\$arch" >> /etc/pacman.conf
9999
# install pacboy with `pacman -S pactoys` if necessary
100100
pacboy -Sy
101-
pacboy -S ngdevkit:u ngdevkit-gngeo:u
101+
pacboy -S ngdevkit:u
102102
# the remaining packages are only required for the examples
103-
pacboy -S autoconf automake make zip imagemagick:u sox:u
103+
pacboy -S autoconf automake make zip imagemagick:u sox:u ngdevkit-gngeo:u
104104

105105
An old version of ngdevkit supported Windows 10 via [WSL][wsl], but it
106106
is now deprecated in favour of the native MSYS2 environment. Likewise,

tools/soundtool.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,39 @@
2020
import argparse
2121
import re
2222
import sys
23-
import yaml
2423
import glob
2524
import os
2625
import wave
2726

27+
# Special handling for YAML: try to import ruamel.yaml first,
28+
# because it's better at keeping comments in YAML files, and
29+
# default to yaml if not found, as they are API-compatible.
30+
try:
31+
import ruamel.yaml
32+
_yaml = "ruamel"
33+
except ImportError:
34+
import yaml
35+
_yaml = "PyYAML"
36+
37+
def yaml_load_all(f):
38+
if _yaml == "ruamel":
39+
return ruamel.yaml.YAML().load_all(f)
40+
else:
41+
return yaml.safe_load_all(f)
42+
43+
def yaml_load(f):
44+
if _yaml == "ruamel":
45+
return ruamel.yaml.YAML().load(f)
46+
else:
47+
return yaml.safe_load(f)
48+
49+
def yaml_dump(data, end, f):
50+
if _yaml == "ruamel":
51+
return ruamel.yaml.YAML().dump(data, stream=f)
52+
else:
53+
return yaml.dump(data, end=end, stream=f)
54+
55+
2856
VERBOSE = False
2957

3058

@@ -44,7 +72,7 @@ def load_sound_desc(descfile):
4472
descdata = open(descfile,'r').read()
4573
comments = [l for l in descdata.split('\n') if re.search(r'^#', l)]
4674
header = "\n".join(comments)
47-
yamldata = sum(list(yaml.safe_load_all(descdata)), [])
75+
yamldata = sum(list(yaml_load_all(descdata)), [])
4876
return header+"\n", yamldata
4977

5078

@@ -117,7 +145,7 @@ def detect_adpcm_type(f):
117145

118146
# save sound map description
119147
print(header, end='', file=output)
120-
print(yaml.dump(result_data), end='', file=output)
148+
print(yaml_dump(result_data), end='', file=output)
121149

122150

123151

@@ -405,7 +433,7 @@ def main():
405433
# Otherwise load a sound map from the input yaml file
406434
for smap in arguments.soundmap:
407435
with open(smap, 'r') as f:
408-
desc.extend(yaml.safe_load(f.read()))
436+
desc.extend(yaml_load(f.read()))
409437

410438
# generate z80 macros
411439
if arguments.action == 'z80':

tools/vromtool.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@
2727
import wave
2828
from adpcmtool import ym2610_adpcma, ym2610_adpcmb
2929

30-
import yaml
30+
# Special handling for YAML: try to import ruamel.yaml first,
31+
# because it's better at keeping comments in YAML files, and
32+
# default to yaml if not found, as they are API-compatible.
33+
try:
34+
import ruamel.yaml
35+
_yaml = "ruamel"
36+
except ImportError:
37+
import yaml
38+
_yaml = "PyYAML"
39+
40+
def yaml_load_all(f):
41+
if _yaml == "ruamel":
42+
return ruamel.yaml.YAML().load_all(f)
43+
else:
44+
return yaml.safe_load_all(f)
45+
3146

3247
VERBOSE = False
3348

@@ -162,7 +177,7 @@ def load_sample_map_file(filenames):
162177
for filename in filenames:
163178
ysamples = []
164179
with open(filename, "rb") as f:
165-
yamlblocks = list(yaml.load_all(f, yaml.Loader))
180+
yamlblocks = list(yaml_load_all(f))
166181
for b in yamlblocks:
167182
ysamples.extend(b)
168183
all_ysamples.extend([filename, y] for y in ysamples)

0 commit comments

Comments
 (0)