Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt install -y python3-pip python3-clang-20
# python -m pip install --upgrade pip
# pip install clang==19.1.7
- name: Install package
run: |
pip install .
pip uninstall -y clang
- name: Run Tests
run: |
python test/run_tests.py
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# pytest
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt install -y python3-pip python3-clang-20
pip3 install ruff
- name: lint
run: |
ruff check
2 changes: 1 addition & 1 deletion cl_bindgen/mangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init(self):
def can_mangle(self, string):
# if there is already a colon in the name, then
# common lisp won't accept it, so don't do anything:
return not ':' in string
return ':' not in string

def mangle(self, string):
return ':' + string
Expand Down
6 changes: 3 additions & 3 deletions cl_bindgen/pointer_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def process_pointer_expansion_rules(options: dict):
def _match_regex_list(regex_list, name):
for r in regex_list:
if r.search(name):
return True;
return False;
return True
return False

def _compile_regexes(regexes):
return [re.compile(m) for m in regexes]
Expand Down Expand Up @@ -67,7 +67,7 @@ def fn(typename):
includer = _compile_regexes(include_matcher)
return lambda x: (x in white_set or _match_regex_list(includer, x)) and x not in black_set
else:
return lambda x: typename in white_set and typename not in black_set
return lambda x: x in white_set and x not in black_set
else:
# import everything
return lambda x: True
32 changes: 16 additions & 16 deletions cl_bindgen/processfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys
import os.path
import errno
import copy
import io
import itertools
import typing
import re
from enum import Enum
from dataclasses import dataclass, field
import dataclasses
from dataclasses import dataclass
from collections import namedtuple
import cl_bindgen.macro_util as macro_util
from cl_bindgen.exception import ProcessingError
Expand Down Expand Up @@ -61,19 +61,19 @@ def format_errors(self):

@dataclass
class ProcessOptions:
typedef_manglers: list = field(default_factory=lambda: [])
enum_manglers: list = field(default_factory=lambda: [])
type_manglers: list = field(default_factory=lambda: [])
name_manglers: list = field(default_factory=lambda: [])
constant_manglers: list = field(default_factory=lambda: [])
typedef_manglers: list = dataclasses.field(default_factory=lambda: [])
enum_manglers: list = dataclasses.field(default_factory=lambda: [])
type_manglers: list = dataclasses.field(default_factory=lambda: [])
name_manglers: list = dataclasses.field(default_factory=lambda: [])
constant_manglers: list = dataclasses.field(default_factory=lambda: [])

macro_detector: typing.Callable[[str,str,], bool] = field(default_factory=lambda: lambda s, n: False)
expand_pointer_p: typing.Callable[[str], bool] = field(default_factory=lambda: lambda s: True)
declaim_inline_p: typing.Callable[[str], bool] = field(default_factory=lambda: lambda s: False)
macro_detector: typing.Callable[[str,str,], bool] = dataclasses.field(default_factory=lambda: lambda s, n: False)
expand_pointer_p: typing.Callable[[str], bool] = dataclasses.field(default_factory=lambda: lambda s: True)
declaim_inline_p: typing.Callable[[str], bool] = dataclasses.field(default_factory=lambda: lambda s: False)

output: str = field(default_factory=lambda: ":stdout")
output: str = dataclasses.field(default_factory=lambda: ":stdout")
package : str = None
arguments: list = field(default_factory=lambda: [])
arguments: list = dataclasses.field(default_factory=lambda: [])
force: bool = False

@staticmethod
Expand Down Expand Up @@ -155,7 +155,7 @@ def _cursor_typedef_str(type_obj, options):
return _mangle_string(type_decl_str, options.typedef_manglers)

def _cursor_lisp_type_str(type_obj, options, location=None):
assert(type(type_obj) == clang.Type)
assert(isinstance(type_obj, clang.Type))
kind = type_obj.kind
known_type = _cursor_lisp_type_str._builtin_table.get(kind)
if known_type:
Expand Down Expand Up @@ -274,7 +274,7 @@ def _process_macro_def(cursor, data, output, options):
try:
cl_literal = macro_util.convert_literal_token(tokens[0])
output.write(f"(defconstant {spelling} {cl_literal})\n\n")
except macro_util.LiteralConversionError as e:
except macro_util.LiteralConversionError:
print(f"Could not convert C literal `{tokens[0].spelling}` to CL literal", file=sys.stderr)
_output_unknown_macro_def(spelling, cursor, output)
else:
Expand Down Expand Up @@ -379,7 +379,7 @@ def _process_func_decl(cursor, data, output, options):

for arg in cursor.get_arguments():
arg_name = arg.spelling
if arg_name == "" or arg_name == None:
if arg_name == "" or arg_name is None:
arg_name = "unknown"
else:
arg_name = arg.spelling
Expand Down Expand Up @@ -465,7 +465,7 @@ def _process_file(filepath, output, options):
if diagnostics:
errors = []
for diag in diagnostics:
if options.force == False and not diag.severity < clang.Diagnostic.Fatal:
if not options.force and not diag.severity < clang.Diagnostic.Fatal:
raise ParserException(filepath, diagnostics)
errors.append(diag)
print(f'WARNING: errors occured while parsing {filepath}', file=sys.stderr)
Expand Down
9 changes: 4 additions & 5 deletions cl_bindgen/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import sys
import io
import copy
import yaml
import errno
Expand Down Expand Up @@ -76,7 +75,7 @@ def _process_batch_options(option, dictionary):
if package:
option.package = package
if force:
if not type(force) == type(True):
if not isinstance(force, bool):
raise BatchException(f"Invalid value in 'force' option: {force.__repr__()}")
option.force = force
if pkg_config:
Expand Down Expand Up @@ -126,7 +125,7 @@ def _arg_batch_files(arguments, options):
print(f'Error: {str(err)}.\nExiting')
exit(errno.EINVAL)
except processfile.ParserException as err:
print(f'Error encountered while processing file:')
print('Error encountered while processing file:')
print(err.format_errors(), file=sys.stderr)
print('\nNo output produced', file=sys.stderr)
exit(1)
Expand All @@ -146,7 +145,7 @@ def _arg_process_files(arguments, options):
file=sys.stderr)
exit(err.errno)
except processfile.ParserException as err:
print(f'Error encountered while processing file:')
print('Error encountered while processing file:')
print(err.format_errors(), file=sys.stderr)
print('\nNo output produced', file=sys.stderr)
exit(1)
Expand Down Expand Up @@ -225,7 +224,7 @@ def find_clang_resource_dir():
# probably don't need the sanity check, but it might prevent some problems
if os.path.exists(inc_path):
return inc_path
return None;
return None

def add_clang_dir(parsed_args):
if clang_inc_dir := find_clang_resource_dir():
Expand Down
2 changes: 1 addition & 1 deletion test/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _make_path_list(path):
rest, part = os.path.split(rest)
# When at the root dir, rest may just repeat over and over:
if rest == last:
break;
break
last = rest
lst.append(part)
lst.reverse()
Expand Down
5 changes: 1 addition & 4 deletions test/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import framework
from framework import TestOptions
import os
import shutil
import sys

import cl_bindgen.mangler as mangler
from cl_bindgen.processfile import ProcessOptions, process_file
from cl_bindgen.processfile import process_file
import cl_bindgen.util as util
from cl_bindgen.macro_util import macro_matches_file_path

def make_gen_fn():
options = util.build_default_options()
Expand Down