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
27 changes: 15 additions & 12 deletions .github/workflows/ci-autowrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ jobs:
fail-fast: false
matrix:
include:
# - CYTHON: "<=0.29.21"
# python-version: "2.7"
- CYTHON: "<=0.29.21"
python-version: "3.7"
- CYTHON: "<=0.29.21"
python-version: "3.9" # Cython < 0.29.21 not compatible with 3.10, so neither are we
# - CYTHON: ">0.29.21"
# python-version: "2.7"
- CYTHON: ">0.29.21"
python-version: "3.7"
- CYTHON: ">0.29.21"
python-version: "3.10"
- CYTHON: "==3.0.0a10"
python-version: "3.7"
- CYTHON: "==3.0.0a10"
- CYTHON: "==3.0.0"
python-version: "3.10"
- CYTHON: "==3.0.0"
python-version: "3.11"
- CYTHON: "==3.0.0"
python-version: "3.12"
- CYTHON: "==3.1.0"
python-version: "3.10"
- CYTHON: "==3.1.0"
python-version: "3.11"
- CYTHON: "==3.1.0"
python-version: "3.12"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -45,6 +45,9 @@ jobs:
- name: Install pytest
run: |
python -m pip install pytest
- name: Install setuptools
run: |
python -m pip install setuptools
- name: Upgrade cython version
run: |
python -m pip install "Cython${{ matrix.CYTHON }}"
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/release-autowrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
build_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11

- name: Upgrade pip version
run: |
Expand All @@ -30,6 +30,10 @@ jobs:
run: |
python -m pip install wheel

- name: Install setuptools
run: |
python -m pip install setuptools

- name: Build wheel and source distribution
run: |
python setup.py bdist_wheel sdist
Expand All @@ -46,12 +50,12 @@ jobs:
id: version

- name: Create github release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
id: create_release
with:
draft: false
prerelease: false
release_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
tag_name: release/${{ steps.version.outputs.version }}
body_path: CHANGELOG.md
env:
Expand Down
20 changes: 2 additions & 18 deletions autowrap/Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@
import string
import re

try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str, bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring


class Code(object):
def __init__(self):
self.content: List[Union[Code, str]] = []
Expand All @@ -74,7 +58,7 @@ def add(self, what: Union[str, bytes, Code], *a, **kw) -> Code:
kw.update(a[0])
if "self" in kw:
del kw["self"] # self causes problems in substitute call below
if isinstance(what, basestring):
if isinstance(what, (str, bytes)):
try:
res = string.Template(what).substitute(**kw)
except ValueError:
Expand All @@ -92,7 +76,7 @@ def add(self, what: Union[str, bytes, Code], *a, **kw) -> Code:
def _render(self, _indent="") -> List[str]:
result = []
for content in self.content:
if isinstance(content, basestring):
if isinstance(content, (str, bytes)):
result.append(_indent + content)
else:
newindent = _indent + " " * 4
Expand Down
47 changes: 15 additions & 32 deletions autowrap/CodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@
def namespace_handler(ns):
return ns


try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str, bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring


def augment_arg_names(method):
"""replaces missing arg_names with "in_%d" % i, where i is the position
number of the arg"""
Expand Down Expand Up @@ -1276,7 +1259,7 @@ def _create_wrapper_for_attribute(self, attribute):
)
indented = Code()

if isinstance(cleanup, basestring):
if isinstance(cleanup, (str, bytes)):
cleanup = " %s" % cleanup

indented.add(cleanup)
Expand All @@ -1288,10 +1271,10 @@ def _create_wrapper_for_attribute(self, attribute):

cy_type = self.cr.cython_type(t)

if isinstance(to_py_code, basestring):
if isinstance(to_py_code, (str, bytes)):
to_py_code = " %s" % to_py_code

if isinstance(access_stmt, basestring):
if isinstance(access_stmt, (str, bytes)):
access_stmt = " %s" % access_stmt

if t.is_ptr:
Expand Down Expand Up @@ -1360,7 +1343,7 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
else:
indented = meth_code

