Skip to content

Commit e178aeb

Browse files
committed
Merge branch 'develop'
2 parents b67b261 + 5f6f235 commit e178aeb

File tree

266 files changed

+6354
-8244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+6354
-8244
lines changed

.github/workflows/tests.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
on: [push, pull_request]
1+
on:
2+
push:
3+
branches:
4+
- main
5+
- develop
6+
pull_request:
7+
28
jobs:
39
tests:
410
name: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.version }}-python-${{ matrix.python-version }}-${{ matrix.castxml-epic }}
@@ -93,12 +99,7 @@ jobs:
9399
if: matrix.os == 'macos-12'
94100
run: |
95101
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/5d937e938f7b882a3a3e7941e68f8312d0898aaf2082e00003dd362b1ba70b98b0a08706a1be28e71652a6a0f1e66f89768b5eaa20e5a100592d5b3deefec3f0/download | tar zxf - -C ~/
96-
- name: Setup castxml config
97-
if: matrix.compiler == 'gcc' && matrix.version == '9'
98-
run: mv unittests/configs/gcc9.cfg unittests/xml_generator.cfg;
99102
- name: Run tests
100103
run: |
101104
export PATH=~/castxml/bin:$PATH
102-
coverage run -m unittests.test_all
103-
coverage combine
104-
coverage xml
105+
pytest tests

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
*.pyo
33
*~
44
docs/_build
5+
tests/temp
6+
tests/data/pygccxml.cache
7+
tests/data/directory_cache_test
8+
tests/data/ogre.1.7.xml
59
unittests/temp
610
unittests/data/pygccxml.cache
711
unittests/data/directory_cache_test

CHANGELOG.md

+13

docs/install.rst

+4-4

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ keywords = [
1818
"CastXML",
1919
"gccxml",
2020
]
21-
version = "2.5.0"
21+
version = "2.6.0"
2222

