Skip to content

Commit

Permalink
Merge pull request #483 from loathingKernel/develop
Browse files Browse the repository at this point in the history
Restore compatibility with python 3.9
  • Loading branch information
loathingKernel authored Dec 23, 2024
2 parents 144f01c + 16ecf4a commit 9e6fa05
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/job_cx-freeze-msi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
pip3 install -r requirements-presence.txt
- name: Build
run: |
python freeze.py bdist_msi
python misc/freeze.py bdist_msi
mv dist/*.msi Rare.msi
- name: Upload artifact
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/job_cx-freeze-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ jobs:
pip3 install -r requirements-presence.txt
pip3 install .
- name: Build
run: cxfreeze -c rare/main.py --target-dir dist --target-name rare --icon rare/resources/images/Rare.ico -OO --base-name Win32GUI
run: >-
cxfreeze
-c rare/main.py
--target-dir dist
--target-name rare
--icon rare/resources/images/Rare.ico
-OO
--base-name Win32GUI
- name: Compress
run: |
python -c "import shutil; shutil.make_archive('Rare', 'zip', 'rare.dist')"
Expand Down
2 changes: 1 addition & 1 deletion freeze.py → misc/freeze_msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name = 'Rare'
author = 'RareDevs'
description = 'A gui for legendary'
description = 'Open source alternative for Epic Games Launcher, using Legendary'

shortcut_table = [
("DesktopShortcut", # Shortcut
Expand Down
2 changes: 1 addition & 1 deletion misc/rare.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Type=Application
Categories=Game;
Icon=rare
Exec=rare
Comment=A GUI for legendary, an open source replacement for Epic Games Launcher
Comment=Open source alternative for Epic Games Launcher, using Legendary
Terminal=false
StartupWMClass=rare
Keywords=epic;games;launcher;legendary;
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ force-exclude = '''
[tool.poetry]
name = "rare"
version = "1.10.11"
description = "A gui for legendary"
description = "Open source alternative for Epic Games Launcher, using Legendary"
authors = ["RareDevs"]
license = "GPL3"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions rare/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from argparse import Namespace
from datetime import datetime, timezone, UTC
from datetime import datetime, timezone
from typing import Optional

import requests.exceptions
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, args: Namespace):

def poke_timer(self):
dt_exp = datetime.fromisoformat(self.core.lgd.userdata['expires_at'][:-1]).replace(tzinfo=timezone.utc)
dt_now = datetime.now(UTC)
dt_now = datetime.now(timezone.utc)
td = abs(dt_exp - dt_now)
self.relogin_timer.start(int(td.total_seconds() - 60) * 1000)
self.logger.info(f"Renewed session expires at {self.core.lgd.userdata['expires_at']}")
Expand Down
4 changes: 2 additions & 2 deletions rare/components/tabs/store/api/models/query.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass, field
from datetime import datetime, timezone, UTC
from datetime import datetime, timezone
from typing import List


@dataclass
class SearchDateRange:
start_date: datetime = datetime(year=1990, month=1, day=1, tzinfo=timezone.utc)
end_date: datetime = datetime.now(UTC)
end_date: datetime = datetime.now(timezone.utc)

def __str__(self):
def fmt_date(date: datetime) -> str:
Expand Down
4 changes: 2 additions & 2 deletions rare/components/tabs/store/landing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import datetime, UTC
from datetime import datetime, timezone
from typing import List

from PySide6.QtCore import Qt, Slot, Signal, QObject, QEvent
Expand Down Expand Up @@ -184,7 +184,7 @@ def __update_free_games(self, free_games: List[CatalogOfferModel]):
self.free_games_next.layout().removeWidget(w)
w.deleteLater()

date = datetime.now(UTC)
date = datetime.now(timezone.utc)
free_now = []
free_next = []
for item in free_games:
Expand Down
26 changes: 13 additions & 13 deletions rare/models/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import platform
from dataclasses import dataclass, field
from datetime import datetime, UTC
from datetime import datetime, timezone
from logging import getLogger
from threading import Lock
from typing import List, Optional, Dict, Set
Expand Down Expand Up @@ -30,19 +30,19 @@ class RareGame(RareGameSlim):
class Metadata:
queued: bool = False
queue_pos: Optional[int] = None
last_played: datetime = datetime.min.replace(tzinfo=UTC)
grant_date: datetime = datetime.min.replace(tzinfo=UTC)
last_played: datetime = datetime.min.replace(tzinfo=timezone.utc)
grant_date: datetime = datetime.min.replace(tzinfo=timezone.utc)
steam_appid: Optional[int] = None
steam_grade: Optional[str] = None
steam_date: datetime = datetime.min.replace(tzinfo=UTC)
steam_date: datetime = datetime.min.replace(tzinfo=timezone.utc)
steam_shortcut: Optional[int] = None
tags: List[str] = field(default_factory=list)

# For compatibility with previously created game metadata
@staticmethod
def parse_date(strdate: str):
dt = datetime.fromisoformat(strdate) if strdate else datetime.min
return dt.replace(tzinfo=UTC)
return dt.replace(tzinfo=timezone.utc)

@classmethod
def from_dict(cls, data: Dict):
Expand All @@ -63,11 +63,11 @@ def __dict__(self):
return dict(
queued=self.queued,
queue_pos=self.queue_pos,
last_played=self.last_played.isoformat() if self.last_played else datetime.min.replace(tzinfo=UTC),
grant_date=self.grant_date.isoformat() if self.grant_date else datetime.min.replace(tzinfo=UTC),
last_played=self.last_played.isoformat() if self.last_played else datetime.min.replace(tzinfo=timezone.utc),
grant_date=self.grant_date.isoformat() if self.grant_date else datetime.min.replace(tzinfo=timezone.utc),
steam_appid=self.steam_appid,
steam_grade=self.steam_grade,
steam_date=self.steam_date.isoformat() if self.steam_date else datetime.min.replace(tzinfo=UTC),
steam_date=self.steam_date.isoformat() if self.steam_date else datetime.min.replace(tzinfo=timezone.utc),
steam_shortcut=self.steam_shortcut,
tags=self.tags,
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def set_worker(self, worker: Optional[QRunnable]):
@Slot(int)
def __game_launched(self, code: int):
self.state = RareGame.State.RUNNING
self.metadata.last_played = datetime.now(UTC)
self.metadata.last_played = datetime.now(timezone.utc)
if code == GameProcess.Code.ON_STARTUP:
return
self.__save_metadata()
Expand Down Expand Up @@ -440,7 +440,7 @@ def steam_grade(self) -> str:
if platform.system() == "Windows" or self.is_unreal:
return "na"
if self.metadata.steam_grade != "pending":
elapsed_time = abs(datetime.now(UTC) - self.metadata.steam_date)
elapsed_time = abs(datetime.now(timezone.utc) - self.metadata.steam_date)
if elapsed_time.days > 3:
logger.info("Refreshing ProtonDB grade for %s", self.app_title)
worker = QRunnable.create(self.set_steam_grade)
Expand All @@ -463,20 +463,20 @@ def set_steam_grade(self) -> None:
if appid and self.steam_appid is None:
self.set_steam_appid(appid)
self.metadata.steam_grade = grade
self.metadata.steam_date = datetime.now(UTC)
self.metadata.steam_date = datetime.now(timezone.utc)
self.__save_metadata()
self.signals.widget.update.emit()

def grant_date(self, force=False) -> datetime:
if not (entitlements := self.core.lgd.entitlements):
return self.metadata.grant_date
if self.metadata.grant_date == datetime.min.replace(tzinfo=UTC) or force:
if self.metadata.grant_date == datetime.min.replace(tzinfo=timezone.utc) or force:
logger.debug("Grant date for %s not found in metadata, resolving", self.app_name)
matching = filter(lambda ent: ent["namespace"] == self.game.namespace, entitlements)
entitlement = next(matching, None)
grant_date = datetime.fromisoformat(
entitlement["grantDate"].replace("Z", "+00:00")
) if entitlement else datetime.min.replace(tzinfo=UTC)
) if entitlement else datetime.min.replace(tzinfo=timezone.utc)
self.metadata.grant_date = grant_date
self.__save_metadata()
return self.metadata.grant_date
Expand Down
4 changes: 2 additions & 2 deletions rare/models/pathspec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Union, List, LiteralString
from typing import Union, List

from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame
Expand Down Expand Up @@ -65,6 +65,6 @@ def __init__(self, core: LegendaryCore = None, igame: InstalledGame = None):
if igame is not None:
self.__egl_path_vars["{installdir}"] = igame.install_path

def resolve_egl_path_vars(self, path: str) -> Union[LiteralString, str, bytes]:
def resolve_egl_path_vars(self, path: str) -> Union[str, bytes]:
cooked_path = (self.__egl_path_vars.get(p.lower(), p) for p in path.split("/"))
return os.path.join(*cooked_path)
6 changes: 3 additions & 3 deletions rare/models/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import binascii
import shlex
from dataclasses import dataclass, field
from datetime import datetime, UTC
from datetime import datetime, timezone
from typing import Dict, List, Type, Any


Expand Down Expand Up @@ -34,7 +34,7 @@ def most_recent(self) -> bool:

@property
def last_login(self) -> datetime:
return datetime.fromtimestamp(float(self._user.get("Timestamp", "0")), UTC)
return datetime.fromtimestamp(float(self._user.get("Timestamp", "0")), timezone.utc)

@property
def __dict__(self):
Expand Down Expand Up @@ -145,7 +145,7 @@ def game_logo(self) -> str:

@property
def last_played(self):
return datetime.fromtimestamp(float(self.LastPlayTime), UTC)
return datetime.fromtimestamp(float(self.LastPlayTime), timezone.utc)

@property
def __dict__(self):
Expand Down
6 changes: 3 additions & 3 deletions rare/utils/compat/steam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shlex
from dataclasses import dataclass
from enum import StrEnum
from enum import Enum
from hashlib import md5
from logging import getLogger
from typing import Optional, Union, List, Dict, Set
Expand Down Expand Up @@ -42,7 +42,7 @@ def find_libraries(steam_path: str) -> Set[str]:
# is a good trade-off for the amount of complexity supporting everything would ensue.


class SteamVerb(StrEnum):
class SteamVerb(Enum):
RUN = "run"
WAIT_FOR_EXIT_AND_RUN = "waitforexitandrun"
RUN_IN_PREFIX = "runinprefix"
Expand Down Expand Up @@ -77,7 +77,7 @@ def command(self, verb: SteamVerb = SteamVerb.DEFAULT) -> List[str]:
cmd = "".join([shlex.quote(tool_path), self.toolmanifest["commandline"]])
# NOTE: "waitforexitandrun" seems to be the verb used in by steam to execute stuff
# `run` is used when setting up the environment, so use that if we are setting up the prefix.
cmd = cmd.replace("%verb%", str(verb))
cmd = cmd.replace("%verb%", verb.value)
return shlex.split(cmd)

def as_str(self, verb: SteamVerb = SteamVerb.DEFAULT):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_requirements(filename):
use_scm_version={"version_scheme": "only-version", "local_scheme": "no-local-version"},
author="RareDevs",
license="GPL-3",
description="A gui for legendary",
description="Open source alternative for Epic Games Launcher, using Legendary",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Dummerle/Rare",
Expand Down

0 comments on commit 9e6fa05

Please sign in to comment.