changeset 698:3a9d661d33b5

Implement SYS:executable
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 14 Jun 2023 09:13:07 +0200
parents 57fe110c50c8
children c076de854ac6
files CHANGES.txt configmix/variables.py docs/introduction.rst tests/test.py
diffstat 4 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Wed Jun 14 01:11:01 2023 +0200
+++ b/CHANGES.txt	Wed Jun 14 09:13:07 2023 +0200
@@ -16,8 +16,8 @@
 ~~~
 
 - **[feature]**
-  Implement a new ``SYS`` variable namespace with ``prefix``, ``base_prefix``
-  and ``platform`` as current content.
+  Implement a new ``SYS`` variable namespace with ``executable``,
+  ``prefix``, ``base_prefix`` and ``platform`` as current content.
 
 
 v0.21.3 (2023-06-12)
--- a/configmix/variables.py	Wed Jun 14 01:11:01 2023 +0200
+++ b/configmix/variables.py	Wed Jun 14 09:13:07 2023 +0200
@@ -51,9 +51,11 @@
 
 def _syslookup(name, default=_MARKER):
     """Lookup some variables from Python's :mod:`sys` module"""
+    if name == "executable":
+        return native_os_str_to_text(sys.executable)
     if name == "prefix":
         return native_os_str_to_text(sys.prefix)
-    elif name == "base_prefix":
+    if name == "base_prefix":
         val = getattr(sys, name, _MARKER)
         if val is _MARKER:
             if default is _MARKER:
@@ -61,13 +63,12 @@
             else:
                 return default
         return native_os_str_to_text(val)
-    elif name == "platform":
+    if name == "platform":
         return native_os_str_to_text(sys.platform)
+    if default is _MARKER:
+        raise KeyError("key %r not found in the namespace" % name)
     else:
-        if default is _MARKER:
-            raise KeyError("key %r not found in the namespace" % name)
-        else:
-            return default
+        return default
 
 
 def _pylookup(name, default=_MARKER):
--- a/docs/introduction.rst	Wed Jun 14 01:11:01 2023 +0200
+++ b/docs/introduction.rst	Wed Jun 14 09:13:07 2023 +0200
@@ -376,6 +376,10 @@
 
    Available functions:
 
+     ``executable``
+         Contains the content of the current running Python's
+         :py:data:`sys.executable`.
+
      ``prefix``
          Contains the content of the current running Python's
          :py:data:`sys.prefix`.
--- a/tests/test.py	Wed Jun 14 01:11:01 2023 +0200
+++ b/tests/test.py	Wed Jun 14 09:13:07 2023 +0200
@@ -288,6 +288,7 @@
         self.assertEqual(u(os.getcwd()), cfg.getvar("OS:cwd"))
         self.assertEqual(u(platform.python_version()),
                          cfg.getvar_s("PY:version"))
+        self.assertEqual(u(sys.executable), cfg.getvar_s("SYS:executable"))
         self.assertEqual(u(sys.prefix), cfg.getvar_s("SYS:prefix"))
         self.assertEqual(u(sys.platform), cfg.getvar_s("SYS:platform"))
         if hasattr(sys, "base_prefix"):