Skip to content

Commit 8733413

Browse files
authored
Merge pull request #189 from OpenMS/remove_py2
Remove OrderKeepingDict. as of py 3.7 dict keeps order. Removed some …
2 parents 35eb3ab + 919817d commit 8733413

File tree

11 files changed

+59
-197
lines changed

11 files changed

+59
-197
lines changed

.github/workflows/ci-autowrap.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
include:
18-
# - CYTHON: "<=0.29.21"
19-
# python-version: "2.7"
20-
- CYTHON: "<=0.29.21"
21-
python-version: "3.7"
2218
- CYTHON: "<=0.29.21"
2319
python-version: "3.9" # Cython < 0.29.21 not compatible with 3.10, so neither are we
24-
# - CYTHON: ">0.29.21"
25-
# python-version: "2.7"
26-
- CYTHON: ">0.29.21"
27-
python-version: "3.7"
2820
- CYTHON: ">0.29.21"
2921
python-version: "3.10"
30-
- CYTHON: "==3.0.0a10"
31-
python-version: "3.7"
32-
- CYTHON: "==3.0.0a10"
22+
- CYTHON: "==3.0.0"
3323
python-version: "3.10"
24+
- CYTHON: "==3.0.0"
25+
python-version: "3.11"
26+
- CYTHON: "==3.0.0"
27+
python-version: "3.12"
28+
- CYTHON: "==3.1.0"
29+
python-version: "3.10"
30+
- CYTHON: "==3.1.0"
31+
python-version: "3.11"
32+
- CYTHON: "==3.1.0"
33+
python-version: "3.12"
3434
steps:
35-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
3636

3737
- name: Set up Python ${{ matrix.python-version }}
3838
uses: actions/setup-python@v4
@@ -45,6 +45,9 @@ jobs:
4545
- name: Install pytest
4646
run: |
4747
python -m pip install pytest
48+
- name: Install setuptools
49+
run: |
50+
python -m pip install setuptools
4851
- name: Upgrade cython version
4952
run: |
5053
python -m pip install "Cython${{ matrix.CYTHON }}"

.github/workflows/release-autowrap.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
build_publish:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919

2020
- name: Set up Python
2121
uses: actions/setup-python@v4
2222
with:
23-
python-version: 3.9
23+
python-version: 3.11
2424

2525
- name: Upgrade pip version
2626
run: |
@@ -30,6 +30,10 @@ jobs:
3030
run: |
3131
python -m pip install wheel
3232
33+
- name: Install setuptools
34+
run: |
35+
python -m pip install setuptools
36+
3337
- name: Build wheel and source distribution
3438
run: |
3539
python setup.py bdist_wheel sdist
@@ -46,12 +50,12 @@ jobs:
4650
id: version
4751

4852
- name: Create github release
49-
uses: softprops/action-gh-release@v1
53+
uses: softprops/action-gh-release@v2
5054
id: create_release
5155
with:
5256
draft: false
5357
prerelease: false
54-
release_name: ${{ steps.version.outputs.version }}
58+
name: ${{ steps.version.outputs.version }}
5559
tag_name: release/${{ steps.version.outputs.version }}
5660
body_path: CHANGELOG.md
5761
env:

autowrap/Code.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,6 @@
3737
import string
3838
import re
3939

40-
try:
41-
unicode = unicode
42-
except NameError:
43-
# 'unicode' is undefined, must be Python 3
44-
str = str
45-
unicode = str
46-
bytes = bytes
47-
basestring = (str, bytes)
48-
else:
49-
# 'unicode' exists, must be Python 2
50-
str = str
51-
unicode = unicode
52-
bytes = str
53-
basestring = basestring
54-
55-
5640
class Code(object):
5741
def __init__(self):
5842
self.content: List[Union[Code, str]] = []
@@ -74,7 +58,7 @@ def add(self, what: Union[str, bytes, Code], *a, **kw) -> Code:
7458
kw.update(a[0])
7559
if "self" in kw:
7660
del kw["self"] # self causes problems in substitute call below
77-
if isinstance(what, basestring):
61+
if isinstance(what, (str, bytes)):
7862
try:
7963
res = string.Template(what).substitute(**kw)
8064
except ValueError:
@@ -92,7 +76,7 @@ def add(self, what: Union[str, bytes, Code], *a, **kw) -> Code:
9276
def _render(self, _indent="") -> List[str]:
9377
result = []
9478
for content in self.content:
95-
if isinstance(content, basestring):
79+
if isinstance(content, (str, bytes)):
9680
result.append(_indent + content)
9781
else:
9882
newindent = _indent + " " * 4

autowrap/CodeGenerator.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,6 @@
8484
def namespace_handler(ns):
8585
return ns
8686

87-
88-
try:
89-
unicode = unicode
90-
except NameError:
91-
# 'unicode' is undefined, must be Python 3
92-
str = str
93-
unicode = str
94-
bytes = bytes
95-
basestring = (str, bytes)
96-
else:
97-
# 'unicode' exists, must be Python 2
98-
str = str
99-
unicode = unicode
100-
bytes = str
101-
basestring = basestring
102-
103-
10487
def augment_arg_names(method):
10588
"""replaces missing arg_names with "in_%d" % i, where i is the position
10689
number of the arg"""
@@ -1276,7 +1259,7 @@ def _create_wrapper_for_attribute(self, attribute):
12761259
)
12771260
indented = Code()
12781261

1279-
if isinstance(cleanup, basestring):
1262+
if isinstance(cleanup, (str, bytes)):
12801263
cleanup = " %s" % cleanup
12811264

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

12891272
cy_type = self.cr.cython_type(t)
12901273

1291-
if isinstance(to_py_code, basestring):
1274+
if isinstance(to_py_code, (str, bytes)):
12921275
to_py_code = " %s" % to_py_code
12931276

1294-
if isinstance(access_stmt, basestring):
1277+
if isinstance(access_stmt, (str, bytes)):
12951278
access_stmt = " %s" % access_stmt
12961279

12971280
if t.is_ptr:
@@ -1360,7 +1343,7 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
13601343
else:
13611344
indented = meth_code
13621345

