Skip to content

Commit 6c39f2b

Browse files
authored
Merge pull request #2 from apple1417/master
integrate with mods db
2 parents 1c4ef1c + d87d5ef commit 6c39f2b

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Setup Python
8282
uses: actions/setup-python@v4
8383
with:
84-
python-version: ">=3.10"
84+
python-version: ">=3.11"
8585

8686
- name: Checkout repository and submodules
8787
uses: actions/checkout@v3
@@ -136,6 +136,11 @@ jobs:
136136
- name: Setup CMake and Ninja
137137
uses: lukka/get-cmake@latest
138138

139+
- name: Setup Python
140+
uses: actions/setup-python@v4
141+
with:
142+
python-version: ">=3.11"
143+
139144
- name: Setup msitools
140145
uses: awalsh128/cache-apt-pkgs-action@latest
141146
with:
@@ -258,7 +263,7 @@ jobs:
258263
- name: Setup Python
259264
uses: actions/setup-python@v4
260265
with:
261-
python-version: ">=3.10"
266+
python-version: ">=3.11"
262267

263268
- name: Checkout repository and submodules
264269
uses: actions/checkout@v3

prepare_release.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shutil
44
import subprocess
55
import textwrap
6+
import tomllib
67
from collections.abc import Iterator, Sequence
78
from functools import cache
89
from io import BytesIO
@@ -244,7 +245,7 @@ def zip_release(
244245
STUBS_DIR = Path("libs") / "pyunrealsdk" / "stubs"
245246
SETTINGS_DIR = Path("src") / "settings"
246247

247-
GIT_VERSION_FILE = BASE_MOD / "git_version.txt"
248+
PYPROJECT_FILE = BASE_MOD / "pyproject.toml"
248249

249250
parser = ArgumentParser(description="Prepares a release zip.")
250251
parser.add_argument(
@@ -275,12 +276,6 @@ def zip_release(
275276
default=False,
276277
help="Create a unified release zip. Defaults to off.",
277278
)
278-
parser.add_argument(
279-
"--update-git-version-txt",
280-
action=BooleanOptionalAction,
281-
default=True,
282-
help="Updates the `git_version.txt`. Defaults to on.",
283-
)
284279
args = parser.parse_args()
285280

286281
install_dir = INSTALL_DIR_BASE / str(args.preset)
@@ -291,10 +286,18 @@ def zip_release(
291286

292287
assert install_dir.exists() and install_dir.is_dir(), "install dir doesn't exist"
293288

294-
if args.update_git_version_txt:
295-
with GIT_VERSION_FILE.open("w") as file:
296-
file.write(get_git_repo_version())
289+
# Add the git hash to the displayed version in the pyproject
290+
old_pyproject = PYPROJECT_FILE.read_text()
291+
version_number = tomllib.loads(old_pyproject)["project"]["version"]
292+
git_version = get_git_repo_version()
293+
PYPROJECT_FILE.write_text(
294+
old_pyproject.replace(
295+
"# RELEASE_SCRIPT_REPLACE_ME_WITH_DISPLAY_VERSION",
296+
f'version = "{version_number} ({git_version})"',
297+
),
298+
)
297299

300+
# Zip up all the requested files
298301
COMMON_FOLDERS = (BASE_MOD, KEYBINDS, UI_UTILS)
299302

300303
for prefix, arg, mods in (
@@ -317,3 +320,6 @@ def zip_release(
317320
SETTINGS_DIR,
318321
install_dir,
319322
)
323+
324+
# Restore the old pyproject contents
325+
PYPROJECT_FILE.write_text(old_pyproject)

src/mods_base/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/mods_base/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
import tomllib
12
from pathlib import Path
23

34
import unrealsdk
45
from unrealsdk.unreal import UObject
56

7+
from .dot_sdkmod import open_in_mod_dir
8+
69
# Need to define a few things first to avoid circular imports
7-
__version_info__: tuple[int, int] = (1, 0)
8-
__version__: str = f"{__version_info__[0]}.{__version_info__[1]}"
10+
with open_in_mod_dir(Path(__file__).parent / "pyproject.toml", binary=True) as _pyproject:
11+
# We're being a bit unsafe here, but we know what we expect to see, and given we expect to be
12+
# in a .sdkmod it's quite unlikely that a regular user will unknowingly edit it
13+
_pyproject_data = tomllib.load(_pyproject)
14+
_version_str = _pyproject_data["project"]["version"]
15+
_major, _, _minor = _version_str.partition(".")
916

10-
if True: # Inner block suppresses E402 for following imports
17+
__version_info__: tuple[int, int] = (int(_major), int(_minor))
18+
__version__: str = _pyproject_data["tool"]["sdkmod"].get("version", _version_str)
19+
del _major, _, _minor, _version_str, _pyproject_data, _pyproject
20+
21+
# This doesn't need to be in the inner block, but exiting would cause E402 for following imports
1122
MODS_DIR: Path = (
1223
_mod_dir
1324
if (_mod_dir := Path(__file__).parent.parent).is_dir()
@@ -23,7 +34,6 @@
2334
command,
2435
remove_next_console_line_capture,
2536
)
26-
from .dot_sdkmod import open_in_mod_dir
2737
from .hook import hook
2838
from .keybinds import EInputEvent, KeybindType, keybind
2939
from .mod import Game, Library, Mod, ModType

src/mods_base/mod_list.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
from . import MODS_DIR, __version__
1111
from .command import AbstractCommand
12-
from .dot_sdkmod import open_in_mod_dir
1312
from .hook import HookProtocol
1413
from .keybinds import KeybindType
1514
from .mod import Library, Mod, ModType
1615
from .options import BaseOption, ButtonOption
1716
from .settings import SETTINGS_DIR
1817

18+
MOD_DB_URL = "https://bl-sdk.github.io/oak-mod-db/"
19+
1920

2021
@dataclass
2122
class BaseMod(Library):
@@ -62,29 +63,26 @@ def description( # pyright: ignore[reportIncompatibleVariableOverride]
6263
"""No-op description setter."""
6364

6465

65-
try:
66-
with open_in_mod_dir(Path(__file__).with_name("git_version.txt")) as file:
67-
_base_mod_version = f"{__version__} ({file.read().strip()})"
68-
except FileNotFoundError:
69-
_base_mod_version = __version__
70-
7166
mod_list: list[Mod] = [
7267
base_mod := BaseMod(
7368
options=[
7469
ButtonOption(
75-
"Open Mods Folder",
70+
"Open Mod Database",
71+
on_press=lambda _: os.startfile(MOD_DB_URL), # type: ignore
72+
),
73+
ButtonOption(
74+
"Open Installed Mods Folder",
7675
on_press=lambda _: os.startfile(MODS_DIR), # type: ignore
7776
),
7877
],
7978
components=[
80-
BaseMod.ComponentInfo("Base", _base_mod_version),
79+
BaseMod.ComponentInfo("Base", __version__),
8180
# Both of these start their version strings with their module name, strip it out
8281
BaseMod.ComponentInfo("unrealsdk", unrealsdk.__version__.partition(" ")[2]),
8382
BaseMod.ComponentInfo("pyunrealsdk", pyunrealsdk.__version__.partition(" ")[2]),
8483
],
8584
),
8685
]
87-
del _base_mod_version
8886

8987

9088
def register_mod(mod: Mod) -> None:

src/mods_base/pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "mods_base"
3+
version = "1.0"
4+
authors = [{ name = "bl-sdk" }]
5+
description = "The SDK itself."
6+
7+
[tool.sdkmod]
8+
name = "Python SDK"
9+
# RELEASE_SCRIPT_REPLACE_ME_WITH_DISPLAY_VERSION
10+
license = {name = "LGPL3", url = "https://choosealicense.com/licenses/lgpl-3.0/" }
11+
download = "https://github.com/bl-sdk/oak-mod-manager/releases/latest"

0 commit comments

Comments
 (0)