diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-11 12:05:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-11 12:05:08 +0200 |
| commit | 4544e08997a7af6a8defa47efae1e9ba5c2c30f6 (patch) | |
| tree | aa211e7f80429ca758573349e1866861469ec12b | |
| parent | d25f23805c6d7128b508a359d47af136dd2fd0db (diff) | |
| download | nissy-core-4544e08997a7af6a8defa47efae1e9ba5c2c30f6.tar.gz nissy-core-4544e08997a7af6a8defa47efae1e9ba5c2c30f6.zip | |
Simplified name of Python module
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | build | 2 | ||||
| -rw-r--r-- | python/examples/move.py | 7 | ||||
| -rw-r--r-- | python/examples/solve.py | 11 | ||||
| -rw-r--r-- | python/examples/variations.py | 5 | ||||
| -rw-r--r-- | python/nissy_module.c | 6 |
7 files changed, 21 insertions, 15 deletions
| @@ -36,6 +36,7 @@ tools/results | |||
| 36 | *.a | 36 | *.a |
| 37 | *.o | 37 | *.o |
| 38 | *.so | 38 | *.so |
| 39 | */*.so | ||
| 39 | *.s | 40 | *.s |
| 40 | *.pyd | 41 | *.pyd |
| 41 | *.dll | 42 | *.dll |
| @@ -224,8 +224,8 @@ $ ./build python | |||
| 224 | And to import it | 224 | And to import it |
| 225 | 225 | ||
| 226 | ``` | 226 | ``` |
| 227 | $ python # In the main folder | 227 | $ python # In the main folder or in the python subfolder |
| 228 | >>> import nissy_python_module as nissy # In the python shell | 228 | >>> import nissy # In the python shell |
| 229 | ``` | 229 | ``` |
| 230 | 230 | ||
| 231 | From here you can call the library functions directly, for example: | 231 | From here you can call the library functions directly, for example: |
| @@ -280,7 +280,7 @@ build_python() { | |||
| 280 | fi | 280 | fi |
| 281 | build_nissy || exit 1 | 281 | build_nissy || exit 1 |
| 282 | run $CC $PYCFLAGS $WFLAGS $PYTHON3_INCLUDES $OFLAGS -shared \ | 282 | run $CC $PYCFLAGS $WFLAGS $PYTHON3_INCLUDES $OFLAGS -shared \ |
| 283 | -o nissy_python_module.so nissy.o python/nissy_module.c | 283 | -o python/nissy.so nissy.o python/nissy_module.c |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | build_cpp() { | 286 | build_cpp() { |
diff --git a/python/examples/move.py b/python/examples/move.py index 9c7a756..0ed879b 100644 --- a/python/examples/move.py +++ b/python/examples/move.py | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | # See the solve.py example for more details on how this works | 2 | # See the solve.py example for more details on how this works |
| 3 | 3 | ||
| 4 | import os, sys | 4 | import os, sys |
| 5 | 5 | ||
| 6 | # Assume we are eithe rin the top-level directory of the nissy-core repo, | ||
| 7 | # or in the python subdirectory | ||
| 6 | sys.path.append(os.getcwd()) | 8 | sys.path.append(os.getcwd()) |
| 7 | import nissy_python_module as nissy | 9 | sys.path.append(os.getcwd() + os.path.sep + "python") |
| 10 | import nissy | ||
| 8 | 11 | ||
| 9 | cube = nissy.applymoves(nissy.solved_cube, "R' U' F"); | 12 | cube = nissy.applymoves(nissy.solved_cube, "R' U' F"); |
| 10 | print("Cube after the moves R' U' F:") | 13 | print("Cube after the moves R' U' F:") |
diff --git a/python/examples/solve.py b/python/examples/solve.py index e3752fe..d77dd74 100644 --- a/python/examples/solve.py +++ b/python/examples/solve.py | |||
| @@ -1,14 +1,15 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | 2 | ||
| 3 | # Compile the python module with "make python", then run this from the main | 3 | # Run "./build python", then run this from either the top-level directory |
| 4 | # folder containing nissy_python_module.so | 4 | # of the nissy-core repo or from the python subdirectory. |
| 5 | 5 | ||
| 6 | # Append the main folder to the python path so we can load the module | 6 | # Append the directories to the python path so we can load the module |
| 7 | import sys, os | 7 | import sys, os |
| 8 | sys.path.append(os.getcwd()) | 8 | sys.path.append(os.getcwd()) |
| 9 | sys.path.append(os.getcwd() + os.path.sep + "python") | ||
| 9 | 10 | ||
| 10 | # Import with a nicer name | 11 | # Import with a nicer name |
| 11 | import nissy_python_module as nissy | 12 | import nissy |
| 12 | 13 | ||
| 13 | # Choose the solver you prefer | 14 | # Choose the solver you prefer |
| 14 | solver = "h48h0k4" | 15 | solver = "h48h0k4" |
diff --git a/python/examples/variations.py b/python/examples/variations.py index 1a9d5bb..2507e6e 100644 --- a/python/examples/variations.py +++ b/python/examples/variations.py | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | # See the solve.py example for more details on how this works | 2 | # See the solve.py example for more details on how this works |
| 3 | 3 | ||
| 4 | import sys, os | 4 | import sys, os |
| 5 | sys.path.append(os.getcwd()) | 5 | sys.path.append(os.getcwd()) |
| 6 | import nissy_python_module as nissy | 6 | sys.path.append(os.getcwd() + os.path.sep + "python") |
| 7 | import nissy | ||
| 7 | 8 | ||
| 8 | moves = "R U' Bw2 M D' x' F B(E2 F D B' Lw2 U2 U' S2 B)" | 9 | moves = "R U' Bw2 M D' x' F B(E2 F D B' Lw2 U2 U' S2 B)" |
| 9 | 10 | ||
diff --git a/python/nissy_module.c b/python/nissy_module.c index 88109d3..bff4ead 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -431,7 +431,7 @@ static PyMethodDef nissy_methods[] = { | |||
| 431 | { NULL, NULL, 0, NULL } | 431 | { NULL, NULL, 0, NULL } |
| 432 | }; | 432 | }; |
| 433 | 433 | ||
| 434 | static struct PyModuleDef nissy_python_module = { | 434 | static struct PyModuleDef nissy = { |
| 435 | .m_base = PyModuleDef_HEAD_INIT, | 435 | .m_base = PyModuleDef_HEAD_INIT, |
| 436 | .m_name = "nissy", | 436 | .m_name = "nissy", |
| 437 | .m_doc = "python module for libnissy", | 437 | .m_doc = "python module for libnissy", |
| @@ -449,11 +449,11 @@ log_stdout(const char *str, void *unused) | |||
| 449 | fprintf(stderr, "%s", str); | 449 | fprintf(stderr, "%s", str); |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | PyMODINIT_FUNC PyInit_nissy_python_module(void) { | 452 | PyMODINIT_FUNC PyInit_nissy(void) { |
| 453 | PyObject *module; | 453 | PyObject *module; |
| 454 | 454 | ||
| 455 | nissy_setlogger(log_stdout, NULL); | 455 | nissy_setlogger(log_stdout, NULL); |
| 456 | module = PyModule_Create(&nissy_python_module); | 456 | module = PyModule_Create(&nissy); |
| 457 | 457 | ||
| 458 | PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); | 458 | PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); |
| 459 | PyModule_AddIntConstant(module, "nissflag_normal", NISSY_NISSFLAG_NORMAL); | 459 | PyModule_AddIntConstant(module, "nissflag_normal", NISSY_NISSFLAG_NORMAL); |
