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

utils: Use context managers for subprocesses and opening files #4905

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

echoix
Copy link
Member

@echoix echoix commented Jan 2, 2025

I tried out a tool called pyrefact. While not that safe and stable (hanged on some files if not changed), it still found out some places where context managers could be used and applied these transformations. The changes by pyrefact plus some manual tweaks were enough to unlock existing ruff simplifications afterwards.

I include here some changes that were appropriate for us

@github-actions github-actions bot added the Python Related code is in Python label Jan 2, 2025
@@ -14,8 +14,8 @@


def check_md(filename):
p = subprocess.Popen(["mdl", filename])
p.wait()
with subprocess.Popen(["mdl", filename]) as p:

Check notice

Code scanning / Bandit

Starting a process with a partial executable path Note

Starting a process with a partial executable path
@echoix echoix force-pushed the utils-pyrefact-contextmanager branch from 74f057c to 9c4084b Compare January 3, 2025 02:34
@echoix echoix force-pushed the utils-pyrefact-contextmanager branch from 9c4084b to 7a45fcb Compare January 3, 2025 02:45
@echoix echoix requested a review from petrasovaa January 15, 2025 23:38
@echoix echoix merged commit f958f45 into OSGeo:main Jan 16, 2025
27 checks passed
@echoix echoix deleted the utils-pyrefact-contextmanager branch January 16, 2025 02:47
@github-actions github-actions bot added this to the 8.5.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants