File 0001-Initialize-sys.argv.patch of Package python3-pyotherside

From 747f6b2747ee403a0fe00cc9f0ddfe24edc966a1 Mon Sep 17 00:00:00 2001
From: Thomas Perl <m@thp.io>
Date: Mon, 30 Oct 2017 13:01:51 +0100
Subject: [PATCH] Initialize sys.argv (Fixes #77)

---
 src/qpython_priv.cpp                  |  7 +++++++
 tests/test_sys_argv/test_sys_argv.qml | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 tests/test_sys_argv/test_sys_argv.qml

diff --git a/src/qpython_priv.cpp b/src/qpython_priv.cpp
index 31eca26..7cee0e1 100644
--- a/src/qpython_priv.cpp
+++ b/src/qpython_priv.cpp
@@ -503,6 +503,13 @@ QPythonPriv::QPythonPriv()
     Py_InitializeEx(0);
     PyEval_InitThreads();
 
+    // Initialize sys.argv (https://github.com/thp/pyotherside/issues/77)
+    int argc = 1;
+    wchar_t *argv[argc];
+    argv[0] = Py_DecodeLocale("", nullptr);
+    PySys_SetArgvEx(argc, argv, 0);
+    PyMem_RawFree((void *)argv[0]);
+
     locals = PyObjectRef(PyDict_New(), true);
     assert(locals);
 
diff --git a/tests/test_sys_argv/test_sys_argv.qml b/tests/test_sys_argv/test_sys_argv.qml
new file mode 100644
index 0000000..f50b794
--- /dev/null
+++ b/tests/test_sys_argv/test_sys_argv.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+import io.thp.pyotherside 1.5
+
+Text {
+    id: txt
+
+    Python {
+        Component.onCompleted: {
+            importModule('sys', function() {
+                var args = evaluate('sys.argv');
+                for (var i=0; i<args.length; i++) {
+                    txt.text += 'Arg ' + i + ': "' + args[i] + '"\n';
+                }
+            });
+        }
+    }
+}
openSUSE Build Service is sponsored by