Moved code up one level post build folder creation
This commit is contained in:
0
src/utils/cbindings/__init__.py
Normal file
0
src/utils/cbindings/__init__.py
Normal file
20
src/utils/cbindings/gtkmemreaper.py
Normal file
20
src/utils/cbindings/gtkmemreaper.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Python imports
|
||||
import pkg_resources
|
||||
import importlib.util
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
def __bootstrap__():
|
||||
__file__ = pkg_resources.resource_filename(__name__, 'gtkmemreaper.cpython-313-x86_64-linux-gnu.so')
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
__name__,
|
||||
__file__
|
||||
)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
|
||||
__bootstrap__()
|
||||
15
src/utils/cbindings/python_package_works/compile.sh
Executable file
15
src/utils/cbindings/python_package_works/compile.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# . CONFIG.sh
|
||||
|
||||
# set -o xtrace ## To debug scripts
|
||||
# set -o errexit ## To exit on error
|
||||
# set -o errunset ## To exit if a variable is referenced but not set
|
||||
|
||||
function main() {
|
||||
cd "$(dirname "")"
|
||||
echo "Working Dir: " $(pwd)
|
||||
|
||||
python3 setup.py build && python3 setup.py install --user
|
||||
}
|
||||
main "$@";
|
||||
62
src/utils/cbindings/python_package_works/gtkmemreaper.c
Normal file
62
src/utils/cbindings/python_package_works/gtkmemreaper.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <Python.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <cairo.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// static PyObject* free_pixbuf(PyObject* self, PyObject* args) {
|
||||
static PyObject* free_pixbuf(PyObject* self, PyObject* args) {
|
||||
PyObject *py_pixbuf;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &py_pixbuf)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
GdkPixbuf *pixbuf = (GdkPixbuf *) PyLong_AsVoidPtr(py_pixbuf);
|
||||
if (!GDK_IS_PIXBUF(pixbuf)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid GdkPixbuf pointer.");
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
g_object_unref(pixbuf);
|
||||
g_assert_null(pixbuf);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject* free_list_store(PyObject* self, PyObject* args) {
|
||||
PyObject *py_list_store;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &py_list_store)) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
GtkListStore *list_store = (GtkListStore *) PyLong_AsVoidPtr(py_list_store);
|
||||
if (!GTK_IS_LIST_STORE(list_store)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid Gtk.ListStore pointer.");
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
g_object_unref(list_store);
|
||||
g_assert_null(list_store);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef Methods[] = {
|
||||
{"free_pixbuf", free_pixbuf, METH_VARARGS, "Clear GdkPixbuf* ."},
|
||||
{"free_list_store", free_list_store, METH_VARARGS, "Clear GtkListStore* ."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"gtkmemreaper",
|
||||
NULL,
|
||||
-1,
|
||||
Methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_gtkmemreaper(void) {
|
||||
return PyModule_Create(&moduledef);
|
||||
}
|
||||
28
src/utils/cbindings/python_package_works/setup.py
Normal file
28
src/utils/cbindings/python_package_works/setup.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Python imports
|
||||
from setuptools import setup, Extension
|
||||
from subprocess import check_output
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
pkg_config_args = ["gdk-pixbuf-2.0", "cairo", "gtk+-3.0"]
|
||||
|
||||
def get_pkgconfig_flags(flag_type):
|
||||
return check_output(["pkg-config", flag_type] + pkg_config_args).decode().split()
|
||||
|
||||
ext = Extension(
|
||||
"gtkmemreaper",
|
||||
sources = ["gtkmemreaper.c"],
|
||||
include_dirs = [],
|
||||
extra_compile_args = get_pkgconfig_flags("--cflags"),
|
||||
extra_link_args = get_pkgconfig_flags("--libs")
|
||||
)
|
||||
|
||||
setup(
|
||||
name = "gtkmemreaper",
|
||||
version = "0.1",
|
||||
ext_modules = [ext]
|
||||
)
|
||||
Reference in New Issue
Block a user