Skip to content

Commit

Permalink
refactor: enforce more lint rules in codebase (#101)
Browse files Browse the repository at this point in the history
* feat: add ruff.toml

* treewide: format gamefix modules through ruff

- Enforces single quotes, a line length of 88, and updates the format of comment

* treewide: remove 'pylint: disable=C0103' from gamefixes

* treewide: format python files through ruff

* treewide: remove all pylint disables

* __init__: remove unused import

* __init__: don't use bare except

* debug: don't log system python version

* tools: delete lint.sh

* workflows: lint through ruff

* ruff.toml: add ANN rule to enforce typings

* ruff.toml: exclude test file

* treewide: add return type for all gamefixes

* steamhelper: prefer using f-string

* config: fix missing types

* check_gamefixes: fix missing type

* util: fix reference to cache directory

* util: add missing types to functions

* util: fix types for function calls

* workflows: fix lint step

* workflows: lint winetricks

* util: use Union type instead of pipe

* ruff.toml: add FLY, ARG, and UP rules

* treewide: use built in open

* treewide: remove unnecessary open mode

* treewide: fix deprecated imports

* util: prefer OSError over IOError

- Use OSError directly as advised in UP024 from ruff

* ruff.toml: add pydocstyle rule

* treewide: enforce pydocstyle for *.py files

* treewide: enforce pydocstyle for gamefixes

* ruff.toml: add lint exceptions

* treewide: ruff lint

* debug: fix type when printing sys.argv

* ruff.toml: enforce D211 rule

* gamefixes-steam: ruff format

* gamefixes-steam: fix invalid steam appid on rebase
  • Loading branch information
R1kaB3rN authored Sep 4, 2024
1 parent 6878800 commit 490f513
Show file tree
Hide file tree
Showing 291 changed files with 1,715 additions and 2,512 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/umu-protonfixes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ jobs:
run: |
sudo apt-get install shellcheck
python3 -m pip install --upgrade pip
pip install pylint
pip install ruff
pip install ijson
- name: Lint with Shellcheck
run: |
shellcheck tools/lint.sh tools/check-links.sh
shellcheck tools/check-links.sh
shellcheck winetricks
- name: Check symbolic links
run: |
bash tools/check-links.sh
- name: Check gamefix module IDs
run: |
python tools/check_gamefixes.py
- name: Lint with Pylint
- name: Lint with Ruff
run: |
bash tools/lint.sh
ruff check .
- name: Test with unittest
run: |
python protonfixes_test.py
10 changes: 3 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
""" Starts the protonfix module
"""
"""Starts the protonfix module"""

import os
import sys

if 'DEBUG' in os.environ:
from . import debug

RUN_CONDITIONS = [
'STEAM_COMPAT_DATA_PATH' in os.environ,
'PROTONFIXES_DISABLE' not in os.environ,
Expand All @@ -16,11 +12,11 @@
if all(RUN_CONDITIONS):
import traceback
from . import fix

try:
fix.main()

#pylint: disable=W0702
# Catch any exceptions and print a traceback
except:
except Exception:
sys.stderr.write('ProtonFixes ' + traceback.format_exc())
sys.stderr.flush()
18 changes: 7 additions & 11 deletions checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Run some tests and generate warnings for proton configuration issues
"""
"""Run some tests and generate warnings for proton configuration issues"""

try:
from .logger import log
Expand All @@ -8,16 +7,15 @@


def esync_file_limits() -> bool:
"""
Check esync file limits using /proc/sys/fs/file-max
"""Check esync file limits using /proc/sys/fs/file-max
https://www.reddit.com/r/SteamPlay/comments/9kqisk/tip_for_those_using_proton_no_esync1/
"""

warning = '''File descriptor limit is low
warning = """File descriptor limit is low
This can cause issues with ESYNC
For more details see:
https://github.com/zfigura/wine/blob/esync/README.esync
'''
"""

with open('/proc/sys/fs/file-max', encoding='ascii') as fsmax:
max_files = fsmax.readline()
Expand All @@ -28,12 +26,10 @@ def esync_file_limits() -> bool:


def run_checks() -> None:
""" Run checks to notify of any potential issues
"""

"""Run checks to notify of any potential issues"""
log.info('Running checks')
checks = [
esync_file_limits(),
]
]
if all(checks):
log.info('All checks successful')
25 changes: 11 additions & 14 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
""" Load configuration settings for protonfixes
"""
"""Load configuration settings for protonfixes"""

import os
from configparser import ConfigParser

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


CONF_FILE = '~/.config/protonfixes/config.ini'
DEFAULT_CONF = '''
DEFAULT_CONF = """
[main]
enable_checks = true
enable_splash = false
Expand All @@ -18,30 +19,26 @@
[path]
cache_dir = ~/.cache/protonfixes
'''
"""

CONF = ConfigParser()
CONF.read_string(DEFAULT_CONF)

try:
CONF.read(os.path.expanduser(CONF_FILE))
# pylint: disable=W0703

except Exception:
log.debug('Unable to read config file ' + CONF_FILE)

def opt_bool(opt):
""" Convert bool ini strings to actual boolean values
"""

def opt_bool(opt: str) -> bool:
"""Convert bool ini strings to actual boolean values"""
return opt.lower() in ['yes', 'y', 'true', '1']

# pylint: disable=E1101
locals().update(
{x:opt_bool(y) for x, y
in CONF['main'].items()
if 'enable' in x})

locals().update({x:os.path.expanduser(y) for x, y in CONF['path'].items()})
locals().update({x: opt_bool(y) for x, y in CONF['main'].items() if 'enable' in x})

locals().update({x: os.path.expanduser(y) for x, y in CONF['path'].items()})

try:
[os.makedirs(os.path.expanduser(d)) for n, d in CONF['path'].items()]
Expand Down
19 changes: 6 additions & 13 deletions debug.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
""" Prints debug info if the environment variable DEBUG is 1
"""
"""Prints debug info if the environment variable DEBUG is 1"""

import os
import sys
import shutil
# pylint: disable=E0611

from __main__ import CURRENT_PREFIX_VERSION, g_proton
from .logger import log

os.environ['DEBUG'] = '1'

def show_debug_info() -> None:
""" Show various debug info """

def show_debug_info() -> None:
"""Show various debug info"""
check_args = [
'iscriptevaluator.exe' in sys.argv[2],
'getcompatpath' in sys.argv[1],
Expand All @@ -29,12 +27,6 @@ def show_debug_info() -> None:
log.debug(sys.executable)
log.debug(sys.version)
log.debug(line)
log.debug('System Python Version:')
try:
log.debug(shutil.which(os.readlink(shutil.which('python'))))
except: #pylint: disable=W0702
log.debug(shutil.which('python'))
log.debug(line)

log.debug('Proton Version:')
log.debug(CURRENT_PREFIX_VERSION)
Expand All @@ -58,7 +50,8 @@ def show_debug_info() -> None:
log.debug(line)

log.debug('Command Line:')
log.debug(sys.argv)
log.debug(f'{sys.argv}')
log.debug('----- end protontricks debug info -----')


show_debug_info()
20 changes: 9 additions & 11 deletions download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Module with helper functions to download from file-hosting providers
"""
"""Module with helper functions to download from file-hosting providers"""

import os
import hashlib
Expand All @@ -12,26 +11,26 @@


def get_filename(headers: list) -> str:
""" Retrieve a filename from a request headers via Content-Disposition
"""
"""Retrieve a filename from a request headers via Content-Disposition"""
content_disp = [x for x in headers if x[0] == 'Content-Disposition'][0][1]
raw_filename = [x for x in content_disp.split(';') if x.startswith('filename=')][0]
return raw_filename.replace('filename=', '').replace('"', '')


def gdrive_download(gdrive_id: str, path: str) -> None:
""" Download a file from gdrive given the fileid and a path to save
"""
"""Download a file from gdrive given the fileid and a path to save"""
url = GDRIVE_URL.format(gdrive_id)
cjar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cjar))
urllib.request.install_opener(opener)

req = urllib.request.Request(url)
with urllib.request.urlopen(req, timeout=10) as resp:
confirm_cookie = [x for x in resp.getheaders() if
(x[0] == 'Set-Cookie'
and x[1].startswith('download_warning'))][0][1]
confirm_cookie = [
x
for x in resp.getheaders()
if (x[0] == 'Set-Cookie' and x[1].startswith('download_warning'))
][0][1]
confirm = confirm_cookie.split(';')[0].split('=')[1]

req = urllib.request.Request(f'{url}&confirm={confirm}')
Expand All @@ -42,8 +41,7 @@ def gdrive_download(gdrive_id: str, path: str) -> None:


def sha1sum(filename: str) -> str:
""" Computes the sha1sum of the specified file
"""
"""Computes the sha1sum of the specified file"""
if not os.path.isfile(filename):
return ''
hasher = hashlib.sha1()
Expand Down
Loading

0 comments on commit 490f513

Please sign in to comment.