Skip to content

Commit 0d338f7

Browse files
authored
Merge pull request #668 from monkeyman192/add_uv
Add uv to make running python code easier
2 parents 312b8ce + 9c021e6 commit 0d338f7

File tree

6 files changed

+386
-7
lines changed

6 files changed

+386
-7
lines changed

.github/workflows/pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ jobs:
5353
python-version: "3.9"
5454
- name: Install dependencies
5555
run: |
56-
python -m pip install --upgrade pip
57-
pip install pytest requests
56+
python -m pip install --upgrade pip uv
57+
uv sync
5858
- name: Run tests
59-
run: python -m pytest --mbincompiler_path="./MBINCompiler.exe" --tb=no --report
59+
run: uv run python -m pytest --mbincompiler_path="./MBINCompiler.exe" --tb=no --report
6060
- name: Upload Windows binaries
6161
uses: actions/upload-artifact@v4
6262
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ paket-files/
262262
# python-related files
263263
*.pyc
264264
.pytest_cache/
265+
.venv/
265266

266267
# test data
267268
tests/**/*.MBIN

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,25 @@ dotnet publish -c Release -f net6.0-windows -r win-x64 -o Build/Release/net6/ /n
112112

113113
For convenience we have included two batch scripts which build either the entire project for the .NET 6 framework (`build-net6.bat`) or the .NET 7 framework (`build-net7.bat`)
114114

115+
## Installing python dependencies
116+
117+
The unit tests and auto-extractor scripts are written in python.
118+
The easiest way to set up the correct environment to run the tests is to install [uv](https://github.com/astral-sh/uv). You can do this by running `python -m pip install -U uv`.
119+
Once run, you can run `uv sync` to install all the required dependencies.
115120

116121
## TESTING INSTRUCTIONS
117122

118123
For anyone helping to develop MBINCompiler, if you are contributing new structs or updating existing ones, it is good to ensure that the tests that are run on the CI service that builds and tests MBINCompiler will pass.
119124

120125
### Requirements
121126

122-
To run the tests you will need python installed and on the path. It is recommended you get a recent version (3.9 or above).
123-
The required dependencies are `pytest` and `requests`. These can be installed by entering `python -m pip install -U pytest requests` in your favorite command line program.
124127
Before running the tests, you need to have built a `Release` version of MBINCompiler locally.
128+
You can do this by running `dotnet publish --no-self-contained -c Release -f net6.0 -r win-x64 /nowarn:cs0618 /nowarn:cs0169 /nowarn:cs0414` (change dotnet and framework version as required).
129+
See section above about building for more details.
125130

126131
### Running the tests
127132

128-
Open a command line window in the root MBINCompiler directory and enter `python -m pytest`.
133+
Open a command line window in the root MBINCompiler directory and enter `uv run python -m pytest`.
129134
This will pull the latest test data into the directory `./tests/data`.
130135

131136
#### Command line arguments:
@@ -149,5 +154,12 @@ Use of `--use_cache=True` should only be done if you are 100% sure that the loca
149154

150155
`--datapath` is primarily used for running tests on folder of data files to test which files pass or fail for the updating of the `MBINCompiler-test-data` repository. This option can however be used to point the tests at any other directory (such as an unpacked PCBANKS directory or sub-folder to run the tests on any of the games' files.)
151156

157+
## Running the auto-extractor
158+
159+
MBINCompiler has a script which can be used to automatically extract the latest .cs files for the current game version.
160+
To run this simply run `uv run python ./Tools/auto_extract/extractor.py`
161+
This will run the game and extract all the files as required.
162+
Note that this will overwrite the files in the local folder, so it's recommended to either back up your local files or create a new branch if you have cloned this repo.
163+
152164
## CREDITS
153165
Original project thanks to Emoose: https://github.com/emoose/MBINCompiler

Tools/auto_extract/extractor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import pymem
1919

2020

21+
CWD = op.dirname(__file__)
22+
23+
2124
GUID_REGEX = re.compile(r'GUID = (0x[a-fA-F0-9]+)')
2225

2326
RESTRICTED_NAMES = (
@@ -886,7 +889,7 @@ def find_classes(nms_path: pathlib.Path):
886889
_guid_hash = 0
887890
for guid in guids:
888891
_guid_hash = (_guid_hash ^ guid) & 0xFFFFFFFFFFFFFFFF
889-
with open(f'guids_{fmt_hex(_guid_hash)}.json', 'w') as f:
892+
with open(op.join(CWD, f'guids_{fmt_hex(_guid_hash)}.json'), 'w') as f:
890893
f.write(json.dumps(class_guid_mapping))
891894
for cls_ in classes:
892895
# Before writing out, loop over the fields of the class also to

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "mbincompiler"
3+
version = "1.0.0"
4+
description = "Unit test and extraction tools for MBINCompiler"
5+
readme = "README.md"
6+
requires-python = ">=3.9"
7+
dependencies = [
8+
"pytest",
9+
"requests",
10+
"jinja2",
11+
"pymem"
12+
]

0 commit comments

Comments
 (0)