if isinstance(full_call_stmt, basestring):
if isinstance(full_call_stmt, (str, bytes)):
indented.add(
"""
| $full_call_stmt
Expand All @@ -1373,14 +1356,14 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
for cleanup in reversed(cleanups):
if not cleanup:
continue
if isinstance(cleanup, basestring):
if isinstance(cleanup, (str, bytes)):
cleanup = " %s" % cleanup
indented.add(cleanup)

to_py_code = out_converter.output_conversion(res_t, "_r", "py_result")

if to_py_code is not None: # for non void return value
if isinstance(to_py_code, basestring):
if isinstance(to_py_code, (str, bytes)):
to_py_code = " %s" % to_py_code
indented.add(to_py_code)
indented.add(" return py_result")
Expand Down Expand Up @@ -1455,7 +1438,7 @@ def _create_wrapper_for_free_function(
out_converter = self.cr.get(res_t)
full_call_stmt = out_converter.call_method(res_t, cy_call_str)

if isinstance(full_call_stmt, basestring):
if isinstance(full_call_stmt, (str, bytes)):
fun_code.add(
"""
| $full_call_stmt
Expand All @@ -1468,15 +1451,15 @@ def _create_wrapper_for_free_function(
for cleanup in reversed(cleanups):
if not cleanup:
continue
if isinstance(cleanup, basestring):
if isinstance(cleanup, (str, bytes)):
cleanup = " %s" % cleanup
fun_code.add(cleanup)

to_py_code = out_converter.output_conversion(res_t, "_r", "py_result")

out_vars = ["py_result"]
if to_py_code is not None: # for non void return value
if isinstance(to_py_code, basestring):
if isinstance(to_py_code, (str, bytes)):
to_py_code = " %s" % to_py_code
fun_code.add(to_py_code)
fun_code.add(" return %s" % (", ".join(out_vars)))
Expand Down Expand Up @@ -1573,7 +1556,7 @@ def create_wrapper_for_nonoverloaded_constructor(self, class_decl, py_name, cons
for cleanup in reversed(cleanups):
if not cleanup:
continue
if isinstance(cleanup, basestring):
if isinstance(cleanup, (str, bytes)):
cleanup = " %s" % cleanup
cons_code.add(cleanup)

Expand Down Expand Up @@ -1699,7 +1682,7 @@ def create_special_getitem_method(self, mdcl):
out_converter = self.cr.get(res_t)
full_call_stmt = out_converter.call_method(res_t, cy_call_str)

if isinstance(full_call_stmt, basestring):
if isinstance(full_call_stmt, (str, bytes)):
meth_code.add(
"""
| $full_call_stmt
Expand All @@ -1712,14 +1695,14 @@ def create_special_getitem_method(self, mdcl):
for cleanup in reversed(cleanups):
if not cleanup:
continue
if isinstance(cleanup, basestring):
if isinstance(cleanup, (str, bytes)):
cleanup = Code().add(cleanup)
meth_code.add(cleanup)

out_var = "py_result"
to_py_code = out_converter.output_conversion(res_t, "_r", out_var)
if to_py_code is not None: # for non void return value
if isinstance(to_py_code, basestring):
if isinstance(to_py_code, (str, bytes)):
to_py_code = " %s" % to_py_code
meth_code.add(to_py_code)
meth_code.add(" return $out_var", locals())
Expand Down Expand Up @@ -1827,7 +1810,7 @@ def create_cast_methods(self, mdecls):
call_stmt = "<%s>(deref(self.inst.get()))" % cy_t
full_call_stmt = out_converter.call_method(res_t, call_stmt)

if isinstance(full_call_stmt, basestring):
if isinstance(full_call_stmt, (str, bytes)):
code.add(
"""
| $full_call_stmt
Expand All @@ -1838,7 +1821,7 @@ def create_cast_methods(self, mdecls):
code.add(full_call_stmt)

to_py_code = out_converter.output_conversion(res_t, "_r", "py_res")
if isinstance(to_py_code, basestring):
if isinstance(to_py_code, (str, bytes)):
to_py_code = " %s" % to_py_code
code.add(to_py_code)
code.add(""" return py_res""")
Expand Down
20 changes: 2 additions & 18 deletions autowrap/ConversionProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@
import logging as L
import string

try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str, bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring


def mangle(s):
s = s.replace("(", "_l_")
s = s.replace(")", "_r_")
Expand Down Expand Up @@ -2036,7 +2020,7 @@ def input_conversion(
# Cython understands it and uses the Py_IsUnicodeCheck
code.add(
"""
|if isinstance($argument_var, unicode):
|if isinstance($argument_var, str):
| $argument_var = $argument_var.encode('utf-8')
""",
locals(),
Expand Down Expand Up @@ -2222,7 +2206,7 @@ def __contains__(self, cpp_type):
return False

def cython_type(self, type_: Union[CppType, AnyStr]) -> CppType:
if isinstance(type_, basestring):
if isinstance(type_, (str, bytes)):
type_ = CppType(type_)
return type_.transformed(self.instance_mapping)

Expand Down
5 changes: 2 additions & 3 deletions autowrap/DeclResolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import autowrap.Utils as Utils
import os
from collections import defaultdict
from autowrap.tools import OrderKeepingDictionary


__doc__ = """
Expand Down Expand Up @@ -170,7 +169,7 @@ class ResolvedClass(object):
"""

name: str
methods: OrderKeepingDictionary
methods: dict
attributes: List[ResolvedAttribute]
cpp_decl: PXDParser.CppClassDecl
ns: AnyStr
Expand All @@ -185,7 +184,7 @@ class ResolvedClass(object):
def __init__(self, name, methods, attributes, decl, instance_map, local_map):
self.name: str = name
# resolve overloads
self.methods: OrderKeepingDictionary = OrderKeepingDictionary()
self.methods: dict = {}
for m in methods:
self.methods.setdefault(m.name, []).append(m)
self.attributes = attributes
Expand Down
11 changes: 5 additions & 6 deletions autowrap/PXDParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from autowrap.Code import Code as Code

from collections import defaultdict
from .tools import OrderKeepingDictionary

AnnotDict = Dict[str, Union[bool, List[str]]]

Expand Down Expand Up @@ -143,7 +142,7 @@ def _parse_multiline_annotations(lines: Collection[str]) -> AnnotDict:
# make sure wrap-doc is always a Code object
if "wrap-doc" in result.keys():
doc = result.get("wrap-doc", [])
if isinstance(doc, basestring):
if isinstance(doc, (str, bytes)):
doc = [doc]

c = Code()
Expand Down Expand Up @@ -208,7 +207,7 @@ def parse_line_annotations(node: Cython.Compiler.Nodes.Node, lines: Sequence[str
# make sure wrap-doc is always a Code object
if "wrap-doc" in result.keys():
doc = result.get("wrap-doc", [])
if isinstance(doc, basestring):
if isinstance(doc, (str, bytes)):
doc = [doc]

c = Code()
Expand Down Expand Up @@ -401,7 +400,7 @@ def parseTree(cls, node: Cython.Compiler.Nodes.CppClassNode, lines: Collection[s
template_parameters = [t[0] for t in template_parameters]

class_annotations = parse_class_annotations(node, lines)
methods = OrderKeepingDictionary()
methods = dict()
attributes = []
for att in node.attributes:
decl = None
Expand Down Expand Up @@ -583,10 +582,10 @@ def parse_pxd_file(path, warn_level=1):

options, sources = parse_command_line(["--cplus", path])

import pkg_resources
from importlib.resources import files

# TODO sync with CodeGenerator.py function fixed_include_dirs
data = pkg_resources.resource_filename("autowrap", "data_files/autowrap")
data = files("autowrap").joinpath("data_files/autowrap")
options.include_path = [data]
options.language_level = sys.version_info.major

Expand Down
Loading
Loading