Skip to content

Python cleanup - #173

Open
slycordinator wants to merge 4 commits into
mmaher88:masterfrom
slycordinator:python_cleanup
Open

slycordinator wants to merge 4 commits into
mmaher88:masterfrom
slycordinator:python_cleanup

Conversation

@slycordinator

Copy link
Copy Markdown

Python script cleanup

Replaces low level os library to use pathlib.Path for file operations and loop over pathlib.Path.rglob for files instead of using string paths or glob libary.
Replaces Optional[object] with object | None for hype hints
For repeated re.sub calls, uses re.compile early.
Reorders/condenses imports according to ruff
And in case of scripts/generate-placeholders.py, moves logitech_receiver imports early in script to fail before starting to work on other stuff (which would otherwise make the work pointless)

convert to use pathlib.Path for file operations

* allows files to be opened directly with their own path object [file_path.open()] instead of the low-level open function [open(file_path)]

* made extract_depo return list of Path objects

* replaced os.makedirs(dir, exist_ok=True) with dir_path.mkdir(parents=True, exist_ok=True)

* simplified looking for '.depot' files using pathlib.Path.rglob

* remove/count path objects by checking Path.suffix
* moved solaar imports to head of file
- arguably better for it to crash early before trying other operations

* moved repeated/looped re.sub patterns into their own compiled patterns to be reused

* changed file operations to use pathlib.Path instead of string paths
* generate-placholders.py - correct typo from previous

* optionsplus_extractor/canonicalize.py - ruff changed the imports into alphabetical with capitals first

* optionsplus_extractor/cli.py
- ruff changed order of imports
- replace Optional with typehint of "object | None"
- use re.compile for slugify reuse

* descriptor.py
consolidate imports
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