You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/sphinx/source/debugging/debug_in_ide.rst
+37-36Lines changed: 37 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Debuging Python C Extensions in an IDE
17
17
18
18
The basic idea is to compile/link your C extension in your IDE and get ``main()`` to call a function ``int import_call_execute(int argc, const char *argv[])`` that embeds the Python interpreter which then imports a Python module, say a unit test, that exercises your C extension code.
19
19
20
-
This ``import_call_execute()`` entry point is fairly generic and takes the standard arguments to ``main()``.
20
+
This ``import_call_execute()`` entry point is fairly generic and takes the standard arguments to ``main()`` so it can be in its own .h/.c file.
21
21
22
22
------------------------------------------------
23
23
Creating a Python Unit Test to Execute
@@ -39,38 +39,34 @@ Suppose you have a Python extension ``ScList`` that sub-classes a list and count
We write the ``import_call_execute()`` function to take that same arguments as ``main()`` and ``import_call_execute()`` expects 4 arguments:
42
+
We create the ``import_call_execute()`` function that takes that same arguments as ``main()`` which can forward its arguments. ``import_call_execute()`` expects 4 arguments:
43
43
44
44
* ``argc[0]`` - Name of the executable.
45
45
* ``argc[1]`` - Path to the directory that the Python module is in.
46
46
* ``argc[2]`` - Name of the Python module to be imported. This could be a unit test module for example.
47
47
* ``argc[3]`` - Name of the Python function in the Python module (no arguments will be supplied, the return value is ignored). This could be a particular unit test.
48
48
49
-
The ``import_call_execute()`` function does this, in this particular case:
49
+
The ``import_call_execute()`` function does this:
50
50
51
51
#. Check the arguments and initialises the Python interpreter
52
-
#. Add the path to the ``test_sclist.py`` to ``sys.paths``.
53
-
#. Import ``test_sclist``.
54
-
#. Find the function ``test()`` in module ``test_sclist`` and call it.
52
+
#. Add the path to the ``argc[1]`` to ``sys.paths``.
53
+
#. Import ``argc[2]``.
54
+
#. Find the function ``argc[3]`` in module ``argc[2]`` and call it.
55
55
#. Clean up.
56
56
57
57
58
58
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59
59
Code Walk Through
60
60
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
61
61
62
-
So ``import_call_execute()`` is quite generic, here is a walk through of the code, the whole code is below.
62
+
``import_call_execute()`` is quite generic and could be implemented in, say, ``py_import_call_execute.c``.
63
+
64
+
Here is a walk through of the implementation code:
63
65
64
66
Step 1: Check the arguments and initialise the Python interpreter
65
67
66
68
.. code-block:: c
67
69
68
-
#include <Python.h>
69
-
70
-
/** This should be the name of your executable.
71
-
* It is just used for error messages. */
72
-
#define EXECUTABLE_NAME "pyxcode"
73
-
74
70
/** This imports a Python module and calls a specific function in it.
75
71
* It's arguments are similar to main():
76
72
* argc - Number of strings in argv
@@ -96,7 +92,7 @@ Step 1: Check the arguments and initialise the Python interpreter
0 commit comments