-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
Fix Flake8 errors and improve exception handling in lib/init/grass.py. Fixes ResourceWarning for python/libgrass_interface_generator/ctypesgen/version.py #4285
Conversation
p = Popen(["git", "describe"], stdout=PIPE, stderr=devnull, **args) | ||
out, err = p.communicate() | ||
with open(os.devnull, "w") as devnull: | ||
p = Popen(["git", "describe"], stdout=PIPE, stderr=devnull, **args) |
Check notice
Code scanning / Bandit
Starting a process with a partial executable path Note
@@ -1585,7 +1585,7 @@ def say_hello(): | |||
|
|||
revision = linerev.split(" ")[1] | |||
sys.stderr.write(" (" + revision + ")") | |||
except: | |||
except Exception: |
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.
Doesn't this add add another warning, where we don't use anything in that except?
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.
As per flake8, there should be no bare 'except' statements E722 - and at the same time it shouldn't be assigned to an unused variable which will trigger F841. I ran flake8 post this update and it didn't highlight anything
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.
What do we do here, as ctypesgen is code that is supposed to be upstream? @nilason or @wenzeslaus ?
with open(VERSION_FILE, "w") as f: | ||
f.write(v) |
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.
Ruff should suggest you to change it in a single Pathlib write_text call, with FURB103 rule
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.
@echoix I was going off of ResourceWarnings
so I hadn't checked the Ruff outputs. I ran them just now - there were a lot of SIM115 but no FURB103 in ctypesgen
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.
I think you need the --preview flag.
Or better idea, I had it excluded in config maybe, so maybe either give the path on the CLI, or use something like --isolated to ignore all configuration files
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.
Yeah I see it now. Either way updating this PR would become too messy. I'll close this PR and clone a clean copy and create separate PR for these 2 warnings. Thanks!
Description
This pull request addresses several Flake8 warnings and improves exception handling in the GRASS GIS initialization script. The changes focus on removing unused variables and replacing bare except clauses with more specific exception handling. This pull request also addresses the recurring ResourceWarning about an unclosed file in the version.py script.
Changes
Also as @echoix mentioned here: #4239 (comment)
workign through the errors in the result will fix most of ResourceWarnings although it also highlights simple linting cases where the warning may not exist
Specific Changes
1. Removed unused 'e' variables:
In the locale setting section, removed
as e
from twoexcept locale.Error
clauses where the error variable was not being used.