From e1b8d3eb0de763548f8bec60801a4d0cc88ca12f Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:31:23 -0600 Subject: [PATCH 1/4] [Currently untested] Better LWJGL version resolver --- src/fix_lwjgl/__init__.py | 50 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/fix_lwjgl/__init__.py b/src/fix_lwjgl/__init__.py index 79c59ec..35aa3f9 100644 --- a/src/fix_lwjgl/__init__.py +++ b/src/fix_lwjgl/__init__.py @@ -488,26 +488,52 @@ async def rewrite_class_path_lwjgl2( return class_path +def discover_lwjgl_version(version_string: str) -> int: + """Discover version of lwjgl to use from version string.""" + # Extract grouped numbers + parsed = [] + current = "" + # Extra space at end means last number group will + # be added to parsed properly because digit check fails + for char in f"{version_string} ": + if char in "0123456789": + current += char + elif current: + parsed.append(int(current)) + current = "" + + parsed_version = tuple(parsed) + + if "w" in version_string: + # The snapshot minecraft updated to lwjgl 3 is apparently 17w43b + if parsed_version >= (17, 43): + return 3 + return 2 + if parsed_version >= (1, 13): + return 3 + return 2 + + async def rewrite_mc_args( loop: asyncio.AbstractEventLoop, mc_args: list[str] ) -> list[str]: - "Rewrite minecraft arguments" + """Rewrite minecraft arguments.""" global BASE_FOLDER # pylint: disable=global-statement if "-cp" not in mc_args: return mc_args - mc_vers = tuple( - map(int, mc_args[mc_args.index("--version") + 1].split(".")) - ) - lwjgl_vers = 2 if mc_vers < (1, 13) else 3 - # The snapshot minecraft updated to lwjgl 3 is apparently 17w43b - # TODO: Handle snapshots properly + raw_version = "Legacy Minecraft" + lwjgl_vers = 2 + if "--version" in mc_args: + raw_version = mc_args[mc_args.index("--version") + 1] + lwjgl_vers = discover_lwjgl_version(raw_version) - lib_path = None - for arg in mc_args: + lib_path: str | None = None + for arg in reversed(mc_args): if arg.startswith("-Dorg.lwjgl.librarypath="): lib_path = arg.split("=", 1)[1] + break cls_path = mc_args.index("-cp") @@ -534,8 +560,7 @@ async def rewrite_mc_args( mc_args[cls_path + 1] = os.pathsep.join(class_path) - mc_ver_text = ".".join(map(str, mc_vers)) - log(f"Rewrote lwjgl class paths for {mc_ver_text} (LWJGL {lwjgl_vers})") + log(f"Rewrote lwjgl class paths for {raw_version} (LWJGL {lwjgl_vers})") return mc_args @@ -613,6 +638,9 @@ def run(args: list[str]) -> int: if not args: log("No java arguments to rewrite lwjgl class paths for!") + log( + "Make sure you are using `Wrapper Command` and not pre or post launch command!" + ) return 1 if args[0].lower() == "-noop": From 09a632a6c28c21d140119f8481c6790f214ed511 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 04:49:09 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- src/fix_lwjgl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_lwjgl/__init__.py b/src/fix_lwjgl/__init__.py index dd7f7fe..6ae5f9d 100644 --- a/src/fix_lwjgl/__init__.py +++ b/src/fix_lwjgl/__init__.py @@ -661,7 +661,7 @@ def run(args: list[str]) -> int: if not args: log("No java arguments to rewrite lwjgl class paths for!") log( - "Make sure you are using `Wrapper Command` and not pre or post launch command!" + "Make sure you are using `Wrapper Command` and not pre or post launch command!", ) return 1 From 73116adb4fd58c1cbe3b5af2c6fe8a980c114e1d Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:00:00 -0500 Subject: [PATCH 3/4] Run tests for versions we claim to support --- .github/dependabot.yml | 4 ---- .github/workflows/tests.yml | 40 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 6 +++++- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8919d38..6187589 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,7 +10,3 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" - commit-message: - prefix: "[pip prod] " - prefix-development: "[pip dev] " - include: "scope" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d502524 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: Tests + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + push: + branches: ["main"] + pull_request: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + test: + # The type of runner that the job will run on + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@main + with: + python-version: ${{ matrix.python-version }} + cache: pip + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions + - name: Test with tox + run: tox diff --git a/pyproject.toml b/pyproject.toml index 364090b..0bd2172 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -163,7 +163,11 @@ legacy_tox_ini = """ [gh-actions] python = - 3.11: py311, pytest, mypy + 3.8: py38, pytest, mypy + 3.9: py39, pytest + 3.10: py310, pytest + 3.11: py311, pytest + 3.12: py312, pytest, mypy [testenv] setenv = From 4c69d0e61087a876d87bd21ae1456f55675767c5 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:25:12 -0500 Subject: [PATCH 4/4] Add tests and make sure they run --- pyproject.toml | 13 ++++++++-- tests/test_init.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/test_init.py diff --git a/pyproject.toml b/pyproject.toml index 0bd2172..a67bf86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ warn_unreachable = true warn_unused_configs = true warn_unused_ignores = true -[tool.ruff.isort] +[tool.ruff.lint.isort] combine-as-imports = true [tool.pycln] @@ -84,6 +84,8 @@ line-length = 79 fix = true include = ["*.py", "*.pyi", "**/pyproject.toml"] + +[tool.ruff.lint] select = [ "A", # flake8-builtins "ASYNC", # flake8-async @@ -121,6 +123,13 @@ extend-ignore = [ "SIM117", # Use multiple with statements at the same time ] +[tool.ruff.lint.per-file-ignores] +"tests/*" = [ + "D100", # undocumented-public-module + "D103", # undocumented-public-function + "D107", # Missing docstring +] + [tool.pytest.ini_options] addopts = "--cov-report term-missing --cov=fix_lwjgl" testpaths = [ @@ -158,7 +167,7 @@ partial_branches = [ [tool.tox] legacy_tox_ini = """ [tox] - envlist = py311, mypy + envlist = py38, py39, py310, py311, py312, mypy, pytest isolated_build = false [gh-actions] diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..bd4cc8f --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +import os + +import fix_lwjgl +import pytest + + +def test_get_paths() -> None: + assert fix_lwjgl.get_paths( + { + "": [ + "main.py", + "waffles.txt", + ], + "folder": { + "": [ + "folder_one.txt", + ], + "inner": { + "": [ + "folder_two.txt", + ], + "inner_two": [ + "folder_three.txt", + ], + }, + }, + }, + ) == [ + "main.py", + "waffles.txt", + os.path.join("folder", "folder_one.txt"), + os.path.join("folder", "inner", "folder_two.txt"), + os.path.join("folder", "inner", "inner_two", "folder_three.txt"), + ] + + +def test_get_address() -> None: + assert ( + fix_lwjgl.get_address("CoolCat467", "fix-lwjgl", "HEAD", "README.md") + == "https://raw.githubusercontent.com/CoolCat467/fix-lwjgl/HEAD/README.md" + ) + + +def test_get_lwjgl_file_url() -> None: + assert ( + fix_lwjgl.get_lwjgl_file_url("bin/lwjgl/lwjgl.jar") + == "https://build.lwjgl.org/release/latest/bin/lwjgl/lwjgl.jar" + ) + + +@pytest.mark.parametrize( + ("version", "expected"), + [ + ("17w43b", 3), + ("17w42b", 2), + ("1.12.2", 2), + ("1.13.0", 3), + ("1.7.10", 2), + ("1.20.1", 3), + ], +) +def test_discover_lwjgl_version(version: str, expected: int) -> None: + assert fix_lwjgl.discover_lwjgl_version(version) == expected