Skip to content

Commit

Permalink
refactor(backend): get version from package metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 committed Nov 14, 2023
1 parent 13e59c2 commit 5aa03a6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
16 changes: 14 additions & 2 deletions backend/decky_loader/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
from hashlib import sha256
from io import BytesIO
import importlib.metadata

import certifi
from aiohttp.web import Request, Response, middleware
Expand All @@ -13,6 +14,7 @@
from .localplatform import localplatform
from .customtypes import UserType
from logging import getLogger
from packaging.version import Version

REMOTE_DEBUGGER_UNIT = "steam-web-debug-portforward.service"

Expand Down Expand Up @@ -49,8 +51,18 @@ def mkdir_as_user(path: str):
# Fetches the version of loader
def get_loader_version() -> str:
try:
with open(os.path.join(os.getcwd(), ".loader.version"), "r", encoding="utf-8") as version_file:
return version_file.readline().strip()
# Normalize Python-style version to conform to Decky style
v = Version(importlib.metadata.version("decky_loader"))

version_str = f'v{v.major}.{v.minor}.{v.micro}'

if v.pre:
version_str += f'-pre{v.pre[1]}'

if v.post:
version_str += f'-post{v.post}'

return version_str
except Exception as e:
logger.warn(f"Failed to execute get_loader_version(): {str(e)}")
return "unknown"
Expand Down
4 changes: 0 additions & 4 deletions backend/decky_loader/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async def do_update(self):
logger.error("Unable to update as remoteVer is missing")
return

version = self.remoteVer["tag_name"]
download_url = None
download_filename = "PluginLoader" if ON_LINUX else "PluginLoader.exe"
download_temp_filename = download_filename + ".new"
Expand Down Expand Up @@ -217,9 +216,6 @@ async def do_update(self):
self.context.loop.create_task(tab.evaluate_js(f"window.DeckyUpdater.updateProgress({new_progress})", False, False, False))
progress = new_progress

with open(path.join(getcwd(), ".loader.version"), "w", encoding="utf-8") as out:
out.write(version)

if ON_LINUX:
remove(path.join(getcwd(), download_filename))
shutil.move(path.join(getcwd(), download_temp_filename), path.join(getcwd(), download_filename))
Expand Down
13 changes: 12 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aiohttp-jinja2 = "^1.5.1"
aiohttp-cors = "^0.7.0"
watchdog = "^2.1.7"
certifi = "*"
packaging = "^23.2"

[tool.poetry.group.dev.dependencies]
pyinstaller = "^5.13.0"
Expand Down

0 comments on commit 5aa03a6

Please sign in to comment.