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 all commits
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
19 changes: 9 additions & 10 deletions python/libgrass_interface_generator/ctypesgen/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
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")
DEFAULT_PREFIX = "ctypesgen"

__all__ = ["VERSION", "version_tuple", "version", "compatible"]
__all__ = ["VERSION", "compatible", "version", "version_tuple"]


def version_tuple(v):
Expand All @@ -23,17 +24,16 @@


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 @@ -48,7 +48,8 @@


def version_number():
return version().partition("-")[-1]
v = version()
return v.partition("-")[-1]


def compatible(v0, v1):
Expand All @@ -60,9 +61,7 @@
def write_version_file(v=None):
if v is None:
v = version()
f = open(VERSION_FILE, "w")
f.write(v)
f.close()
Path(VERSION_FILE).write_text(v)


VERSION = version()
Expand Down
Loading