Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Nov 17, 2024
2 parents b67b261 + 5f6f235 commit e178aeb
Show file tree
Hide file tree
Showing 266 changed files with 6,354 additions and 8,244 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
on: [push, pull_request]
on:
push:
branches:
- main
- develop
pull_request:

jobs:
tests:
name: ${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.version }}-python-${{ matrix.python-version }}-${{ matrix.castxml-epic }}
Expand Down Expand Up @@ -93,12 +99,7 @@ jobs:
if: matrix.os == 'macos-12'
run: |
wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/5d937e938f7b882a3a3e7941e68f8312d0898aaf2082e00003dd362b1ba70b98b0a08706a1be28e71652a6a0f1e66f89768b5eaa20e5a100592d5b3deefec3f0/download | tar zxf - -C ~/
- name: Setup castxml config
if: matrix.compiler == 'gcc' && matrix.version == '9'
run: mv unittests/configs/gcc9.cfg unittests/xml_generator.cfg;
- name: Run tests
run: |
export PATH=~/castxml/bin:$PATH
coverage run -m unittests.test_all
coverage combine
coverage xml
pytest tests
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
*.pyo
*~
docs/_build
tests/temp
tests/data/pygccxml.cache
tests/data/directory_cache_test
tests/data/ogre.1.7.xml
unittests/temp
unittests/data/pygccxml.cache
unittests/data/directory_cache_test
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changes
=======

Version 2.6.0
-------------

1. Drop utils.is_str function

2. Massive unit test refactoring: migrated all the tests to pytest.

3. Make sure has_mutable, has_static, has_extern functions always return a boolean

4. Fix a bug in unordered_set_traits and unordered_multiset_traits

5. Fix a bug in build_decl_string with elaborated type specifiers

Version 2.5.0
-------------

Expand Down
8 changes: 4 additions & 4 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ These instructions are only here for historical reasons. `GCC-XML`_ was the tool
to generate the xml files before CastXML existed.

**From version v1.8.0 on, pygccxml uses CastXML by default.
The support for GCC-XML will finally be dropped in pygccxml v2.0.0.**
The support for GCC-XML was finally dropped in pygccxml v2.0.0.**

There are few different ways to install GCC-XML on your system:

Expand All @@ -58,8 +58,8 @@ There are few different ways to install GCC-XML on your system:
.. _`instructions`: http://gccxml.org/HTML/Install.html
.. _`GCC-XML`: http://www.gccxml.org
.. _`CastXML`: https://github.com/CastXML/CastXML
.. _`Linux`: https://midas3.kitware.com/midas/folder/13152
.. _`OS X`: https://midas3.kitware.com/midas/folder/13152
.. _`Windows`: https://midas3.kitware.com/midas/folder/13152
.. _`Linux`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest
.. _`OS X`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest
.. _`Windows`: https://github.com/CastXML/CastXMLSuperbuild/releases/latest
.. _`SuperBuild`: https://github.com/thewtex/CastXMLSuperbuild
.. _`full install instructions`: https://github.com/CastXML/CastXML#build
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ keywords = [
"CastXML",
"gccxml",
]
version = "2.5.0"
version = "2.6.0"

classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -55,6 +55,7 @@ test = [
"coverage",
"coveralls",
"pycodestyle",
"pytest",
]
docs = [
"sphinx",
Expand Down
4 changes: 2 additions & 2 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ def remove_defaults(self, type_or_string):

unordered_set_traits = container_traits_impl_t(
'unordered_set',
1,
0,
'value_type',
'erase_hash_allocator',
unordered_maps_and_sets=True)

unordered_multiset_traits = container_traits_impl_t(
'unordered_multiset',
1,
0,
'value_type',
'erase_hash_allocator',
unordered_maps_and_sets=True)
Expand Down
7 changes: 4 additions & 3 deletions src/pygccxml/declarations/cpptypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from . import algorithms_cache
from . import byte_info
from . import elaborated_info


class type_t(byte_info.byte_info):
Expand Down Expand Up @@ -593,10 +594,10 @@ def __init__(self, base):
compound_t.__init__(self, base)

def build_decl_string(self, with_defaults=True):
if hasattr(self.base.declaration, "elaborated_type_specifier"):
prefix = ""
if isinstance(self.base, type(declarated_t)) and \
isinstance(self.base.declaration, type(elaborated_info)):
prefix = self.base.declaration.elaborated_type_specifier + " "
else:
prefix = ""
return prefix + self.base.build_decl_string(with_defaults)

def _clone_impl(self):
Expand Down
41 changes: 11 additions & 30 deletions src/pygccxml/parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import copy
import platform
import shutil
import subprocess
import warnings
# In py3, ConfigParser was renamed to the more-standard configparser.
Expand Down Expand Up @@ -129,16 +130,12 @@ def compiler(self, compiler):

@property
def xml_generator(self):
"""get xml_generator (gccxml or castxml)"""
"""get xml_generator"""
return self.__xml_generator

@xml_generator.setter
def xml_generator(self, xml_generator):
"""set xml_generator (gccxml or castxml)"""
if "real" in xml_generator:
# Support for gccxml.real from newer gccxml package
# Can be removed once gccxml support is dropped.
xml_generator = "gccxml"
"""set xml_generator"""
self.__xml_generator = xml_generator

@property
Expand Down Expand Up @@ -241,9 +238,8 @@ def raise_on_wrong_settings(self):
self.__ensure_dir_exists(self.working_directory, 'working directory')
for idir in self.include_paths:
self.__ensure_dir_exists(idir, 'include directory')
if self.__xml_generator not in ["castxml", "gccxml"]:
msg = ('xml_generator("%s") should either be ' +
'"castxml" or "gccxml".') % self.xml_generator
if self.__xml_generator != "castxml":
msg = f"xml_generator ({self.xml_generator}) can only be 'castxml'"
raise RuntimeError(msg)


Expand Down Expand Up @@ -456,35 +452,20 @@ def create_compiler_path(xml_generator, compiler_path):
if xml_generator == 'castxml' and compiler_path is None:
if platform.system() == 'Windows':
# Look for msvc
compiler_path = __get_first_compiler_in_path('where', 'cl')
compiler_path = shutil.which('cl')
# No msvc found; look for mingw
if compiler_path == '':
compiler_path = __get_first_compiler_in_path('where', 'mingw')
if compiler_path is None:
compiler_path = shutil.which('mingw')
else:
# OS X or Linux
# Look for clang first, then gcc
compiler_path = __get_first_compiler_in_path('which', 'clang++')
compiler_path = shutil.which('clang++')
# No clang found; use gcc
if compiler_path == '':
compiler_path = __get_first_compiler_in_path('which', 'c++')

if compiler_path == "":
compiler_path = None
if compiler_path is None:
compiler_path = shutil.which('c++')

return compiler_path


def __get_first_compiler_in_path(command, compiler_name):
p = subprocess.Popen(
[command, compiler_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
path = p.stdout.read().decode("utf-8").rstrip().split("\r\n")[0].rstrip()
p.wait()
p.stdout.close()
p.stderr.close()
return path


if __name__ == '__main__':
print(load_xml_generator_configuration('xml_generator.cfg').__dict__)
20 changes: 12 additions & 8 deletions src/pygccxml/parser/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
XML_AN_STATIC = "static"
XML_AN_THROW = "throw"
XML_AN_TYPE = "type"
XML_AN_ORIGINAL_TYPE = "original_type"
XML_AN_VIRTUAL = "virtual"
XML_AN_VOLATILE = "volatile"
XML_NN_ARGUMENT = "Argument"
Expand Down Expand Up @@ -558,7 +559,10 @@ def __read_argument(self, attrs):
XML_AN_NAME,
'arg%d' % len(
self.__inst.arguments))
argument.decl_type = attrs[XML_AN_TYPE]
argument.decl_type = attrs.get(
XML_AN_ORIGINAL_TYPE,
attrs.get(XML_AN_TYPE)
)
argument.default_value = attrs.get(XML_AN_DEFAULT)
self.__read_attributes(argument, attrs)
self.__inst.arguments.append(argument)
Expand All @@ -576,8 +580,8 @@ def __read_calldef(self, calldef, attrs, is_declaration):
if is_declaration:
self.__calldefs.append(calldef)
calldef.name = attrs.get(XML_AN_NAME, '')
calldef.has_extern = attrs.get(XML_AN_EXTERN, False)
calldef.has_inline = bool(attrs.get(XML_AN_INLINE, "") == "1")
calldef.has_extern = bool(attrs.get(XML_AN_EXTERN, False))
calldef.has_inline = bool(attrs.get(XML_AN_INLINE, False))
throw_stmt = attrs.get(XML_AN_THROW)
if None is throw_stmt:
calldef.does_throw = True
Expand All @@ -593,9 +597,9 @@ def __read_calldef(self, calldef, attrs, is_declaration):

def __read_member_function(self, calldef, attrs, is_declaration):
self.__read_calldef(calldef, attrs, is_declaration)
calldef.has_const = attrs.get(XML_AN_CONST, False)
calldef.has_const = bool(attrs.get(XML_AN_CONST, False))
if is_declaration:
calldef.has_static = attrs.get(XML_AN_STATIC, False)
calldef.has_static = bool(attrs.get(XML_AN_STATIC, False))
if XML_AN_PURE_VIRTUAL in attrs:
calldef.virtuality = declarations.VIRTUALITY_TYPES.PURE_VIRTUAL
elif XML_AN_VIRTUAL in attrs:
Expand Down Expand Up @@ -626,9 +630,9 @@ def __read_typedef(self, attrs):

def __read_variable(self, attrs):
type_qualifiers = declarations.type_qualifiers_t()
type_qualifiers.has_mutable = attrs.get(XML_AN_MUTABLE, False)
type_qualifiers.has_static = attrs.get(XML_AN_STATIC, False)
type_qualifiers.has_extern = attrs.get(XML_AN_EXTERN, False)
type_qualifiers.has_mutable = bool(attrs.get(XML_AN_MUTABLE, False))
type_qualifiers.has_static = bool(attrs.get(XML_AN_STATIC, False))
type_qualifiers.has_extern = bool(attrs.get(XML_AN_EXTERN, False))
bits = attrs.get(XML_AN_BITS)
if bits:
bits = int(bits)
Expand Down
1 change: 0 additions & 1 deletion src/pygccxml/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

from .utils import is_str
from .utils import get_architecture
from .utils import loggers
from .utils import create_temp_file_name
Expand Down
24 changes: 0 additions & 24 deletions src/pygccxml/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,12 @@

import os
import sys
import platform
import logging
import tempfile
import shutil
import subprocess
import warnings


def is_str(string):
"""
Python 2 and 3 compatible string checker.
Args:
string (str | basestring): the string to check
Returns:
bool: True or False
"""
warnings.warn(
"The is_str function is deprecated. \
Use isinstance(string, str) instead.",
DeprecationWarning)

if sys.version_info[:2] >= (3, 0):
return isinstance(string, str)

return isinstance(string, basestring)


def find_xml_generator(name="castxml", search_path=None):
"""
Try to find a c++ parser (xml generator)
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions unittests/autoconfig.py → tests/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
data_directory = os.path.join(this_module_dir_path, 'data')
build_directory = os.path.join(this_module_dir_path, 'temp')

if not os.path.exists(build_directory):
os.makedirs(build_directory)

sys.path.insert(1, os.path.join(os.curdir, '..'))
# The tests are run on the parent pygccxml directory, not the one
# in site-packages. Insert the directory's path.
Expand Down
43 changes: 43 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt

import pytest


class Helpers:
@staticmethod
def _test_type_composition(type_, expected_compound, expected_base):
assert isinstance(type_, expected_compound)
assert isinstance(type_.base, expected_base)

@staticmethod
def _test_calldef_args(calldef, expected_args):
assert len(calldef.arguments) == len(expected_args)

for i, expected_arg in enumerate(expected_args):
arg = calldef.arguments[i]
assert arg == expected_arg

@staticmethod
def _test_calldef_return_type(calldef, expected_type):
assert isinstance(calldef.return_type, expected_type)

@staticmethod
def _test_calldef_exceptions(global_ns, calldef, exceptions):
# exceptions is list of classes names
exception_decls = []
for name in exceptions:
exception_decl = global_ns.class_(name)
assert exception_decl is not None
exception_decls.append(exception_decl)
exception_decls.sort()
assert len(calldef.exceptions) == len(exception_decls)
exceptions_indeed = sorted(calldef.exceptions[:])
assert exception_decls == exceptions_indeed


@pytest.fixture
def helpers():
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.
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/data/test_array_argument.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2014-2017 Insight Software Consortium.
// Copyright 2004-2009 Roman Yakovenko.
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt

class test
{
public:
// A constructor
test(const float & t0){};

void function(int arg1[1024], int arg2[512]) {};
};
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.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
sys.modules[__name__].__file__ = example_file

# Run the example
if sys.version_info[:2] >= (3, 0):
with open(example_file) as f:
code = compile(f.read(), example_file, "exec")
exec(code, None, None)
else:
execfile(example_file)
with open(example_file) as f:
code = compile(f.read(), example_file, "exec")
exec(code, None, None)
Loading

0 comments on commit e178aeb

Please sign in to comment.