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

pythonlib: Fix ResourceWarning in libgrass_interface_generator/ctypesgen/version.py #4288

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions python/libgrass_interface_generator/ctypesgen/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from subprocess import Popen, PIPE
import os
from os import path
from pathlib import Path

THIS_DIR = path.dirname(__file__)
VERSION_FILE = path.join(THIS_DIR, "VERSION")
Expand All @@ -23,17 +24,16 @@ def version_tuple(v):


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)
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?")
Expand All @@ -60,9 +60,9 @@ def compatible(v0, v1):
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)
Path(VERSION_FILE).write_text(v)
arohanajit marked this conversation as resolved.
Show resolved Hide resolved


VERSION = version()
Expand Down
Loading