-
Notifications
You must be signed in to change notification settings - Fork 48
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: prefer pathlib when possible #183
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 6818b6b.
os.path.join(script_dir, 'game_title'), # noqa: PTH118 | ||
'w', | ||
encoding='utf-8', | ||
) as file: | ||
file.write(title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bug. If I'm understanding correctly, we're not writing the title in the user's prefix. Instead, the title's is in the protonfixes directory.
file.write(title) | ||
return title | ||
except FileNotFoundError: | ||
log.warn(f"CSV file not found: {csv_file_path}") | ||
log.warn(f'CSV file not found: {csv_file_path}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just style changes applied from ruff format.
return False | ||
|
||
# Ensure local gamefixes are importable as modules via PATH | ||
with open(os.path.join(localpath, '__init__.py'), 'a', encoding='utf-8'): | ||
sys.path.append(os.path.expanduser('~/.config/protonfixes')) | ||
with open(os.path.join(localpath, '__init__.py'), 'a', encoding='utf-8'): # noqa: PTH118, PTH123 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even have to open the file here?
|
||
try: | ||
with open(csv_file_path, newline='', encoding='utf-8') as csvfile: | ||
with open(csv_file_path, newline='', encoding='utf-8') as csvfile: # noqa: PTH123 | ||
csvreader = csv.reader(csvfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSV is a database for us so we should handle the CSV by assuming it's very large.
TODO: Refactor to prefer memory mapping the CSV in a future PR.
@@ -129,16 +132,16 @@ def get_module_name(game_id: str, default: bool = False, local: bool = False) -> | |||
|
|||
def _run_fix_local(game_id: str, default: bool = False) -> bool: | |||
"""Check if a local gamefix is available first and run it""" | |||
localpath = os.path.expanduser('~/.config/protonfixes/localfixes') | |||
localpath = os.path.expanduser('~/.config/protonfixes/localfixes') # noqa: PTH111 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring this line and below as pathlib.Path objects should be safe.
Related to #152 and #50.
Refactors to use pathlib when possible or appropriate without directly affecting user-created gamefixes