Skip to content

Commit

Permalink
#20 add flake8 testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Mar 20, 2024
1 parent 10d4888 commit a443870
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 49 deletions.
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max_line_length = 120
exclude=
.git,
.github,
build,
doc,
examples,
5 changes: 4 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ jobs:
- name: Install cppwg
run: |
python -m pip install --upgrade pip
pip install .
pip install .[dev]
- name: Lint with flake8
run: python -m flake8

- name: Test wrapper generation
run: python -m unittest tests/test_shapes.py
Expand Down
6 changes: 5 additions & 1 deletion cppwg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from cppwg.generators import *
from .generators import CppWrapperGenerator

__all__ = [
"CppWrapperGenerator",
]
2 changes: 1 addition & 1 deletion cppwg/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess

from pathlib import Path
from typing import Dict, List, Optional
from typing import List, Optional

from pygccxml import __version__ as pygccxml_version
from pygccxml.declarations.namespace import namespace_t
Expand Down
4 changes: 2 additions & 2 deletions cppwg/input/base_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def hierarchy_attribute_gather(self, attribute_name: str) -> List[Any]:

if hasattr(self, attribute_name) and getattr(self, attribute_name) is not None:
att_list.extend(getattr(self, attribute_name))

if hasattr(self, "parent") and self.parent is not None:
att_list.extend(self.parent.hierarchy_attribute_gather(attribute_name))

return att_list
1 change: 1 addition & 0 deletions cppwg/input/class_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from typing import Any, Dict, Optional

from cppwg.input.cpp_type_info import CppTypeInfo
Expand Down
6 changes: 3 additions & 3 deletions cppwg/input/cpp_type_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_full_names(self) -> List[str]:

return full_names

# TODO: This method is not used, remove it?
# TODO: This method is not used, remove it?
def needs_header_file_instantiation(self):
"""
Does this class need to be instantiated in the header file
Expand All @@ -153,7 +153,7 @@ def needs_header_file_instantiation(self):
and (self.needs_instantiation)
)

# TODO: This method is not used, remove it?
# TODO: This method is not used, remove it?
def needs_header_file_typdef(self):
"""
Does this type need to be typdef'd with a nicer name in the header
Expand All @@ -162,7 +162,7 @@ def needs_header_file_typdef(self):

return (self.template_arg_lists is not None) and (not self.include_file_only)