1363-
if isinstance(full_call_stmt, basestring):
1346+
if isinstance(full_call_stmt, (str, bytes)):
13641347
indented.add(
13651348
"""
13661349
| $full_call_stmt
@@ -1373,14 +1356,14 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
13731356
for cleanup in reversed(cleanups):
13741357
if not cleanup:
13751358
continue
1376-
if isinstance(cleanup, basestring):
1359+
if isinstance(cleanup, (str, bytes)):
13771360
cleanup = " %s" % cleanup
13781361
indented.add(cleanup)
13791362

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

13821365
if to_py_code is not None: # for non void return value
1383-
if isinstance(to_py_code, basestring):
1366+
if isinstance(to_py_code, (str, bytes)):
13841367
to_py_code = " %s" % to_py_code
13851368
indented.add(to_py_code)
13861369
indented.add(" return py_result")
@@ -1455,7 +1438,7 @@ def _create_wrapper_for_free_function(
14551438
out_converter = self.cr.get(res_t)
14561439
full_call_stmt = out_converter.call_method(res_t, cy_call_str)
14571440

1458-
if isinstance(full_call_stmt, basestring):
1441+
if isinstance(full_call_stmt, (str, bytes)):
14591442
fun_code.add(
14601443
"""
14611444
| $full_call_stmt
@@ -1468,15 +1451,15 @@ def _create_wrapper_for_free_function(
14681451
for cleanup in reversed(cleanups):
14691452
if not cleanup:
14701453
continue
1471-
if isinstance(cleanup, basestring):
1454+
if isinstance(cleanup, (str, bytes)):
14721455
cleanup = " %s" % cleanup
14731456
fun_code.add(cleanup)
14741457

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

14771460
out_vars = ["py_result"]
14781461
if to_py_code is not None: # for non void return value
1479-
if isinstance(to_py_code, basestring):
1462+
if isinstance(to_py_code, (str, bytes)):
14801463
to_py_code = " %s" % to_py_code
14811464
fun_code.add(to_py_code)
14821465
fun_code.add(" return %s" % (", ".join(out_vars)))
@@ -1573,7 +1556,7 @@ def create_wrapper_for_nonoverloaded_constructor(self, class_decl, py_name, cons
15731556
for cleanup in reversed(cleanups):
15741557
if not cleanup:
15751558
continue
1576-
if isinstance(cleanup, basestring):
1559+
if isinstance(cleanup, (str, bytes)):
15771560
cleanup = " %s" % cleanup
15781561
cons_code.add(cleanup)
15791562

@@ -1699,7 +1682,7 @@ def create_special_getitem_method(self, mdcl):
16991682
out_converter = self.cr.get(res_t)
17001683
full_call_stmt = out_converter.call_method(res_t, cy_call_str)
17011684

1702-
if isinstance(full_call_stmt, basestring):
1685+
if isinstance(full_call_stmt, (str, bytes)):
17031686
meth_code.add(
17041687
"""
17051688
| $full_call_stmt
@@ -1712,14 +1695,14 @@ def create_special_getitem_method(self, mdcl):
17121695
for cleanup in reversed(cleanups):
17131696
if not cleanup:
17141697
continue
1715-
if isinstance(cleanup, basestring):
1698+
if isinstance(cleanup, (str, bytes)):
17161699
cleanup = Code().add(cleanup)
17171700
meth_code.add(cleanup)
17181701

17191702
out_var = "py_result"
17201703
to_py_code = out_converter.output_conversion(res_t, "_r", out_var)
17211704
if to_py_code is not None: # for non void return value
1722-
if isinstance(to_py_code, basestring):
1705+
if isinstance(to_py_code, (str, bytes)):
17231706
to_py_code = " %s" % to_py_code
17241707
meth_code.add(to_py_code)
17251708
meth_code.add(" return $out_var", locals())
@@ -1827,7 +1810,7 @@ def create_cast_methods(self, mdecls):
18271810
call_stmt = "<%s>(deref(self.inst.get()))" % cy_t
18281811
full_call_stmt = out_converter.call_method(res_t, call_stmt)
18291812

1830-
if isinstance(full_call_stmt, basestring):
1813+
if isinstance(full_call_stmt, (str, bytes)):
18311814
code.add(
18321815
"""
18331816
| $full_call_stmt
@@ -1838,7 +1821,7 @@ def create_cast_methods(self, mdecls):
18381821
code.add(full_call_stmt)
18391822

18401823
to_py_code = out_converter.output_conversion(res_t, "_r", "py_res")
1841-
if isinstance(to_py_code, basestring):
1824+
if isinstance(to_py_code, (str, bytes)):
18421825
to_py_code = " %s" % to_py_code
18431826
code.add(to_py_code)
18441827
code.add(""" return py_res""")

autowrap/ConversionProvider.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,6 @@
4040
import logging as L
4141
import string
4242

43-
try:
44-
unicode = unicode
45-
except NameError:
46-
# 'unicode' is undefined, must be Python 3
47-
str = str
48-
unicode = str
49-
bytes = bytes
50-
basestring = (str, bytes)
51-
else:
52-
# 'unicode' exists, must be Python 2
53-
str = str
54-
unicode = unicode
55-
bytes = str
56-
basestring = basestring
57-
58-
5943
def mangle(s):
6044
s = s.replace("(", "_l_")
6145
s = s.replace(")", "_r_")
@@ -2036,7 +2020,7 @@ def input_conversion(
20362020
# Cython understands it and uses the Py_IsUnicodeCheck
20372021
code.add(
20382022
"""
2039-
|if isinstance($argument_var, unicode):
2023+
|if isinstance($argument_var, str):
20402024
| $argument_var = $argument_var.encode('utf-8')
20412025
""",
20422026
locals(),
@@ -2222,7 +2206,7 @@ def __contains__(self, cpp_type):
22222206
return False
22232207

22242208
def cython_type(self, type_: Union[CppType, AnyStr]) -> CppType:
2225-
if isinstance(type_, basestring):
2209+
if isinstance(type_, (str, bytes)):
22262210
type_ = CppType(type_)
22272211
return type_.transformed(self.instance_mapping)
22282212

autowrap/DeclResolver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import autowrap.Utils as Utils
3838
import os
3939
from collections import defaultdict
40-
from autowrap.tools import OrderKeepingDictionary
4140

4241

4342
__doc__ = """
@@ -170,7 +169,7 @@ class ResolvedClass(object):
170169
"""
171170

172171
name: str
173-
methods: OrderKeepingDictionary
172+
methods: dict
174173
attributes: List[ResolvedAttribute]
175174
cpp_decl: PXDParser.CppClassDecl
176175
ns: AnyStr
@@ -185,7 +184,7 @@ class ResolvedClass(object):
185184
def __init__(self, name, methods, attributes, decl, instance_map, local_map):
186185
self.name: str = name
187186
# resolve overloads
188-
self.methods: OrderKeepingDictionary = OrderKeepingDictionary()
187+
self.methods: dict = {}
189188
for m in methods:
190189
self.methods.setdefault(m.name, []).append(m)
191190
self.attributes = attributes

autowrap/PXDParser.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
from autowrap.Code import Code as Code
5454

5555
from collections import defaultdict
56-
from .tools import OrderKeepingDictionary
5756

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

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

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

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

403402
class_annotations = parse_class_annotations(node, lines)
404-
methods = OrderKeepingDictionary()
403+
methods = dict()
405404
attributes = []
406405
for att in node.attributes:
407406
decl = None
@@ -583,10 +582,10 @@ def parse_pxd_file(path, warn_level=1):
583582

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

586-
import pkg_resources
585+
from importlib.resources import files
587586

588587
# TODO sync with CodeGenerator.py function fixed_include_dirs
589-
data = pkg_resources.resource_filename("autowrap", "data_files/autowrap")
588+
data = files("autowrap").joinpath("data_files/autowrap")
590589
options.include_path = [data]
591590
options.language_level = sys.version_info.major
592591

0 commit comments

Comments
 (0)