2323
classifiers = [
2424
"Development Status :: 5 - Production/Stable",
@@ -55,6 +55,7 @@ test = [
5555
"coverage",
5656
"coveralls",
5757
"pycodestyle",
58+
"pytest",
5859
]
5960
docs = [
6061
"sphinx",

src/pygccxml/declarations/container_traits.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,14 @@ def remove_defaults(self, type_or_string):
647647

648648
unordered_set_traits = container_traits_impl_t(
649649
'unordered_set',
650-
1,
650+
0,
651651
'value_type',
652652
'erase_hash_allocator',
653653
unordered_maps_and_sets=True)
654654

655655
unordered_multiset_traits = container_traits_impl_t(
656656
'unordered_multiset',
657-
1,
657+
0,
658658
'value_type',
659659
'erase_hash_allocator',
660660
unordered_maps_and_sets=True)

src/pygccxml/declarations/cpptypes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from . import algorithms_cache
1111
from . import byte_info
12+
from . import elaborated_info
1213

1314

1415
class type_t(byte_info.byte_info):
@@ -593,10 +594,10 @@ def __init__(self, base):
593594
compound_t.__init__(self, base)
594595

595596
def build_decl_string(self, with_defaults=True):
596-
if hasattr(self.base.declaration, "elaborated_type_specifier"):
597+
prefix = ""
598+
if isinstance(self.base, type(declarated_t)) and \
599+
isinstance(self.base.declaration, type(elaborated_info)):
597600
prefix = self.base.declaration.elaborated_type_specifier + " "
598-
else:
599-
prefix = ""
600601
return prefix + self.base.build_decl_string(with_defaults)
601602

602603
def _clone_impl(self):

src/pygccxml/parser/config.py

+11-30
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import copy
1313
import platform
14+
import shutil
1415
import subprocess
1516
import warnings
1617
# In py3, ConfigParser was renamed to the more-standard configparser.
@@ -129,16 +130,12 @@ def compiler(self, compiler):
129130

130131
@property
131132
def xml_generator(self):
132-
"""get xml_generator (gccxml or castxml)"""
133+
"""get xml_generator"""
133134
return self.__xml_generator
134135

135136
@xml_generator.setter
136137
def xml_generator(self, xml_generator):
137-
"""set xml_generator (gccxml or castxml)"""
138-
if "real" in xml_generator:
139-
# Support for gccxml.real from newer gccxml package
140-
# Can be removed once gccxml support is dropped.
141-
xml_generator = "gccxml"
138+
"""set xml_generator"""
142139
self.__xml_generator = xml_generator
143140

144141
@property
@@ -241,9 +238,8 @@ def raise_on_wrong_settings(self):
241238
self.__ensure_dir_exists(self.working_directory, 'working directory')
242239
for idir in self.include_paths:
243240
self.__ensure_dir_exists(idir, 'include directory')
244-
if self.__xml_generator not in ["castxml", "gccxml"]:
245-
msg = ('xml_generator("%s") should either be ' +
246-
'"castxml" or "gccxml".') % self.xml_generator
241+
if self.__xml_generator != "castxml":
242+
msg = f"xml_generator ({self.xml_generator}) can only be 'castxml'"
247243
raise RuntimeError(msg)
248244

249245

@@ -456,35 +452,20 @@ def create_compiler_path(xml_generator, compiler_path):
456452
if xml_generator == 'castxml' and compiler_path is None:
457453
if platform.system() == 'Windows':
458454
# Look for msvc
459-
compiler_path = __get_first_compiler_in_path('where', 'cl')
455+
compiler_path = shutil.which('cl')
460456
# No msvc found; look for mingw
461-
if compiler_path == '':
462-
compiler_path = __get_first_compiler_in_path('where', 'mingw')
457+
if compiler_path is None:
458+
compiler_path = shutil.which('mingw')
463459
else:
464460
# OS X or Linux
465461
# Look for clang first, then gcc
466-
compiler_path = __get_first_compiler_in_path('which', 'clang++')
462+
compiler_path = shutil.which('clang++')
467463
# No clang found; use gcc
468-
if compiler_path == '':
469-
compiler_path = __get_first_compiler_in_path('which', 'c++')
470-
471-
if compiler_path == "":
472-
compiler_path = None
464+
if compiler_path is None:
465+
compiler_path = shutil.which('c++')
473466

474467
return compiler_path
475468

476469

477-
def __get_first_compiler_in_path(command, compiler_name):
478-
p = subprocess.Popen(
479-
[command, compiler_name],
480-
stdout=subprocess.PIPE,
481-
stderr=subprocess.PIPE)
482-
path = p.stdout.read().decode("utf-8").rstrip().split("\r\n")[0].rstrip()
483-
p.wait()
484-
p.stdout.close()
485-
p.stderr.close()
486-
return path
487-
488-
489470
if __name__ == '__main__':
490471
print(load_xml_generator_configuration('xml_generator.cfg').__dict__)

src/pygccxml/parser/scanner.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
XML_AN_STATIC = "static"
5757
XML_AN_THROW = "throw"
5858
XML_AN_TYPE = "type"
59+
XML_AN_ORIGINAL_TYPE = "original_type"
5960
XML_AN_VIRTUAL = "virtual"
6061
XML_AN_VOLATILE = "volatile"
6162
XML_NN_ARGUMENT = "Argument"
@@ -558,7 +559,10 @@ def __read_argument(self, attrs):
558559
XML_AN_NAME,
559560
'arg%d' % len(
560561
self.__inst.arguments))
561-
argument.decl_type = attrs[XML_AN_TYPE]
562+
argument.decl_type = attrs.get(
563+
XML_AN_ORIGINAL_TYPE,
564+
attrs.get(XML_AN_TYPE)
565+
)
562566
argument.default_value = attrs.get(XML_AN_DEFAULT)
563567
self.__read_attributes(argument, attrs)
564568
self.__inst.arguments.append(argument)
@@ -576,8 +580,8 @@ def __read_calldef(self, calldef, attrs, is_declaration):
576580
if is_declaration:
577581
self.__calldefs.append(calldef)
578582
calldef.name = attrs.get(XML_AN_NAME, '')
579-
calldef.has_extern = attrs.get(XML_AN_EXTERN, False)
580-
calldef.has_inline = bool(attrs.get(XML_AN_INLINE, "") == "1")
583+
calldef.has_extern = bool(attrs.get(XML_AN_EXTERN, False))
584+
calldef.has_inline = bool(attrs.get(XML_AN_INLINE, False))
581585
throw_stmt = attrs.get(XML_AN_THROW)
582586
if None is throw_stmt:
583587
calldef.does_throw = True
@@ -593,9 +597,9 @@ def __read_calldef(self, calldef, attrs, is_declaration):
593597

594598
def __read_member_function(self, calldef, attrs, is_declaration):
595599
self.__read_calldef(calldef, attrs, is_declaration)
596-
calldef.has_const = attrs.get(XML_AN_CONST, False)
600+
calldef.has_const = bool(attrs.get(XML_AN_CONST, False))
597601
if is_declaration:
598-
calldef.has_static = attrs.get(XML_AN_STATIC, False)
602+
calldef.has_static = bool(attrs.get(XML_AN_STATIC, False))
599603
if XML_AN_PURE_VIRTUAL in attrs:
600604
calldef.virtuality = declarations.VIRTUALITY_TYPES.PURE_VIRTUAL
601605
elif XML_AN_VIRTUAL in attrs:
@@ -626,9 +630,9 @@ def __read_typedef(self, attrs):
626630

627631
def __read_variable(self, attrs):
628632
type_qualifiers = declarations.type_qualifiers_t()
629-
type_qualifiers.has_mutable = attrs.get(XML_AN_MUTABLE, False)
630-
type_qualifiers.has_static = attrs.get(XML_AN_STATIC, False)
631-
type_qualifiers.has_extern = attrs.get(XML_AN_EXTERN, False)
633+
type_qualifiers.has_mutable = bool(attrs.get(XML_AN_MUTABLE, False))
634+
type_qualifiers.has_static = bool(attrs.get(XML_AN_STATIC, False))
635+
type_qualifiers.has_extern = bool(attrs.get(XML_AN_EXTERN, False))
632636
bits = attrs.get(XML_AN_BITS)
633637
if bits:
634638
bits = int(bits)

src/pygccxml/utils/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
"""
1010

11-
from .utils import is_str
1211
from .utils import get_architecture
1312
from .utils import loggers
1413
from .utils import create_temp_file_name

src/pygccxml/utils/utils.py

-24
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,12 @@
77

88
import os
99
import sys
10-
import platform
1110
import logging
1211
import tempfile
1312
import shutil
14-
import subprocess
1513
import warnings
1614

1715

18-
def is_str(string):
19-
"""
20-
Python 2 and 3 compatible string checker.
21-
22-
Args:
23-
string (str | basestring): the string to check
24-
25-
Returns:
26-
bool: True or False
27-
28-
"""
29-
warnings.warn(
30-
"The is_str function is deprecated. \
31-
Use isinstance(string, str) instead.",
32-
DeprecationWarning)
33-
34-
if sys.version_info[:2] >= (3, 0):
35-
return isinstance(string, str)
36-
37-
return isinstance(string, basestring)
38-
39-
4016
def find_xml_generator(name="castxml", search_path=None):
4117
"""
4218
Try to find a c++ parser (xml generator)
File renamed without changes.

unittests/autoconfig.py renamed to tests/autoconfig.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
data_directory = os.path.join(this_module_dir_path, 'data')
1919
build_directory = os.path.join(this_module_dir_path, 'temp')
2020

21+
if not os.path.exists(build_directory):
22+
os.makedirs(build_directory)
23+
2124
sys.path.insert(1, os.path.join(os.curdir, '..'))
2225
# The tests are run on the parent pygccxml directory, not the one
2326
# in site-packages. Insert the directory's path.

tests/conftest.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2014-2017 Insight Software Consortium.
2+
# Copyright 2004-2009 Roman Yakovenko.
3+
# Distributed under the Boost Software License, Version 1.0.
4+
# See http://www.boost.org/LICENSE_1_0.txt
5+
6+
import pytest
7+
8+
9+
class Helpers:
10+
@staticmethod
11+
def _test_type_composition(type_, expected_compound, expected_base):
12+
assert isinstance(type_, expected_compound)
13+
assert isinstance(type_.base, expected_base)
14+
15+
@staticmethod
16+
def _test_calldef_args(calldef, expected_args):
17+
assert len(calldef.arguments) == len(expected_args)
18+
19+
for i, expected_arg in enumerate(expected_args):
20+
arg = calldef.arguments[i]
21+
assert arg == expected_arg
22+
23+
@staticmethod
24+
def _test_calldef_return_type(calldef, expected_type):
25+
assert isinstance(calldef.return_type, expected_type)
26+
27+
@staticmethod
28+
def _test_calldef_exceptions(global_ns, calldef, exceptions):
29+
# exceptions is list of classes names
30+
exception_decls = []
31+
for name in exceptions:
32+
exception_decl = global_ns.class_(name)
33+
assert exception_decl is not None
34+
exception_decls.append(exception_decl)
35+
exception_decls.sort()
36+
assert len(calldef.exceptions) == len(exception_decls)
37+
exceptions_indeed = sorted(calldef.exceptions[:])
38+
assert exception_decls == exceptions_indeed
39+
40+
41+
@pytest.fixture
42+
def helpers():
43+
return Helpers
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/data/test_array_argument.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014-2017 Insight Software Consortium.
2+
// Copyright 2004-2009 Roman Yakovenko.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// See http://www.boost.org/LICENSE_1_0.txt
5+
6+
class test
7+
{
8+
public:
9+
// A constructor
10+
test(const float & t0){};
11+
12+
void function(int arg1[1024], int arg2[512]) {};
13+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

unittests/example_tester_wrap.py renamed to tests/example_tester_wrap.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
sys.modules[__name__].__file__ = example_file
2929

3030
# Run the example
31-
if sys.version_info[:2] >= (3, 0):
32-
with open(example_file) as f:
33-
code = compile(f.read(), example_file, "exec")
34-
exec(code, None, None)
35-
else:
36-
execfile(example_file)
31+
with open(example_file) as f:
32+
code = compile(f.read(), example_file, "exec")
33+
exec(code, None, None)

0 commit comments

Comments
 (0)