# TODO: This method is not used, remove it?
# TODO: This method is not used, remove it?
def needs_auto_wrapper_generation(self):
"""
Does this class need a wrapper to be autogenerated.
Expand Down
2 changes: 1 addition & 1 deletion cppwg/input/info_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import logging

from typing import Any
from typing import Any, Dict, List

from cppwg.input.base_info import BaseInfo
from cppwg.input.class_info import CppClassInfo
Expand Down
2 changes: 1 addition & 1 deletion cppwg/input/module_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ def is_decl_in_source_path(self, decl: declaration_t) -> bool:
full_path = os.path.join(self.package_info.source_root, source_location)
if full_path in decl.location.file_name:
return True

return False
2 changes: 1 addition & 1 deletion cppwg/input/variable_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Dict, Optional

from cppwg.input.cpp_type_info import CppTypeInfo

Expand Down
11 changes: 5 additions & 6 deletions cppwg/parsers/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import yaml

from typing import Any, Optional
from typing import Any, Dict, Optional

import cppwg.templates.custom

Expand Down Expand Up @@ -72,7 +72,7 @@ def check_for_custom_generators(self, info: BaseInfo) -> None:
# string if needed. For example, a custom generator might be specified
# as `custom_generator: CPPWG_SOURCEROOT/path/to/CustomGenerator.py`
filepath: str = info.custom_generator.replace(
CPPWG_SOURCEROOT_STRING, self.source_root
CPPWG_SOURCEROOT_STRING, self.source_root
)
filepath = os.path.abspath(filepath)

Expand Down Expand Up @@ -194,7 +194,7 @@ def parse(self) -> PackageInfo:
self.package_info.module_info_collection.append(module_info)

# Parse the class data and create class info objects.
# Note: if module_config["use_all_classes"] == True, class info
# Note: if module_config["use_all_classes"] == True, class info
# objects will be added later after parsing the C++ source code.
if not module_config["use_all_classes"]:
if module_config["classes"]:
Expand All @@ -215,9 +215,8 @@ def parse(self) -> PackageInfo:
class_info.module_info = module_info
module_info.class_info_collection.append(class_info)


# Parse the free function data and create free function info objects.
# Note: if module_config["use_all_free_functions"] == True, free function
# Parse the free function data and create free function info objects.
# Note: if module_config["use_all_free_functions"] == True, free function
# info objects will be added later after parsing the C++ source code.
if not module_config["use_all_free_functions"]:
if module_config["free_functions"]:
Expand Down
47 changes: 29 additions & 18 deletions cppwg/templates/custom.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
"""
This class returns custom code snippets for use during the wrapper
generation processes. It can be used as a base classs for
custom code generators.
"""

class Custom:

"""
This class returns custom code snippets for use during the wrapper
generation processes. It can be used as a base classs for
custom code generators.
"""

def __init__(self):

pass

def get_class_cpp_pre_code(self, *args, **kwargs):


def get_class_cpp_pre_code(self, *args, **kwargs) -> str:
"""
Return a string of C++ code to be inserted before the class
definition.
"""

return ""

def get_class_cpp_def_code(self, *args, **kwargs):


def get_class_cpp_def_code(self, *args, **kwargs) -> str:
"""
Return a string of C++ code to be inserted in the class
definition.
"""

return ""

def get_module_code(self) -> str:
"""
Return a string of C++ code to be inserted in the module
definition.
"""

return ""

def get_module_code(self):

return ""
25 changes: 13 additions & 12 deletions cppwg/templates/pybind11_default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class_cpp_header = """\
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand Down Expand Up @@ -64,17 +63,19 @@ class {class_short_name}_Overloads : public {class_short_name}{{

class_method = """\
.def{def_adorn}(
"{method_name}",
({return_type}({self_ptr})({arg_signature}){const_adorn}) &{class_short_name}::{method_name},
"{method_name}",
({return_type}({self_ptr})({arg_signature}){const_adorn}) &{class_short_name}::{method_name},
{method_docs} {default_args} {call_policy})
"""

template_collection = {'class_cpp_header': class_cpp_header,
'free_function': free_function,
'class_hpp_header': class_hpp_header,
'class_method': class_method,
'class_definition': class_definition,
'class_virtual_override_header': class_virtual_override_header,
'class_virtual_override_footer': class_virtual_override_footer,
'smart_pointer_holder': smart_pointer_holder,
'method_virtual_override': method_virtual_override}
template_collection = {
"class_cpp_header": class_cpp_header,
"free_function": free_function,
"class_hpp_header": class_hpp_header,
"class_method": class_method,
"class_definition": class_definition,
"class_virtual_override_header": class_virtual_override_header,
"class_virtual_override_footer": class_virtual_override_footer,
"smart_pointer_holder": smart_pointer_holder,
"method_virtual_override": method_virtual_override,
}
2 changes: 1 addition & 1 deletion cppwg/writers/constructor_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def add_self(self, cpp_string: str) -> str:
cpp_string += ", ".join(arg_types)

cpp_string += " >()"

# Default args e.g. py::arg("i") = 1
default_args = ""
if not self.default_arg_exclusion_criteria():
Expand Down
2 changes: 2 additions & 0 deletions cppwg/writers/free_function_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict, List

from cppwg.input.free_function_info import CppFreeFunctionInfo

from cppwg.writers.base_writer import CppBaseWrapperWriter
Expand Down
3 changes: 3 additions & 0 deletions cppwg/writers/header_collection_writer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os

from typing import Dict

from cppwg.input.class_info import CppClassInfo
from cppwg.input.free_function_info import CppFreeFunctionInfo
from cppwg.input.package_info import PackageInfo


class CppHeaderCollectionWriter:
"""
This class manages the generation of the header collection file, which
Expand Down
2 changes: 1 addition & 1 deletion cppwg/writers/module_writer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import logging

from typing import Dict
from typing import Dict, List

from pygccxml.declarations.class_declaration import class_t
from pygccxml.declarations.namespace import namespace_t
Expand Down

0 comments on commit a443870

Please sign in to comment.