diff options
-rw-r--r-- | plugins/yaml/python/node.c | 8 | ||||
-rw-r--r-- | plugins/yaml/python/reader.c | 28 | ||||
-rw-r--r-- | plugins/yaml/python/tree.c | 8 | ||||
-rwxr-xr-x | tools/maint/coding_rules.sh | 84 |
4 files changed, 106 insertions, 22 deletions
diff --git a/plugins/yaml/python/node.c b/plugins/yaml/python/node.c index d5e5a48..7db6e59 100644 --- a/plugins/yaml/python/node.c +++ b/plugins/yaml/python/node.c @@ -81,7 +81,7 @@ static PyObject *py_yaml_node_find_by_path(PyObject *self, PyObject *args) size_t count; /* Quantité de trouvailles */ size_t i; /* Boucle de parcours */ -#define YAML_NODE_FIND_BY_PATH PYTHON_METHOD_DEF \ +#define YAML_NODE_FIND_BY_PATH_METHOD PYTHON_METHOD_DEF \ ( \ find_by_path, "path, /, prepare=False", \ METH_VARARGS, py_yaml_node, \ @@ -149,7 +149,7 @@ static PyObject *py_yaml_node_find_one_by_path(PyObject *self, PyObject *args) GYamlNode *node; /* Version GLib du noeud */ GYamlNode *found; /* Création GLib à transmettre */ -#define YAML_NODE_FIND_ONE_BY_PATH PYTHON_METHOD_DEF \ +#define YAML_NODE_FIND_ONE_BY_PATH_METHOD PYTHON_METHOD_DEF \ ( \ find_one_by_path, "path, /, prepare=False", \ METH_VARARGS, py_yaml_node, \ @@ -250,8 +250,8 @@ static PyObject *py_yaml_node_get_yaml_line(PyObject *self, void *closure) PyTypeObject *get_python_yaml_node_type(void) { static PyMethodDef py_yaml_node_methods[] = { - YAML_NODE_FIND_BY_PATH, - YAML_NODE_FIND_ONE_BY_PATH, + YAML_NODE_FIND_BY_PATH_METHOD, + YAML_NODE_FIND_ONE_BY_PATH_METHOD, { NULL } }; diff --git a/plugins/yaml/python/reader.c b/plugins/yaml/python/reader.c index a69e54f..f80623f 100644 --- a/plugins/yaml/python/reader.c +++ b/plugins/yaml/python/reader.c @@ -77,11 +77,11 @@ static PyObject *py_yaml_reader_new_from_content(PyObject *self, PyObject *args) int ret; /* Bilan de lecture des args. */ GYamlReader *reader; /* Création GLib à transmettre */ -#define YAML_READER_NEW_FROM_CONTENT PYTHON_METHOD_DEF \ -( \ - new_from_content, "content", \ - METH_STATIC | METH_VARARGS, py_yaml_reader, \ - "Load a Yaml content." \ +#define YAML_READER_NEW_FROM_CONTENT_METHOD PYTHON_METHOD_DEF \ +( \ + new_from_content, "content", \ + METH_STATIC | METH_VARARGS, py_yaml_reader, \ + "Load a Yaml content." \ ) /** @@ -132,13 +132,13 @@ static PyObject *py_yaml_reader_new_from_path(PyObject *self, PyObject *args) int ret; /* Bilan de lecture des args. */ GYamlReader *reader; /* Création GLib à transmettre */ -#define YAML_READER_NEW_FROM_PATH PYTHON_METHOD_DEF \ -( \ - new_from_path, "path", \ - METH_STATIC | METH_VARARGS, py_yaml_reader, \ - "Load a Yaml content from a path.\n" \ - "\n" \ - "The path can be a filename or a resource URI." \ +#define YAML_READER_NEW_FROM_PATH_METHOD PYTHON_METHOD_DEF \ +( \ + new_from_path, "path", \ + METH_STATIC | METH_VARARGS, py_yaml_reader, \ + "Load a Yaml content from a path.\n" \ + "\n" \ + "The path can be a filename or a resource URI." \ ) ret = PyArg_ParseTuple(args, "s", &path); @@ -281,8 +281,8 @@ static PyObject *py_yaml_reader_get_tree(PyObject *self, void *closure) PyTypeObject *get_python_yaml_reader_type(void) { static PyMethodDef py_yaml_reader_methods[] = { - YAML_READER_NEW_FROM_CONTENT, - YAML_READER_NEW_FROM_PATH, + YAML_READER_NEW_FROM_CONTENT_METHOD, + YAML_READER_NEW_FROM_PATH_METHOD, { NULL } }; diff --git a/plugins/yaml/python/tree.c b/plugins/yaml/python/tree.c index a204a11..7d28254 100644 --- a/plugins/yaml/python/tree.c +++ b/plugins/yaml/python/tree.c @@ -160,7 +160,7 @@ static PyObject *py_yaml_tree_find_by_path(PyObject *self, PyObject *args) size_t count; /* Quantité de trouvailles */ size_t i; /* Boucle de parcours */ -#define YAML_TREE_FIND_BY_PATH PYTHON_METHOD_DEF \ +#define YAML_TREE_FIND_BY_PATH_METHOD PYTHON_METHOD_DEF \ ( \ find_by_path, "path, /, prepare=False", \ METH_VARARGS, py_yaml_tree, \ @@ -228,7 +228,7 @@ static PyObject *py_yaml_tree_find_one_by_path(PyObject *self, PyObject *args) GYamlTree *tree; /* Version GLib du type */ GYamlNode *found; /* Création GLib à transmettre */ -#define YAML_TREE_FIND_ONE_BY_PATH PYTHON_METHOD_DEF \ +#define YAML_TREE_FIND_ONE_BY_PATH_METHOD PYTHON_METHOD_DEF \ ( \ find_one_by_path, "path, /, prepare=False", \ METH_VARARGS, py_yaml_tree, \ @@ -321,8 +321,8 @@ static PyObject *py_yaml_tree_get_root(PyObject *self, void *closure) PyTypeObject *get_python_yaml_tree_type(void) { static PyMethodDef py_yaml_tree_methods[] = { - YAML_TREE_FIND_BY_PATH, - YAML_TREE_FIND_ONE_BY_PATH, + YAML_TREE_FIND_BY_PATH_METHOD, + YAML_TREE_FIND_ONE_BY_PATH_METHOD, { NULL } }; diff --git a/tools/maint/coding_rules.sh b/tools/maint/coding_rules.sh new file mode 100755 index 0000000..2f073f1 --- /dev/null +++ b/tools/maint/coding_rules.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +RESET_COLOR="\e[39m" +ERROR_COLOR="\e[91m" + + +# Check if all Python API definitions end with expected suffixes +function check_python_api_doc_suffix() +{ + filename=$1 + + egrep -q '/(pychrysalide|python)/' <<< $filename + + if [ $? -eq 0 ]; then + + for name in $( grep 'PYTHON_METHOD_DEF' $filename | cut -d ' ' -f 2 ); + do + + if [[ "$name" != *_METHOD ]]; then + + echo -e "[!] ${ERROR_COLOR}${filename}${RESET_COLOR}: bad Python method declaration '$name'" + + fi + + done + + for target in "PYTHON_WRAPPER_DEF" "PYTHON_VOID_WRAPPER_DEF" \ + "PYTHON_FALSE_WRAPPER_DEF" "PYTHON_TRUE_WRAPPER_DEF"; do + + for name in $( grep $target $filename | cut -d ' ' -f 2 ); + do + + if [[ "$name" != *_WRAPPER ]]; then + + echo -e "[!] ${ERROR_COLOR}${filename}${RESET_COLOR}: bad Python wrapper declaration '$name'" + + fi + + done + + done + + for target in "PYTHON_GETSET_DEF" "PYTHON_CAN_DEF_FULL" "PYTHON_IS_DEF_FULL" "PYTHON_HAS_DEF_FULL" \ + "PYTHON_RAWGET_DEF_FULL" "PYTHON_GET_DEF_FULL" "PYTHON_GETSET_DEF_FULL"; do + + for name in $( grep $target $filename | cut -d ' ' -f 2 ); + do + + if [[ "$name" != *_ATTRIB ]]; then + + echo -e "[!] ${ERROR_COLOR}${filename}${RESET_COLOR}: bad Python attribute declaration '$name'" + + fi + + done + + done + + for name in $( grep 'PYTHON_GETTER_WRAPPER_DEF' $filename | cut -d ' ' -f 2 ); + do + + if [[ "$name" != *_ATTRIB_WRAPPER ]]; then + + echo -e "[!] ${ERROR_COLOR}${filename}${RESET_COLOR}: bad Python wrapper declaration '$name'" + + fi + + done + + fi + +} + + +if [ ! -f configure.ac ]; then + echo "This script has to be run from the top directory." + exit 1 +fi + +for file in $( find . -type f -name '*.c' -exec grep -l 'Copyright.*Cyrille Bagard$' {} \; ); +do + check_python_api_doc_suffix $file + +done |