Skip to content

Commit

Permalink
Version fixes related to neoforge and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mindstorm38 committed Jun 29, 2024
1 parent be6f53f commit fd91009
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 2 additions & 4 deletions portablemc/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,10 @@ def fabric_resolve(e: FabricResolveEvent) -> None:
ns.out.finish()

def forge_resolve(e: ForgeResolveEvent) -> None:
# api = "forge" if e._forge_repo == _FORGE_REPO else "neoforge"
api="forge"
if e.alias:
ns.out.task("..", "start.forge.resolving", api=api, version=e.forge_version)
ns.out.task("..", "start.forge.resolving", api=e._api, version=e.forge_version)
else:
ns.out.task("OK", "start.forge.resolved", api=api, version=e.forge_version)
ns.out.task("OK", "start.forge.resolved", api=e._api, version=e.forge_version)
ns.out.finish()

super().__init__({
Expand Down
25 changes: 14 additions & 11 deletions portablemc/forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,16 @@ def _resolve_version(self, watcher: Watcher) -> None:
self.forge_version = self.manifest.filter_latest(self.forge_version)[0]

# The forge version is not fully specified.
if "-" not in self.forge_version:
if "-" not in self.forge_version and self.forge_version.startswith("1."):

watcher.handle(ForgeResolveEvent(self.forge_version, True))
watcher.handle(ForgeResolveEvent(self.forge_version, True, _api = "neoforge"))
full_version = _request_neoforge_version(self.forge_version)

if full_version is None:
raise VersionNotFoundError(f"{self.prefix}-{self.forge_version}-???")

self.forge_version = full_version
watcher.handle(ForgeResolveEvent(self.forge_version, False))
watcher.handle(ForgeResolveEvent(self.forge_version, False, _api = "neoforge"))

# Finally define the full version id.
self.version = f"{self.prefix}-{self.forge_version}"
Expand Down Expand Up @@ -464,11 +464,12 @@ class ForgeResolveEvent:
The 'alias' attribute specifies if an alias version is being resolved, if false the
resolving has finished and we'll try to install the given version.
"""
__slots__ = "forge_version", "alias"
__slots__ = "forge_version", "alias", "_api"

def __init__(self, forge_version: str, alias: bool) -> None:
def __init__(self, forge_version: str, alias: bool, *, _api = "forge") -> None:
self.forge_version = forge_version
self.alias = alias
self._api = _api

class ForgePostProcessingEvent:
"""Event triggered when a post processing task is starting.
Expand Down Expand Up @@ -497,19 +498,21 @@ def _request_neoforge_version(game_version: str) -> Optional[str]:
version is of the right game version.
"""

# Just remove the first 1. because its not really the major version.
if not game_version.startswith("1."):
game_version_parts = game_version.split(".")
if len(game_version_parts) < 2 or len(game_version_parts) > 3:
return None

game_version = game_version[2:]
if not game_version:
# If the "super-major" version is not "1", abort...
if game_version_parts[0] != "1":
return None

# Special case for the first version NeoForged was introduced.
if game_version == "20.1":
if game_version_parts == [1, 20, 1]:
url = "https://maven.neoforged.net/api/maven/latest/version/releases/net%2Fneoforged%2Fforge?filter=1.20.1-"
else:
url = f"https://maven.neoforged.net/api/maven/latest/version/releases/net%2Fneoforged%2Fneoforge?filter={url_parse.quote(game_version)}"
# Just keep major and minor version number and construct the neoforge version prefix.
filter_version = ".".join(game_version_parts[1:3])
url = f"https://maven.neoforged.net/api/maven/latest/version/releases/net%2Fneoforged%2Fneoforge?filter={url_parse.quote(filter_version)}"

try:
ret = http_request("GET", url, accept="application/json").json()
Expand Down
6 changes: 3 additions & 3 deletions test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
JarNotFoundError
from portablemc.download import DownloadList
from portablemc.fabric import FabricVersion
from portablemc.forge import ForgeVersion, _NEO_FORGE_REPO
from portablemc.forge import ForgeVersion, _NeoForgeVersion

from typing import Type, Optional

Expand Down Expand Up @@ -73,12 +73,12 @@ def test_install_forge(tmp_context: Context, test_version: str):
version.install()


@pytest.mark.parametrize("test_version", ["1.20.1", "1.20.1-47.1.79"])
@pytest.mark.parametrize("test_version", ["1.20.1", "1.20.1-47.1.79", "1.21", "21.0.42-beta"])
def test_install_neoforge(tmp_context: Context, test_version: str):
"""Testing neoforge install for both old an new formats.
"""

version = ForgeVersion(test_version, _forge_repo=_NEO_FORGE_REPO)
version = _NeoForgeVersion(test_version)
version.manifest = VersionManifest(tmp_context.work_dir / "version_manifest.json")
_remove_assets(version)
version.install()

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.9

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.10

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.11

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / Ubuntu / 3.12

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / macOS / 3.9

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / macOS / 3.10

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / macOS / 3.11

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'

Check failure on line 84 in test/test_install.py

View workflow job for this annotation

GitHub Actions / macOS / 3.12

test_install_neoforge[1.20.1] portablemc.standard.VersionNotFoundError: 'neoforge-1.20.1-???'
Expand Down

0 comments on commit fd91009

Please sign in to comment.