Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Relative imports / imports without try block #200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
ln -s umu-protonfixes protonfixes
cd protonfixes
python3 .github/scripts/check_imports.py
# We need a known parent package in the unit tests, so we need to change to the parent dir
# As "umu-protonfixes" is not a valid package name, we create a symbolic link to "protonfixes"
- name: Test with unittest
run: |
python3 protonfixes_test.py
cd ..
ln -s umu-protonfixes protonfixes
python3 -m protonfixes.protonfixes_test
42 changes: 33 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
"""Starts the protonfix module"""
"""Starts the protonfix module and runs fixes after pre-flight-checks"""

import os
import sys
import traceback

RUN_CONDITIONS = [
'STEAM_COMPAT_DATA_PATH' in os.environ,
'PROTONFIXES_DISABLE' not in os.environ,
'waitforexitandrun' in sys.argv[1],
]
from . import fix
from .logger import log

if all(RUN_CONDITIONS):
import traceback
from . import fix

def check_conditions() -> bool:
"""Determine, if the actual game was executed and protonfixes isn't deactivated.

Returns:
bool: True, if the fix should be executed.

"""
return len(sys.argv) >= 1 and \
'STEAM_COMPAT_DATA_PATH' in os.environ and \
'PROTONFIXES_DISABLE' not in os.environ and \
'waitforexitandrun' in sys.argv[1]


def check_iscriptevaluator() -> bool:
"""Determine, if we were invoked while running "iscriptevaluator.exe".

Returns:
bool: True, if we were invoked while running "iscriptevaluator.exe".

"""
return len(sys.argv) >= 2 and \
'iscriptevaluator.exe' in sys.argv[2]


if check_iscriptevaluator():
log.debug('Skipping fix execution. We are running "iscriptevaluator.exe".')
elif not check_conditions():
log.warn('Skipping fix execution. We are probably running an unit test.')
else:
try:
fix.main()

Expand Down
5 changes: 1 addition & 4 deletions checks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Run some tests and generate warnings for proton configuration issues"""

try:
from .logger import log
except ImportError:
from logger import log
from .logger import log


def esync_file_limits() -> bool:
Expand Down
7 changes: 2 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""Load configuration settings for protonfixes"""

import os
from configparser import ConfigParser

try:
from .logger import log
except ImportError:
from logger import log
from configparser import ConfigParser
from .logger import log


CONF_FILE = '~/.config/protonfixes/config.ini'
Expand Down
1 change: 1 addition & 0 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys

from .logger import log


Expand Down
12 changes: 4 additions & 8 deletions fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import re
import sys
import csv

from functools import lru_cache
from importlib import import_module

try:
from . import config
from .checks import run_checks
from .logger import log
except ImportError:
import config
from checks import run_checks
from logger import log
from . import config
from .checks import run_checks
from .logger import log

try:
import __main__ as protonmain
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-1248080.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for CYGNI: All Guns Blazing"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-1370140.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix Kao the Kangaroo (2022)"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-2138710.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Sifu"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-2144740.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Ghost Runner 2"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-2229940.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for [REDACTED]"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-517710.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix Redout: Enhanced Edition"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-976590.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Bus Simulator 21 Next Stop"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-egs/umu-990080.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix Hogwarts Legacy"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1141086411.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Silent Hill 4: The Room"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
4 changes: 2 additions & 2 deletions gamefixes-gog/umu-1209310984.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from tempfile import mkdtemp
from urllib.request import urlopen

from protonfixes import util
from protonfixes.logger import log
from .. import util
from ..logger import log


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1228964594.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Soldier of Fortune II: Double Helix - Gold Edition"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
4 changes: 2 additions & 2 deletions gamefixes-gog/umu-1564851593.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from urllib.request import urlopen
from zipfile import ZipFile, is_zipfile

from protonfixes import util
from protonfixes.logger import log
from .. import util
from ..logger import log

# Archive containing the text injecting framework
arc = 'https://github.com/user-attachments/files/16136393/d3d9-2206220222.zip'
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1580232252.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Resident Evil (1997)"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1584652180.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The Wheel of Time"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-1771973390.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""METAL GEAR SOLID"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
3 changes: 1 addition & 2 deletions gamefixes-gog/umu-2069117974.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""METAL GEAR SOLID 2 SUBSTANCE"""
# GOG-ID 2069117974

from protonfixes import util

from .. import util

def main() -> None:
util.protontricks('dsound')
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-22610.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Alien Breed: Impact"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-22650.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Alien Breed 2: Assault"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-gog/umu-22670.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Alien Breed 3: Descent"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1017900.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Age of Empires: DE"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/10220.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Postal III"""

from protonfixes import util
from .. import util


# Missing fonts for console and various UI
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1030830.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Mafia II Definitive Edition"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/105000.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
No cutscene audio in Daedalic Games (Memoria, The Night of the Rabbit, A New Beginning - Final Cut) (105000 230820 243200) #1412
"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
4 changes: 2 additions & 2 deletions gamefixes-steam/105400.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import shutil

from protonfixes import util
from protonfixes.logger import log
from .. import util
from ..logger import log


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/105450.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Age Of Empire 3: Complete Collection"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1056640.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Phantasy Star Online 2"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1062040.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dragon Star Varnir"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1063730.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for New World"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/108710.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Alan Wake"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1097150.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Fall Guys"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1097880.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Super Naughty Maid 2"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/1105510.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for Yakuza 5"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion gamefixes-steam/110800.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Game fix for L.A. Noire"""

from protonfixes import util
from .. import util


def main() -> None:
Expand Down
Loading
Loading