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: prefer pathlib when possible #183

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

R1kaB3rN
Copy link
Member

Related to #152 and #50.

Refactors to use pathlib when possible or appropriate without directly affecting user-created gamefixes

@R1kaB3rN R1kaB3rN marked this pull request as ready for review December 19, 2024 19:01
os.path.join(script_dir, 'game_title'), # noqa: PTH118
'w',
encoding='utf-8',
) as file:
file.write(title)
Copy link
Member Author

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}')
Copy link
Member Author

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
Copy link
Member Author

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)
Copy link
Member Author

@R1kaB3rN R1kaB3rN Dec 19, 2024

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
Copy link
Member Author

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.

logger.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant