commit: af80dd32a276d535d5eae8bf6ed8e4c38eaa2d62
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 11 01:47:22 2025 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat Jan 11 01:59:34 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=af80dd32
portage.VERSION: use subprocess.run() to call git
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/__init__.py | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
index 4bde4886b0..50689b0d2b 100644
--- a/lib/portage/__init__.py
+++ b/lib/portage/__init__.py
@@ -717,24 +717,19 @@ if installation.TYPE == installation.TYPES.SOURCE:
return VERSION
VERSION = "HEAD"
if os.path.isdir(os.path.join(PORTAGE_BASE_PATH, ".git")):
- encoding = _encodings["fs"]
- cmd = [
- BASH_BINARY,
- "-c",
- (
- f"cd {_shell_quote(PORTAGE_BASE_PATH)} ; git describe
--dirty --match 'portage-*' || exit $? ; "
- ),
- ]
- cmd = [
- _unicode_encode(x, encoding=encoding, errors="strict") for
x in cmd
- ]
- proc = subprocess.Popen(
- cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
- )
- output = _unicode_decode(proc.communicate()[0],
encoding=encoding)
- status = proc.wait()
- if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
- VERSION = output.lstrip("portage-").strip().replace("-g",
"+g")
+ try:
+ result = subprocess.run(
+ ["git", "describe", "--dirty", "--match", "portage-*"],
+ capture_output=True,
+ cwd=PORTAGE_BASE_PATH,
+ encoding=_encodings["stdio"],
+ )
+ if result.returncode == 0:
+ VERSION = (
+
result.stdout.lstrip("portage-").strip().replace("-g", "+g")
+ )
+ except OSError:
+ pass
return VERSION
VERSION = _LazyVersion()