aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--README.md35
-rwxr-xr-xconfigure.sh16
-rw-r--r--python/nissy_module.c34
4 files changed, 88 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 8e7948e..08e9084 100644
--- a/Makefile
+++ b/Makefile
@@ -39,4 +39,8 @@ debugshell: debugnissy.o
39shelltest: debugshell 39shelltest: debugshell
40 ./shell/test.sh 40 ./shell/test.sh
41 41
42.PHONY: all clean test tool debugtool shell debugshell shelltest 42python: nissy.o
43 ${CC} -shared ${PYTHON3_INCLUDES} -o nissy_python_module.so \
44 nissy.o python/nissy_module.c
45
46.PHONY: all clean test tool debugtool shell debugshell shelltest python
diff --git a/README.md b/README.md
index 554599d..d1ae1ce 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,41 @@ F' U R
150 150
151For a full list of available command, use `run help`. 151For a full list of available command, use `run help`.
152 152
153## Running commands from a Python shell
154
155There is a work-in-progress python module available. To build it you need
156the Python development headers installed. You can check this from the output
157of `./configure.sh`:
158
159```
160$ ./configure.sh
161...
162Python3 development libraries: version 3.12
163```
164
165Then to build the module:
166
167```
168$ make python
169```
170
171And to import it
172
173```
174$ python # In the main folder
175>>> import nissy_python_module as nissy # In the python shell
176```
177
178From here you can call the library functions directly, for example:
179
180```
181>>> nissy.compose("NEORSQLH=ZFCYUAGLHTKB", "NEORSQLH=ZFCYUAGLHTKB")
182'ASTUGFBH=DACXEZGBLIKF'
183```
184
185Please note: as this is work in progress, not all functions are currently
186available from the Python module.
187
153## Cube formats 188## Cube formats
154 189
155The cube is represented as a string in one of the following formats, 190The cube is represented as a string in one of the following formats,
diff --git a/configure.sh b/configure.sh
index 51e1089..ae51189 100755
--- a/configure.sh
+++ b/configure.sh
@@ -102,21 +102,33 @@ else
102fi 102fi
103LIBS="-lpthread" 103LIBS="-lpthread"
104 104
105CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3" 105CFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $AVX -O3 -fPIC"
106DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG" 106DBGFLAGS="$STD $LIBS $WFLAGS $WNOFLAGS $SAN $AVX -g3 -DDEBUG -fPIC"
107MACROS="-DTHREADS=$THREADS -D$ARCH" 107MACROS="-DTHREADS=$THREADS -D$ARCH"
108 108
109if (command -v "python3-config" >/dev/null 2>&1) ; then
110 PYTHON3_INCLUDES="$(python3-config --includes)"
111 PYTHON3="version $(echo "$PYTHON3_INCLUDES" | sed 's/.*3\./3./')"
112else
113 PYTHON3_INCLUDES=""
114 PYTHON3="Not found, Python shell won't be available"
115fi
116
109echo "Compiler: $CC" 117echo "Compiler: $CC"
110echo "Selected architecture: $ARCH" 118echo "Selected architecture: $ARCH"
111echo "Number of threads: $THREADS" 119echo "Number of threads: $THREADS"
112echo "Sanitizer options (debug build only): $SAN" 120echo "Sanitizer options (debug build only): $SAN"
121echo "Python3 development libraries: $PYTHON3"
113 122
114{ 123{
115echo "ARCH = $ARCH"; 124echo "ARCH = $ARCH";
116echo ""; 125echo "";
117echo "CFLAGS = $CFLAGS"; 126echo "CFLAGS = $CFLAGS";
127echo "";
118echo "DBGFLAGS = $DBGFLAGS"; 128echo "DBGFLAGS = $DBGFLAGS";
129echo "";
119echo "MACROS = $MACROS" 130echo "MACROS = $MACROS"
120echo ""; 131echo "";
132echo "PYTHON3_INCLUDES = $PYTHON3_INCLUDES"
121echo "CC = $CC" 133echo "CC = $CC"
122} > config.mk 134} > config.mk
diff --git a/python/nissy_module.c b/python/nissy_module.c
new file mode 100644
index 0000000..b627300
--- /dev/null
+++ b/python/nissy_module.c
@@ -0,0 +1,34 @@
1#define PY_SSIZE_T_CLEAN
2#include <Python.h>
3
4#include "../src/nissy.h"
5
6/* TODO from here */
7
8static PyObject *compose(PyObject *self, PyObject *args) {
9 const char *cube, *permutation;
10 char result[NISSY_SIZE_B32];
11
12 if (!PyArg_ParseTuple(args, "ss", &cube, &permutation))
13 return NULL;
14
15 nissy_compose(cube, permutation, result);
16 return PyUnicode_FromString(result);
17}
18
19static PyMethodDef NissyMethods[] = {
20 { "compose", compose, METH_VARARGS, "Compose two cubes." },
21 { NULL, NULL, 0, NULL }
22};
23
24static struct PyModuleDef nissy_python_module = {
25 PyModuleDef_HEAD_INIT,
26 "nissy",
27 NULL,
28 -1,
29 NissyMethods
30};
31
32PyMODINIT_FUNC PyInit_nissy_python_module(void) {
33 return PyModule_Create(&nissy_python_module);
34}

Generated with cgit - Back to sebastiano.tronto.net