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: enforce more lint rules in codebase #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6cda070
feat: add ruff.toml
R1kaB3rN Aug 9, 2024
54e60d4
treewide: format gamefix modules through ruff
R1kaB3rN Sep 1, 2024
71a6c54
treewide: remove 'pylint: disable=C0103' from gamefixes
R1kaB3rN Sep 1, 2024
489cafa
treewide: format python files through ruff
R1kaB3rN Sep 1, 2024
09690ba
treewide: remove all pylint disables
R1kaB3rN Sep 1, 2024
e8286b6
__init__: remove unused import
R1kaB3rN Sep 1, 2024
55a0152
__init__: don't use bare except
R1kaB3rN Sep 1, 2024
7a48344
debug: don't log system python version
R1kaB3rN Sep 1, 2024
f27e20c
tools: delete lint.sh
R1kaB3rN Sep 1, 2024
06676a7
workflows: lint through ruff
R1kaB3rN Sep 1, 2024
03e584f
ruff.toml: add ANN rule to enforce typings
R1kaB3rN Sep 1, 2024
7243f73
ruff.toml: exclude test file
R1kaB3rN Sep 1, 2024
b91cb77
treewide: add return type for all gamefixes
R1kaB3rN Sep 1, 2024
59df5a7
steamhelper: prefer using f-string
R1kaB3rN Sep 1, 2024
3722c0f
config: fix missing types
R1kaB3rN Sep 1, 2024
70cf003
check_gamefixes: fix missing type
R1kaB3rN Sep 1, 2024
28f0c9d
util: fix reference to cache directory
R1kaB3rN Sep 1, 2024
64cb086
util: add missing types to functions
R1kaB3rN Sep 1, 2024
e37f23c
util: fix types for function calls
R1kaB3rN Sep 1, 2024
98e83d2
workflows: fix lint step
R1kaB3rN Sep 1, 2024
27b1c8a
workflows: lint winetricks
R1kaB3rN Sep 1, 2024
7a20176
util: use Union type instead of pipe
R1kaB3rN Sep 1, 2024
fc249a6
ruff.toml: add FLY, ARG, and UP rules
R1kaB3rN Sep 1, 2024
899bf62
treewide: use built in open
R1kaB3rN Sep 1, 2024
e02a578
treewide: remove unnecessary open mode
R1kaB3rN Sep 1, 2024
7ee6534
treewide: fix deprecated imports
R1kaB3rN Sep 1, 2024
5565c37
util: prefer OSError over IOError
R1kaB3rN Sep 1, 2024
1be7847
ruff.toml: add pydocstyle rule
R1kaB3rN Sep 2, 2024
2012505
treewide: enforce pydocstyle for *.py files
R1kaB3rN Sep 2, 2024
86ad08a
treewide: enforce pydocstyle for gamefixes
R1kaB3rN Sep 2, 2024
ed2d10a
ruff.toml: add lint exceptions
R1kaB3rN Sep 2, 2024
99bfc5d
treewide: ruff lint
R1kaB3rN Sep 2, 2024
958d5d8
debug: fix type when printing sys.argv
R1kaB3rN Sep 2, 2024
0c467b8
ruff.toml: enforce D211 rule
R1kaB3rN Sep 4, 2024
dc754ba
gamefixes-steam: ruff format
R1kaB3rN Sep 4, 2024
8a5a80c
gamefixes-steam: fix invalid steam appid on rebase
R1kaB3rN Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading