[pygobject] Drop static SPAWN_* constants



commit 6a586af41b8740c4ba590591d1068d80071ff2dc
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Oct 24 14:12:05 2012 +0200

    Drop static SPAWN_* constants
    
    Use the introspected constants instead, which are identical. Add backwards
    compatible aliases.
    
    These constants are covered by tests/test_subprocess.py.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686765

 docs/reference/pyglib-constants.xml    |   68 --------------------------------
 docs/reference/pyglib-functions.xml    |   26 ++++++------
 docs/reference/pygobject-constants.xml |   67 -------------------------------
 gi/_glib/__init__.py                   |    7 ---
 gi/_glib/glibmodule.c                  |   15 -------
 gi/_gobject/__init__.py                |    7 ---
 gi/overrides/GLib.py                   |    6 +++
 gi/overrides/GObject.py                |    6 ++-
 tests/test_subprocess.py               |    6 ++-
 9 files changed, 29 insertions(+), 179 deletions(-)
---
diff --git a/docs/reference/pyglib-constants.xml b/docs/reference/pyglib-constants.xml
index 333cfc6..6f24308 100644
--- a/docs/reference/pyglib-constants.xml
+++ b/docs/reference/pyglib-constants.xml
@@ -12,7 +12,6 @@
     <title>Synopsis</title>
 
     <programlisting>
-<xref linkend="glib-spawn-flag-constants" endterm="glib-spawn-flag-constants-title"></xref>
 <xref linkend="glib-version-constants" endterm="glib-version-constants-title"></xref>
 </programlisting>
 
@@ -21,73 +20,6 @@
   <refsect1 id="glib-constants-description">
     <title>Description</title>
 
-    <refsect2 id="glib-spawn-flag-constants">
-      <title id="glib-spawn-flag-constants-title">Glib Spawn Flag Constants</title>
-
-      <para>The Spawn Flag constants are a set of bit-flags that can be
-passed to the <link
-linkend="function-glib--spawn-async"><function>glib.spawn_async</function>()</link>
-function.</para>
-
-      <variablelist>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></term>
-	  <listitem>
-	    <simpara>the parent's open file descriptors will be inherited by
-the child; otherwise all descriptors except stdin/stdout/stderr will be
-closed before calling <function>exec</function>() in the child.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_DO_NOT_REAP_CHILD</literal></term>
-	  <listitem>
-	    <simpara>the child will not be automatically reaped; you must
-call <function>waitpid</function>() or handle <literal>SIGCHLD</literal>
-yourself, or the child will become a zombie.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_SEARCH_PATH</literal></term>
-	  <listitem>
-	    <simpara><parameter>argv</parameter>[0] need not be an absolute
-path, it will be looked for in the user's <envar>PATH</envar>.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_STDOUT_TO_DEV_NULL</literal></term>
-	  <listitem>
-	    <simpara>the child's standard output will be discarded, instead
-of going to the same location as the parent's standard output.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_STDERR_TO_DEV_NULL</literal></term>
-	  <listitem>
-	    <simpara>the child's standard error will be discarded.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_CHILD_INHERITS_STDIN</literal></term>
-	  <listitem>
-	    <simpara>the child will inherit the parent's standard input (by
-default, the child's standard input is attached to /dev/null).</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>glib.SPAWN_FILE_AND_ARGV_ZERO</literal></term>
-	  <listitem>
-	    <simpara>the first element of <parameter>argv</parameter> is the
-file to execute, while the remaining elements are the actual argument vector
-to pass to the file. Normally <link
-linkend="function-glib--spawn-async"><function>glib.spawn_async</function>()</link>
-uses <parameter>argv</parameter>[0] as the file to execute, and passes all
-of <parameter>argv</parameter> to the child.</simpara>
-	  </listitem>
-	</varlistentry>
-      </variablelist>
-
-    </refsect2>
-
     <refsect2 id="glib-version-constants">
       <title id="glib-version-constants-title">Glib Version Constants</title>
       <para>The Version constants specify the version of
diff --git a/docs/reference/pyglib-functions.xml b/docs/reference/pyglib-functions.xml
index e3a63ac..7d70a66 100644
--- a/docs/reference/pyglib-functions.xml
+++ b/docs/reference/pyglib-functions.xml
@@ -333,7 +333,7 @@ should be a sequence of strings, to be passed as the argument vector for the
 child. The first string in <parameter>argv</parameter> is of course the name
 of the program to execute. By default, the name of the program must be a
 full path; the <envar>PATH</envar> shell variable will only be searched if
-you pass the <literal>glib.SPAWN_SEARCH_PATH</literal> flag in
+you pass the <literal>GLib.SpawnFlags.SEARCH_PATH</literal> flag in
 <parameter>flags</parameter>. The function returns a 4-tuple containing the
 child's process id and the file descriptors for the child's stdin, stdout
 and stderr. The stdin, stdout and stderr file descriptors are returned only
@@ -370,7 +370,7 @@ function.</para>
       <para><parameter>flags</parameter> should be the bitwise
 <literal>OR</literal> of the <xref linkend="glib-spawn-flag-constants"
 endterm="glib-spawn-flag-constants-title"></xref> you want to affect the
-function's behaviour. The <literal>glib.SPAWN_DO_NOT_REAP_CHILD</literal>
+function's behaviour. The <literal>GLib.SpawnFlags.DO_NOT_REAP_CHILD</literal>
 flag means that the child will not automatically be reaped; you must use a
 GChildWatch source to be notified about the death of the child
 process. Eventually you must call g_spawn_close_pid() on the child_pid, in
@@ -381,27 +381,27 @@ signal manually. On Windows, calling g_spawn_close_pid() is equivalent to
 calling <function>CloseHandle</function>() on the process handle
 returned).</para>
 
-      <para><literal>glib.SPAWN_LEAVE_DESCRIPTORS_OPEN</literal> means
+      <para><literal>GLib.SpawnFlags.LEAVE_DESCRIPTORS_OPEN</literal> means
 that the parent's open file descriptors will be inherited by the child;
 otherwise all descriptors except stdin/stdout/stderr will be closed before
 calling <function>exec</function>() in the
-child. <literal>glib.SPAWN_SEARCH_PATH</literal> means that
+child. <literal>GLib.SpawnFlags.SEARCH_PATH</literal> means that
 <parameter>argv</parameter>[0] need not be an absolute path, it will be
 looked for in the user's
-<envar>PATH</envar>. <literal>glib.SPAWN_STDOUT_TO_DEV_NULL</literal>
+<envar>PATH</envar>. <literal>GLib.SpawnFlags.STDOUT_TO_DEV_NULL</literal>
 means that the child's standard output will be discarded, instead of going
 to the same location as the parent's standard output. If you use this flag,
 <parameter>standard_output</parameter> must be
-<literal>None</literal>. <literal>glib.SPAWN_STDERR_TO_DEV_NULL</literal>
+<literal>None</literal>. <literal>GLib.SpawnFlags.STDERR_TO_DEV_NULL</literal>
 means that the child's standard error will be discarded, instead of going to
 the same location as the parent's standard error. If you use this flag,
 <parameter>standard_error</parameter> must be
-<literal>None</literal>. <literal>glib.SPAWN_CHILD_INHERITS_STDIN</literal>
+<literal>None</literal>. <literal>GLib.SpawnFlags.CHILD_INHERITS_STDIN</literal>
 means that the child will inherit the parent's standard input (by default,
 the child's standard input is attached to
 <filename>/dev/null</filename>). If you use this flag,
 <parameter>standard_input</parameter> must be
-<literal>None</literal>. <literal>glib.SPAWN_FILE_AND_ARGV_ZERO</literal>
+<literal>None</literal>. <literal>GLib.SpawnFlags.FILE_AND_ARGV_ZERO</literal>
 means that the first element of <parameter>argv</parameter> is the file to
 execute, while the remaining elements are the actual argument vector to pass
 to the file. Normally the <link
@@ -427,9 +427,9 @@ if you intend your software to be portable to Windows.</para>
 
       <para>The returned child process id can be used to send signals to the
 child, or to wait for the child if you specified the
-<literal>glib.SPAWN_DO_NOT_REAP_CHILD</literal> flag.  On Windows, child
+<literal>GLib.SpawnFlags.DO_NOT_REAP_CHILD</literal> flag.  On Windows, child
 pid will be returned only if you specified the
-<literal>glib.SPAWN_DO_NOT_REAP_CHILD</literal> flag.</para>
+<literal>GLib.SpawnFlags.DO_NOT_REAP_CHILD</literal> flag.</para>
 
       <para>The caller of the <link
 linkend="function-glib--spawn-async"><function>glib.spawn_async</function>()</link>
@@ -439,17 +439,17 @@ use.</para>
       <para>If <parameter>standard_input</parameter> is
 <literal>None</literal>, the child's standard input is attached to
 <filename>/dev/null</filename> unless
-<literal>glib.SPAWN_CHILD_INHERITS_STDIN</literal> is set.</para>
+<literal>GLib.SpawnFlags.CHILD_INHERITS_STDIN</literal> is set.</para>
 
       <para>If <parameter>standard_error</parameter> is
 <literal>None</literal>, the child's standard error goes to the same
 location as the parent's standard error unless
-<literal>glib.SPAWN_STDERR_TO_DEV_NULL</literal> is set.</para>
+<literal>GLib.SpawnFlags.STDERR_TO_DEV_NULL</literal> is set.</para>
 
       <para>If <parameter>standard_output</parameter> is
 <literal>None</literal>, the child's standard output goes to the same
 location as the parent's standard output unless
-<literal>glib.SPAWN_STDOUT_TO_DEV_NULL</literal> is set.</para>
+<literal>GLib.SpawnFlags.STDOUT_TO_DEV_NULL</literal> is set.</para>
 
       <para>If an error occurs, the glib.GError exception will be
 raised.</para>
diff --git a/docs/reference/pygobject-constants.xml b/docs/reference/pygobject-constants.xml
index a8f9711..07c3fdd 100644
--- a/docs/reference/pygobject-constants.xml
+++ b/docs/reference/pygobject-constants.xml
@@ -136,73 +136,6 @@ emission.</para>
 
     </refsect2>
 
-    <refsect2 id="gobject-spawn-flag-constants">
-      <title id="gobject-spawn-flag-constants-title">GObject Spawn Flag Constants</title>
-
-      <para>The Spawn Flag constants are a set of bit-flags that can be
-passed to the <link
-linkend="function-gobject--spawn-async"><function>gobject.spawn_async</function>()</link>
-function.</para>
-
-      <variablelist>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></term>
-	  <listitem>
-	    <simpara>the parent's open file descriptors will be inherited by
-the child; otherwise all descriptors except stdin/stdout/stderr will be
-closed before calling <function>exec</function>() in the child.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_DO_NOT_REAP_CHILD</literal></term>
-	  <listitem>
-	    <simpara>the child will not be automatically reaped; you must
-call <function>waitpid</function>() or handle <literal>SIGCHLD</literal>
-yourself, or the child will become a zombie.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_SEARCH_PATH</literal></term>
-	  <listitem>
-	    <simpara><parameter>argv</parameter>[0] need not be an absolute
-path, it will be looked for in the user's <envar>PATH</envar>.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_STDOUT_TO_DEV_NULL</literal></term>
-	  <listitem>
-	    <simpara>the child's standard output will be discarded, instead
-of going to the same location as the parent's standard output.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_STDERR_TO_DEV_NULL</literal></term>
-	  <listitem>
-	    <simpara>the child's standard error will be discarded.</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_CHILD_INHERITS_STDIN</literal></term>
-	  <listitem>
-	    <simpara>the child will inherit the parent's standard input (by
-default, the child's standard input is attached to /dev/null).</simpara>
-	  </listitem>
-	</varlistentry>
-	<varlistentry>
-	  <term><literal>gobject.SPAWN_FILE_AND_ARGV_ZERO</literal></term>
-	  <listitem>
-	    <simpara>the first element of <parameter>argv</parameter> is the
-file to execute, while the remaining elements are the actual argument vector
-to pass to the file. Normally <link
-linkend="function-gobject--spawn-async"><function>gobject.spawn_async</function>()</link>
-uses <parameter>argv</parameter>[0] as the file to execute, and passes all
-of <parameter>argv</parameter> to the child.</simpara>
-	  </listitem>
-	</varlistentry>
-      </variablelist>
-
-    </refsect2>
-
     <refsect2 id="gobject-type-constants">
       <title id="gobject-type-constants-title">GObject Built-in Type Constants</title>
 
diff --git a/gi/_glib/__init__.py b/gi/_glib/__init__.py
index 9f12f06..145685e 100644
--- a/gi/_glib/__init__.py
+++ b/gi/_glib/__init__.py
@@ -44,13 +44,6 @@ OPTION_FLAG_NO_ARG = _glib.OPTION_FLAG_NO_ARG
 OPTION_FLAG_OPTIONAL_ARG = _glib.OPTION_FLAG_OPTIONAL_ARG
 OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
 OPTION_REMAINING = _glib.OPTION_REMAINING
-SPAWN_CHILD_INHERITS_STDIN = _glib.SPAWN_CHILD_INHERITS_STDIN
-SPAWN_DO_NOT_REAP_CHILD = _glib.SPAWN_DO_NOT_REAP_CHILD
-SPAWN_FILE_AND_ARGV_ZERO = _glib.SPAWN_FILE_AND_ARGV_ZERO
-SPAWN_LEAVE_DESCRIPTORS_OPEN = _glib.SPAWN_LEAVE_DESCRIPTORS_OPEN
-SPAWN_SEARCH_PATH = _glib.SPAWN_SEARCH_PATH
-SPAWN_STDERR_TO_DEV_NULL = _glib.SPAWN_STDERR_TO_DEV_NULL
-SPAWN_STDOUT_TO_DEV_NULL = _glib.SPAWN_STDOUT_TO_DEV_NULL
 
 # Functions
 child_watch_add = _glib.child_watch_add
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index d57db13..1513748 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -388,21 +388,6 @@ pyglib_register_version_tuples(PyObject *d)
 static void
 pyglib_register_constants(PyObject *m)
 {
-    PyModule_AddIntConstant(m, "SPAWN_LEAVE_DESCRIPTORS_OPEN",
-			    G_SPAWN_LEAVE_DESCRIPTORS_OPEN);
-    PyModule_AddIntConstant(m, "SPAWN_DO_NOT_REAP_CHILD",
-			    G_SPAWN_DO_NOT_REAP_CHILD);
-    PyModule_AddIntConstant(m, "SPAWN_SEARCH_PATH",
-			    G_SPAWN_SEARCH_PATH);
-    PyModule_AddIntConstant(m, "SPAWN_STDOUT_TO_DEV_NULL",
-			    G_SPAWN_STDOUT_TO_DEV_NULL);
-    PyModule_AddIntConstant(m, "SPAWN_STDERR_TO_DEV_NULL",
-			    G_SPAWN_STDERR_TO_DEV_NULL);
-    PyModule_AddIntConstant(m, "SPAWN_CHILD_INHERITS_STDIN",
-			    G_SPAWN_CHILD_INHERITS_STDIN);
-    PyModule_AddIntConstant(m, "SPAWN_FILE_AND_ARGV_ZERO",
-			    G_SPAWN_FILE_AND_ARGV_ZERO);
-
     PyModule_AddIntConstant(m, "OPTION_FLAG_HIDDEN",
 			    G_OPTION_FLAG_HIDDEN);
     PyModule_AddIntConstant(m, "OPTION_FLAG_IN_MAIN",
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 91a229f..50a130f 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -93,13 +93,6 @@ IOChannel = _glib.IOChannel
 OptionGroup = _glib.OptionGroup
 OptionContext = _glib.OptionContext
 
-SPAWN_LEAVE_DESCRIPTORS_OPEN = _glib.SPAWN_LEAVE_DESCRIPTORS_OPEN
-SPAWN_DO_NOT_REAP_CHILD = _glib.SPAWN_DO_NOT_REAP_CHILD
-SPAWN_SEARCH_PATH = _glib.SPAWN_SEARCH_PATH
-SPAWN_STDOUT_TO_DEV_NULL = _glib.SPAWN_STDOUT_TO_DEV_NULL
-SPAWN_STDERR_TO_DEV_NULL = _glib.SPAWN_STDERR_TO_DEV_NULL
-SPAWN_CHILD_INHERITS_STDIN = _glib.SPAWN_CHILD_INHERITS_STDIN
-SPAWN_FILE_AND_ARGV_ZERO = _glib.SPAWN_FILE_AND_ARGV_ZERO
 OPTION_FLAG_HIDDEN = _glib.OPTION_FLAG_HIDDEN
 OPTION_FLAG_IN_MAIN = _glib.OPTION_FLAG_IN_MAIN
 OPTION_FLAG_REVERSE = _glib.OPTION_FLAG_REVERSE
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 5902053..b4d74be 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -442,6 +442,12 @@ for n in ['AGAIN', 'EOF', 'ERROR', 'NORMAL']:
     globals()['IO_STATUS_' + n] = getattr(GLib.IOStatus, n)
     __all__.append('IO_STATUS_' + n)
 
+for n in ['CHILD_INHERITS_STDIN', 'DO_NOT_REAP_CHILD', 'FILE_AND_ARGV_ZERO',
+          'LEAVE_DESCRIPTORS_OPEN', 'SEARCH_PATH', 'STDERR_TO_DEV_NULL',
+          'STDOUT_TO_DEV_NULL']:
+    globals()['SPAWN_' + n] = getattr(GLib.SpawnFlags, n)
+    __all__.append('SPAWN_' + n)
+
 
 class MainLoop(GLib.MainLoop):
     # Backwards compatible constructor API
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 5c64b62..305a25f 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -43,6 +43,10 @@ for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH',
              'IO_STATUS_AGAIN', 'IO_FLAG_APPEND', 'IO_FLAG_NONBLOCK',
              'IO_FLAG_IS_READABLE', 'IO_FLAG_IS_WRITEABLE',
              'IO_FLAG_IS_SEEKABLE', 'IO_FLAG_MASK', 'IO_FLAG_GET_MASK',
-             'IO_FLAG_SET_MASK']:
+             'IO_FLAG_SET_MASK',
+             'SPAWN_LEAVE_DESCRIPTORS_OPEN', 'SPAWN_DO_NOT_REAP_CHILD',
+             'SPAWN_SEARCH_PATH', 'SPAWN_STDOUT_TO_DEV_NULL',
+             'SPAWN_STDERR_TO_DEV_NULL', 'SPAWN_CHILD_INHERITS_STDIN',
+             'SPAWN_FILE_AND_ARGV_ZERO']:
     globals()[name] = getattr(GLib, name)
     __all__.append(name)
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index eefa0f8..48e29e5 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -17,8 +17,12 @@ class TestProcess(unittest.TestCase):
         self.loop = GLib.MainLoop()
         argv = [sys.executable, '-c', 'import sys']
         pid, stdin, stdout, stderr = GLib.spawn_async(
-            argv, flags=GLib.SPAWN_DO_NOT_REAP_CHILD)
+            argv, flags=GLib.SpawnFlags.DO_NOT_REAP_CHILD)
         pid.close()
         GLib.child_watch_add(pid, self._child_watch_cb, 12345)
         self.loop.run()
         self.assertEqual(self.data, 12345)
+
+    def test_backwards_compat_flags(self):
+        self.assertEqual(GLib.SpawnFlags.DO_NOT_REAP_CHILD,
+                         GLib.SPAWN_DO_NOT_REAP_CHILD)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]