-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,18 +23,17 @@ | |
|
||
|
||
def read_file_version(): | ||
f = open(VERSION_FILE) | ||
v = f.readline() | ||
f.close() | ||
with open(VERSION_FILE) as f: | ||
v = f.readline() | ||
return v.strip() | ||
|
||
|
||
def version(): | ||
try: | ||
args = {"cwd": THIS_DIR} | ||
devnull = open(os.devnull, "w") | ||
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
Starting a process with a partial executable path
|
||
out, err = p.communicate() | ||
if p.returncode: | ||
raise RuntimeError("no version defined?") | ||
git_tag = out.strip().decode() | ||
|
@@ -60,9 +59,8 @@ | |
def write_version_file(v=None): | ||
if v is None: | ||
v = version() | ||
f = open(VERSION_FILE, "w") | ||
f.write(v) | ||
f.close() | ||
with open(VERSION_FILE, "w") as f: | ||
f.write(v) | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @echoix I was going off of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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! |
||
|
||
|
||
VERSION = version() | ||
|
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